on master help sign in
Add parsing for infix declarations. No support for actually using this

information though.

commit8590c6bd18bf4d0059146f6668bbae1010d14fac authorEvan Czaplicki <evan@Evans-MacBook-Air.local> dateTue 16 Jul 2013, 14:39 (13 years ago) parent72bd5cb
1 file changed+13−5
compiler/Parse/Declaration.hs+13−5
compiler/Parse/Declaration.hs+13−5
@@ -11,27 +11,24 @@ import Parse.Helpers
1111import qualified Parse.Expression as Expr
1212import qualified SourceSyntax.Type as T
1313import qualified Parse.Type as Type
14−
15−import SourceSyntax.Declaration (Declaration(..))
14+import SourceSyntax.Declaration (Declaration(..), Assoc(..))
1615
1716import Unique
1817
1918declaration :: IParser (Declaration t v)
20−declaration = alias <|> datatype <|> foreignDef <|> definition
19+declaration = alias <|> datatype <|> infixDecl <|> foreignDef <|> definition
2120
2221definition :: IParser (Declaration t v)
2322definition = Definition <$> Expr.def
2423
2524alias :: IParser (Declaration t v)
2625alias = do
27− start <- getPosition
2826 reserved "type" <?> "type alias (type Point = {x:Int, y:Int})"
2927 forcedWS
3028 alias <- capVar
3129 args <- spacePrefix lowVar
3230 whitespace ; string "=" ; whitespace
3331 tipe <- Type.expr
34− end <- getPosition
3532 return (TypeAlias alias args tipe)
3633
3734datatype :: IParser (Declaration t v)
@@ -45,6 +42,17 @@ datatype = do
4542 return $ Datatype name args tcs
4643
4744
45+infixDecl :: IParser (Declaration t v)
46+infixDecl = do
47+ assoc <- choice [ reserved "infixl" >> return L
48+ , reserved "infix" >> return N
49+ , reserved "infixr" >> return R ]
50+ whitespace
51+ n <- digit
52+ whitespace
53+ Fixity assoc (read [n]) <$> anyOp
54+
55+
4856foreignDef :: IParser (Declaration t v)
4957foreignDef = do
5058 try (reserved "foreign")