on master help sign in
Add JSObject to the FFI parser.
868e71eevancz
Elm.cabal+1−1
@@ -1,5 +1,5 @@
1Name: Elm
1Name: Elm
2−Version: 0.8
2+Version: 0.8.0.1
3Synopsis: The Elm language module.
3Synopsis: The Elm language module.
4Description: Elm aims to make client-side web-development more pleasant.
4Description: Elm aims to make client-side web-development more pleasant.
5 It is a statically/strongly typed, functional reactive
5 It is a statically/strongly typed, functional reactive
compiler/Parse/Foreign.hs+3−4
@@ -11,12 +11,11 @@ import Parse.Expr (term)
11import Parse.Types
11import Parse.Types
12import Types.Types (signalOf)
12import Types.Types (signalOf)
13
13
14−
15foreignDef = do try (reserved "foreign") ; whitespace
14foreignDef = do try (reserved "foreign") ; whitespace
16− importEvent <|> exportEvent
15+ try importEvent <|> exportEvent
17
16
18exportEvent = do
17exportEvent = do
19− try (reserved "export" >> whitespace >> reserved "jsevent" >> whitespace)
18+ reserved "export" >> whitespace >> reserved "jsevent" >> whitespace
20 js <- jsVar ; whitespace
19 js <- jsVar ; whitespace
21 elm <- lowVar ; whitespace
20 elm <- lowVar ; whitespace
22 hasType ; whitespace
21 hasType ; whitespace
@@ -27,7 +26,7 @@ exportEvent = do
27 _ -> fail "When exporting events, the exported value must be a Signal."
26 _ -> fail "When exporting events, the exported value must be a Signal."
28
27
29importEvent = do
28importEvent = do
30− try (reserved "import" >> whitespace >> reserved "jsevent" >> whitespace)
29+ reserved "import" >> whitespace >> reserved "jsevent" >> whitespace
31 js <- jsVar ; whitespace
30 js <- jsVar ; whitespace
32 base <- term <?> "Base case for imported signal (signals cannot be undefined)"
31 base <- term <?> "Base case for imported signal (signals cannot be undefined)"
33 whitespace
32 whitespace
compiler/Parse/Types.hs+16−13
@@ -5,7 +5,7 @@ import Control.Applicative ((<$>),(<*>))
5import Control.Monad (liftM,mapM)
5import Control.Monad (liftM,mapM)
6import Data.Char (isUpper,isLower)
6import Data.Char (isUpper,isLower)
7import Data.Maybe (fromMaybe)
7import Data.Maybe (fromMaybe)
8−import Data.List (lookup)
8+import Data.List (lookup,intercalate)
9import Text.Parsec
9import Text.Parsec
10import Text.Parsec.Indent
10import Text.Parsec.Indent
11
11
@@ -18,6 +18,7 @@ data ParseType = VarPT String
18 | LambdaPT ParseType ParseType
18 | LambdaPT ParseType ParseType
19 | ADTPT String [ParseType]
19 | ADTPT String [ParseType]
20 | RecordPT (Maybe ParseType) [(String,ParseType)]
20 | RecordPT (Maybe ParseType) [(String,ParseType)]
21+ deriving (Show)
21
22
22listPT t = ADTPT "List" [t]
23listPT t = ADTPT "List" [t]
23tuplePT ts = ADTPT ("Tuple" ++ show (length ts)) ts
24tuplePT ts = ADTPT ("Tuple" ++ show (length ts)) ts
@@ -150,18 +151,20 @@ toDatatype name args tcs = Datatype name [1..n] <$> mapM toC tcs
150toForeignType (LambdaPT t1 t2) =
151toForeignType (LambdaPT t1 t2) =
151 fail $ "Elm's JavaScript event interface does not yet handle functions. " ++
152 fail $ "Elm's JavaScript event interface does not yet handle functions. " ++
152 "Only simple values can be imported and exported in this release."
153 "Only simple values can be imported and exported in this release."
153− --LambdaT <$> toForeignType t1 <*> toForeignType t2
154+
154−toForeignType (ADTPT name args)
155+toForeignType (ADTPT "JSArray" args) =
155− | isJsStructure name = ADT name <$> mapM toForeignType args
156+ ADT "JSArray" <$> mapM toForeignType args
156− | otherwise =
157+
158+toForeignType (ADTPT name _) =
157− Left $ "'" ++ name ++ "' is not an exportable type " ++
159+ Left $ "'" ++ name ++ "' is not an exportable type " ++
158− "constructor. Only 'JSArray' and 'JSTupleN' are exportable."
160+ "constructor. Only 'JSArray' is exportable."
159
161
160toForeignType (VarPT x@(c:_))
162toForeignType (VarPT x@(c:_))
163+ | x `elem` jsTypes = Right (ADT x [])
161 | isLower c =
164 | isLower c =
162− Left "All exported types must be concrete types (JSNumber, JSString, etc.)"
165+ Left $ "All exported types must be concrete types." ++ msg
163− | x `elem` ["JSString","JSNumber","JSElement","JSBool"] = Right (ADT x [])
166+ | otherwise =
164− | otherwise = Left $ "'" ++ x ++ "' is not an exportable type. Only JSTypes are exportable."
167+ Left $ "'" ++ x ++ "' is not an exportable type." ++ msg
165−
168+ where
166−isJsStructure name = name == "JSArray" || isTuple
169+ msg = " The following types are exportable: " ++ intercalate ", " jsTypes
167− where isTuple = "JSTuple" == take 7 name && drop 7 name `elem` map show [2..5]
170+ jsTypes = ["JSString","JSNumber","JSElement","JSBool","JSObject"]