on master help sign in
Improve some parser code by adding type annotations, removing unused dependencies, and using prefixed imports
fcbd7fdEvan Czaplicki
compiler/Parse/Expression.hs+2−2
@@ -1,4 +1,4 @@
1−module Parse.Expression (def,term,typeAnnotation) where
1+module Parse.Expression (def,term,typeAnnotation,expr) where
2
2
3import Control.Arrow ((***))
3import Control.Arrow ((***))
4import Control.Applicative ((<$>), (<*>))
4import Control.Applicative ((<$>), (<*>))
@@ -16,7 +16,6 @@ import SourceSyntax.Location as Location
16import SourceSyntax.Pattern hiding (tuple,list)
16import SourceSyntax.Pattern hiding (tuple,list)
17import qualified SourceSyntax.Literal as Literal
17import qualified SourceSyntax.Literal as Literal
18import SourceSyntax.Expression
18import SourceSyntax.Expression
19−import SourceSyntax.Declaration (Declaration(Definition))
20
19
21
20
22-------- Basic Terms --------
21-------- Basic Terms --------
@@ -191,6 +190,7 @@ caseExpr = do
191 with = brackets (semiSep1 (case_ <?> "cases { x -> ... }"))
190 with = brackets (semiSep1 (case_ <?> "cases { x -> ... }"))
192 without = block (do c <- case_ ; whitespace ; return c)
191 without = block (do c <- case_ ; whitespace ; return c)
193
192
193+expr :: IParser (LExpr t v)
194expr = addLocation (choice [ ifExpr, letExpr, caseExpr ])
194expr = addLocation (choice [ ifExpr, letExpr, caseExpr ])
195 <|> lambdaExpr
195 <|> lambdaExpr
196 <|> binaryExpr
196 <|> binaryExpr
compiler/Parse/Helpers.hs+1−1
@@ -22,7 +22,7 @@ reserveds = [ "if", "then", "else"
22 , "module", "where"
22 , "module", "where"
23 , "import", "as", "hiding", "open"
23 , "import", "as", "hiding", "open"
24 , "export", "foreign"
24 , "export", "foreign"
25− , "deriving" ]
25+ , "deriving", "port" ]
26
26
27jsReserveds :: Set.Set String
27jsReserveds :: Set.Set String
28jsReserveds = Set.fromList
28jsReserveds = Set.fromList
compiler/Parse/Parse.hs+2−2
@@ -9,7 +9,7 @@ import Text.Parsec hiding (newline,spaces)
9import qualified Text.PrettyPrint as P
9import qualified Text.PrettyPrint as P
10
10
11import qualified SourceSyntax.Module as S
11import qualified SourceSyntax.Module as S
12−import SourceSyntax.Declaration (Declaration(Fixity))
12+import qualified SourceSyntax.Declaration as D
13import Parse.Helpers
13import Parse.Helpers
14import Parse.Binop (OpTable)
14import Parse.Binop (OpTable)
15import Parse.Expression
15import Parse.Expression
@@ -61,7 +61,7 @@ setupParserWithTable table p source =
61
61
62parseFixities = do
62parseFixities = do
63 decls <- onFreshLines (:) [] infixDecl
63 decls <- onFreshLines (:) [] infixDecl
64− return $ Map.fromList [ (op,(lvl,assoc)) | Fixity assoc lvl op <- decls ]
64+ return $ Map.fromList [ (op,(lvl,assoc)) | D.Fixity assoc lvl op <- decls ]
65
65
66setupParser :: IParser a -> String -> Either [P.Doc] a
66setupParser :: IParser a -> String -> Either [P.Doc] a
67setupParser p source =
67setupParser p source =