on master help sign in
Update type syntax to be clearer

type => type alias data => type

commit27eafdacc025b325d6386b6ace71aefdceabdcc9 authorEvan Czaplicki <info@elm-lang.org> dateSat 20 Sep 2014, 14:13 (12 years ago) parent42b2236
1 file changed+20−20
compiler/Parse/Declaration.hs+20−20
compiler/Parse/Declaration.hs+20−20
@@ -10,30 +10,30 @@ import qualified Parse.Type as Type
1010import qualified AST.Declaration as D
1111
1212declaration :: IParser D.SourceDecl
13−declaration = alias <|> datatype <|> infixDecl <|> port <|> definition
13+declaration = typeDecl <|> infixDecl <|> port <|> definition
1414
1515definition :: IParser D.SourceDecl
1616definition = D.Definition <$> Expr.def
1717
18−alias :: IParser D.SourceDecl
19−alias = do
20− reserved "type" <?> "type alias (type Point = {x:Int, y:Int})"
21− forcedWS
22− name <- capVar
23− args <- spacePrefix lowVar
24− padded equals
25− tipe <- Type.expr
26− return (D.TypeAlias name args tipe)
27−
28−datatype :: IParser D.SourceDecl
29−datatype = do
30− reserved "data" <?> "datatype definition (data T = A | B | ...)"
31− forcedWS
32− name <- capVar <?> "name of data-type"
33− args <- spacePrefix lowVar
34− padded equals
35− tcs <- pipeSep1 Type.constructor
36− return $ D.Datatype name args tcs
18+typeDecl :: IParser D.SourceDecl
19+typeDecl =
20+ do reserved "type" <?> "type declaration"
21+ forcedWS
22+ isAlias <- optionMaybe (string "alias" >> forcedWS)
23+ case isAlias of
24+ Just _ ->
25+ do name <- capVar
26+ args <- spacePrefix lowVar
27+ padded equals
28+ tipe <- Type.expr
29+ return (D.TypeAlias name args tipe)
30+
31+ Nothing ->
32+ do name <- capVar <?> "name of data-type"
33+ args <- spacePrefix lowVar
34+ padded equals
35+ tcs <- pipeSep1 Type.constructor
36+ return $ D.Datatype name args tcs
3737
3838
3939infixDecl :: IParser D.SourceDecl