on master help sign in
Merge branch 'master' into make

Conflicts: libraries/Array.elm libraries/Basics.elm libraries/Char.elm libraries/Color.elm libraries/Date.elm libraries/Dict.elm libraries/Either.elm libraries/Graphics/Collage.elm libraries/Graphics/Element.elm libraries/Graphics/Input.elm libraries/Graphics/Input/Field.elm libraries/Http.elm libraries/JavaScript/Experimental.elm libraries/Json.elm libraries/Keyboard.elm libraries/List.elm libraries/Maybe.elm libraries/Native/Array.js libraries/Regex.elm libraries/Set.elm libraries/Signal.elm libraries/String.elm libraries/Text.elm libraries/Time.elm libraries/Touch.elm libraries/Trampoline.elm libraries/Transform2D.elm src/Parse/Declaration.hs

commitad235f980b9683765b3531782a4c5463952e683a authorEvan Czaplicki <info@elm-lang.org> dateThu 16 Oct 2014, 12:36 (12 years ago) parentb75e5a7e531046
4 files changed+38−31
src/Docs.hs+2−2 src/Parse/Declaration.hs+23−20 src/Parse/Helpers.hs+11−9 tests/libraries/Test/Array.elm+2
src/Docs.hs+2−2
@@ -25,7 +25,7 @@ import qualified AST.Expression.Source as Src
2525import qualified AST.Variable as Var
2626
2727import Text.Parsec hiding (newline,spaces)
28−import Parse.Declaration (alias,datatype,infixDecl)
28+import Parse.Declaration (typeDecl,infixDecl)
2929import Parse.Expression (typeAnnotation)
3030import Parse.Helpers
3131import qualified Parse.Module as Module
@@ -102,7 +102,7 @@ docThing = uncommentable <|> commented <|> uncommented ""
102102 uncommented comment
103103
104104 uncommented comment = do
105− (src,def) <- withSource $ choice [ alias, datatype, D.Definition <$> typeAnnotation ]
105+ (src,def) <- withSource $ choice [ typeDecl, D.Definition <$> typeAnnotation ]
106106 return (comment, def, src)
107107
108108
src/Parse/Declaration.hs+23−20
@@ -9,32 +9,35 @@ import qualified Parse.Expression as Expr
99import Parse.Helpers
1010import qualified Parse.Type as Type
1111
12+
1213declaration :: IParser D.SourceDecl
1314declaration =
14− alias <|> datatype <|> infixDecl <|> port <|> definition
15+ typeDecl <|> infixDecl <|> port <|> definition
16+
1517
1618definition :: IParser D.SourceDecl
1719definition = D.Definition <$> Expr.def
1820
19−alias :: IParser D.SourceDecl
20−alias = do
21− reserved "type" <?> "type alias (type Point = {x:Int, y:Int})"
22− forcedWS
23− name <- capVar
24− args <- spacePrefix lowVar
25− padded equals
26− tipe <- Type.expr
27− return (D.TypeAlias name args tipe)
28−
29−datatype :: IParser D.SourceDecl
30−datatype = do
31− reserved "data" <?> "datatype definition (data T = A | B | ...)"
32− forcedWS
33− name <- capVar <?> "name of data-type"
34− args <- spacePrefix lowVar
35− padded equals
36− tcs <- pipeSep1 Type.constructor
37− return $ D.Datatype name args tcs
21+
22+typeDecl :: IParser D.SourceDecl
23+typeDecl =
24+ do reserved "type" <?> "type declaration"
25+ forcedWS
26+ isAlias <- optionMaybe (string "alias" >> forcedWS)
27+ case isAlias of
28+ Just _ ->
29+ do name <- capVar
30+ args <- spacePrefix lowVar
31+ padded equals
32+ tipe <- Type.expr
33+ return (D.TypeAlias name args tipe)
34+
35+ Nothing ->
36+ do name <- capVar <?> "name of data-type"
37+ args <- spacePrefix lowVar
38+ padded equals
39+ tcs <- pipeSep1 Type.constructor
40+ return $ D.Datatype name args tcs
3841
3942
4043infixDecl :: IParser D.SourceDecl
src/Parse/Helpers.hs+11−9
@@ -22,15 +22,17 @@ import qualified AST.Literal as L
2222import qualified AST.PrettyPrint as P
2323import qualified AST.Variable as Variable
2424
25−reserveds = [ "if", "then", "else"
26− , "case", "of"
27− , "let", "in"
28− , "data", "type"
29− , "module", "where"
30− , "import", "as", "hiding", "open"
31− , "export", "foreign"
32− , "deriving", "port"
33− ]
25+reserveds :: [String]
26+reserveds =
27+ [ "if", "then", "else"
28+ , "case", "of"
29+ , "let", "in"
30+ , "data", "type"
31+ , "module", "where"
32+ , "import", "as", "hiding", "open"
33+ , "export", "foreign"
34+ , "deriving", "port"
35+ ]
3436
3537expecting = flip (<?>)
3638
tests/libraries/Test/Array.elm+2
@@ -37,6 +37,8 @@ tests =
3737 , test "append" <| assertEqual [42,42,81,81,81] (Array.toList (Array.append (Array.repeat 2 42) (Array.repeat 3 81)))
3838 , test "appendEmpty 1" <| assertEqual [1..33] (Array.toList (Array.append Array.empty (Array.fromList [1..33])))
3939 , test "appendEmpty 2" <| assertEqual [1..33] (Array.toList (Array.append (Array.fromList [1..33]) Array.empty))
40+ , test "appendSmall 1" <| assertEqual [1..33] (Array.toList (Array.append (Array.fromList [1..30]) (Array.fromList [31..33])))
41+ , test "appendSmall 2" <| assertEqual [1..33] (Array.toList (Array.append (Array.fromList [1..3]) (Array.fromList [4..33])))
4042 , test "appendAndSlice" <| assertEqual [0..100] (Array.toList holeArray)
4143 ]
4244 getAndSetTests = suite "Get and Set"