on master help sign in
Split "def" parser into separate typeAnnotation and definition parsers
commite65f0f063837702562a370ff2e9520387a1fffc6 authorEvan Czaplicki <info@elm-lang.org> dateThu 2 Apr 2015, 18:20 (12 years ago) parent5e3f51a
2 files changed+10−18
src/Parse/Declaration.hs+1−1 src/Parse/Expression.hs+9−17
src/Parse/Declaration.hs+1−1
@@ -17,7 +17,7 @@ declaration =
1717
1818definition :: IParser D.SourceDecl
1919definition =
20− D.Definition <$> Expr.def
20+ D.Definition <$> (Expr.typeAnnotation <|> Expr.definition)
2121
2222
2323typeDecl :: 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
22
33import Control.Applicative ((<$>), (<*>))
44import qualified Data.List as List
@@ -232,25 +232,16 @@ letExpr :: IParser Source.Expr'
232232letExpr =
233233 do try (reserved "let")
234234 whitespace
235− defs <- defSet
235+ defs <-
236+ block $
237+ do def <- typeAnnotation <|> definition
238+ whitespace
239+ return def
236240 padded (reserved "in")
237241 E.Let defs <$> expr
238242
239243
240−defSet :: IParser [Source.Def]
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−
244+-- TYPE ANNOTATION
254245
255246typeAnnotation :: IParser Source.Def
256247typeAnnotation =
@@ -262,6 +253,8 @@ typeAnnotation =
262253 return v
263254
264255
256+-- DEFINITION
257+
265258definition :: IParser Source.Def
266259definition =
267260 withPos $
@@ -299,4 +292,3 @@ defStart =
299292 if o == '`'
300293 then [ P.Var $ takeWhile (/='`') p, p1, p2 ]
301294 else [ P.Var (o:p), p1, p2 ]
302−