-
Notifications
You must be signed in to change notification settings - Fork 35
/
Expr.hs
30 lines (22 loc) · 867 Bytes
/
Expr.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module Text.Parsec.String.Expr (buildExpressionParser
,Operator(..)
,OperatorTable
,E.Assoc(..)
)where
{-
Wrappers for the Text.Parsec.Expr module with simplified types.
-}
import Text.Parsec.String (Parser)
import qualified Text.Parsec.Expr as E
-- not sure if this is neccessary, or a type alias would be good
-- enough
data Operator a = Infix (Parser (a -> a -> a)) E.Assoc
| Prefix (Parser (a -> a))
| Postfix (Parser (a -> a))
type OperatorTable a = [[Operator a]]
buildExpressionParser :: OperatorTable a -> Parser a -> Parser a
buildExpressionParser t = E.buildExpressionParser (map (map f) t)
where
f (Infix p a) = E.Infix p a
f (Prefix p) = E.Prefix p
f (Postfix p) = E.Postfix p