on master help sign in
Split "def" parser into separate typeAnnotation and definition parsers
e65f0f0Evan Czaplicki
src/Parse/Declaration.hs+1−1
@@ -17,7 +17,7 @@ declaration =
17
17
18definition :: IParser D.SourceDecl
18definition :: IParser D.SourceDecl
19definition =
19definition =
20− D.Definition <$> Expr.def
20+ D.Definition <$> (Expr.typeAnnotation <|> Expr.definition)
21
21
22
22
23typeDecl :: IParser D.SourceDecl
23typeDecl :: IParser D.SourceDecl
src/Parse/Expression.hs+9−17
@@ -1,4 +1,4 @@
1−module Parse.Expression (def, term, typeAnnotation, expr) where
1+module Parse.Expression (term, typeAnnotation, definition, expr) where
2
2
3import Control.Applicative ((<$>), (<*>))
3import Control.Applicative ((<$>), (<*>))
4import qualified Data.List as List
4import qualified Data.List as List
@@ -232,25 +232,16 @@ letExpr :: IParser Source.Expr'
232letExpr =
232letExpr =
233 do try (reserved "let")
233 do try (reserved "let")
234 whitespace
234 whitespace
235− defs <- defSet
235+ defs <-
236+ block $
237+ do def <- typeAnnotation <|> definition
238+ whitespace
239+ return def
236 padded (reserved "in")
240 padded (reserved "in")
237 E.Let defs <$> expr
241 E.Let defs <$> expr
238
242
239
243
240−defSet :: IParser [Source.Def]
244+-- TYPE ANNOTATION
241−defSet =
242− block $
243− do d <- def
244− whitespace
245− return d
246−
247−
248−-- DEFINITIONS
249−
250−def :: IParser Source.Def
251−def =
252− typeAnnotation <|> definition
253−
254
245
255typeAnnotation :: IParser Source.Def
246typeAnnotation :: IParser Source.Def
256typeAnnotation =
247typeAnnotation =
@@ -262,6 +253,8 @@ typeAnnotation =
262 return v
253 return v
263
254
264
255
256+-- DEFINITION
257+
265definition :: IParser Source.Def
258definition :: IParser Source.Def
266definition =
259definition =
267 withPos $
260 withPos $
@@ -299,4 +292,3 @@ defStart =
299 if o == '`'
292 if o == '`'
300 then [ P.Var $ takeWhile (/='`') p, p1, p2 ]
293 then [ P.Var $ takeWhile (/='`') p, p1, p2 ]
301 else [ P.Var (o:p), p1, p2 ]
294 else [ P.Var (o:p), p1, p2 ]
302−