on master help sign in
Update input/output syntax
552beccEvan Czaplicki
src/AST/Declaration.hs+23−23
@@ -49,10 +49,10 @@ data RawWire
49 | LoopbackDefinition String Source.Expr
49 | LoopbackDefinition String Source.Expr
50
50
51
51
52−data Wire expr var loopback
52+data Wire expr var input
53 = Input String (T.Type var)
53 = Input String (T.Type var)
54 | Output String expr (T.Type var)
54 | Output String expr (T.Type var)
55− | Loopback loopback
55+ | Loopback input
56
56
57
57
58data ValidLoopback =
58data ValidLoopback =
@@ -60,7 +60,7 @@ data ValidLoopback =
60
60
61
61
62data CanonicalLoopback
62data CanonicalLoopback
63− = Mailbox String T.CanonicalType
63+ = Address String T.CanonicalType
64 | Promise String T.CanonicalType Canonical.Expr T.CanonicalType
64 | Promise String T.CanonicalType Canonical.Expr T.CanonicalType
65
65
66
66
@@ -144,56 +144,56 @@ instance Pretty RawWire where
144 pretty wire =
144 pretty wire =
145 case wire of
145 case wire of
146 InputAnnotation name tipe ->
146 InputAnnotation name tipe ->
147− prettyWire "input" name ":" tipe
147+ prettyWire "foreign input" name ":" tipe
148
148
149 OutputAnnotation name tipe ->
149 OutputAnnotation name tipe ->
150− prettyWire "output" name ":" tipe
150+ prettyWire "foreign output" name ":" tipe
151
151
152 OutputDefinition name expr ->
152 OutputDefinition name expr ->
153− prettyWire "output" name "=" expr
153+ prettyWire "foreign output" name "=" expr
154
154
155 LoopbackAnnotation name tipe ->
155 LoopbackAnnotation name tipe ->
156− prettyWire "loopback" name ":" tipe
156+ prettyWire "input" name ":" tipe
157
157
158 LoopbackDefinition name expr ->
158 LoopbackDefinition name expr ->
159− prettyWire "loopback" name "<-" expr
159+ prettyWire "input" name "from" expr
160
160
161
161
162−instance (Pretty expr, Pretty var, Var.ToString var, Pretty loopback) =>
162+instance (Pretty expr, Pretty var, Var.ToString var, Pretty input) =>
163− Pretty (Wire expr var loopback) where
163+ Pretty (Wire expr var input) where
164 pretty wire =
164 pretty wire =
165 case wire of
165 case wire of
166 Input name tipe ->
166 Input name tipe ->
167− prettyWire "input" name ":" tipe
167+ prettyWire "foreign input" name ":" tipe
168
168
169 Output name expr tipe ->
169 Output name expr tipe ->
170 P.vcat
170 P.vcat
171− [ prettyWire "output" name ":" tipe
171+ [ prettyWire "foreign output" name ":" tipe
172− , prettyWire "output" name "=" expr
172+ , prettyWire "foreign output" name "=" expr
173 ]
173 ]
174
174
175− Loopback loopback ->
175+ Loopback input ->
176− pretty loopback
176+ pretty input
177
177
178
178
179instance Pretty ValidLoopback where
179instance Pretty ValidLoopback where
180 pretty (ValidLoopback name maybeExpr tipe) =
180 pretty (ValidLoopback name maybeExpr tipe) =
181 P.vcat
181 P.vcat
182− [ prettyWire "loopback" name ":" tipe
182+ [ prettyWire "input" name ":" tipe
183− , maybe P.empty (prettyWire "loopback" name "<-") maybeExpr
183+ , maybe P.empty (prettyWire "input" name "<-") maybeExpr
184 ]
184 ]
185
185
186
186
187instance Pretty CanonicalLoopback where
187instance Pretty CanonicalLoopback where
188− pretty loopback =
188+ pretty input =
189− case loopback of
189+ case input of
190− Mailbox name tipe ->
190+ Address name tipe ->
191− prettyWire "loopback" name ":" tipe
191+ prettyWire "input" name ":" tipe
192
192
193 Promise name _promiseType expr resultType ->
193 Promise name _promiseType expr resultType ->
194 P.vcat
194 P.vcat
195− [ prettyWire "loopback" name ":" resultType
195+ [ prettyWire "input" name ":" resultType
196− , prettyWire "loopback" name "<-" expr
196+ , prettyWire "input" name "<-" expr
197 ]
197 ]
198
198
199
199
src/AST/Expression/General.hs+1−1
@@ -67,7 +67,7 @@ data Expr' ann def var
67
67
68
68
69data Source
69data Source
70− = Mailbox
70+ = Address
71 | PromiseStream
71 | PromiseStream
72 deriving (Show)
72 deriving (Show)
73
73
src/Generate/JavaScript.hs+2−2
@@ -216,8 +216,8 @@ expression (A region expr) =
216
216
217 LoopbackIn name source ->
217 LoopbackIn name source ->
218 case source of
218 case source of
219− Mailbox ->
219+ Address ->
220− return $ obj ["_P","mailbox"] `call` [ string name ]
220+ return $ obj ["_P","input"] `call` [ string name ]
221
221
222 PromiseStream ->
222 PromiseStream ->
223 return $ obj ["_P","loopbackIn"] `call` [ string name ]
223 return $ obj ["_P","loopbackIn"] `call` [ string name ]
src/Parse/Declaration.hs+16−16
@@ -12,7 +12,7 @@ import qualified Parse.Type as Type
12
12
13declaration :: IParser D.SourceDecl
13declaration :: IParser D.SourceDecl
14declaration =
14declaration =
15− typeDecl <|> infixDecl <|> loopback <|> input <|> output <|> definition
15+ typeDecl <|> infixDecl <|> foreign <|> input <|> definition
16
16
17
17
18definition :: IParser D.SourceDecl
18definition :: IParser D.SourceDecl
@@ -54,27 +54,27 @@ infixDecl =
54 D.Fixity assoc (read [n]) <$> anyOp
54 D.Fixity assoc (read [n]) <$> anyOp
55
55
56
56
57−input :: IParser D.SourceDecl
57+foreign :: IParser D.SourceDecl
58−input =
58+foreign =
59− do name <- wireBegining "input"
59+ do try (reserved "foreign")
60− wireEnding (D.InputAnnotation name) hasType Type.expr
60+ whitespace
61−
62−
63−output :: IParser D.SourceDecl
64−output =
65− do name <- wireBegining "output"
66 choice
61 choice
62+ [ do name <- wireBegining "input"
63+ wireEnding (D.InputAnnotation name) hasType Type.expr
64+ , do name <- wireBegining "output"
65+ choice
67− [ wireEnding (D.OutputAnnotation name) hasType Type.expr
66+ [ wireEnding (D.OutputAnnotation name) hasType Type.expr
68− , wireEnding (D.OutputDefinition name) equals Expr.expr
67+ , wireEnding (D.OutputDefinition name) equals Expr.expr
68+ ]
69 ]
69 ]
70
70
71
71
72−loopback :: IParser D.SourceDecl
72+input :: IParser D.SourceDecl
73−loopback =
73+input =
74− do name <- wireBegining "loopback"
74+ do name <- wireBegining "input"
75 choice
75 choice
76 [ wireEnding (D.LoopbackAnnotation name) hasType Type.expr
76 [ wireEnding (D.LoopbackAnnotation name) hasType Type.expr
77− , wireEnding (D.LoopbackDefinition name) (string "<-") Expr.expr
77+ , wireEnding (D.LoopbackDefinition name) (string "from") Expr.expr
78 ]
78 ]
79
79
80
80
src/Parse/Helpers.hs+1−1
@@ -33,7 +33,7 @@ reserveds =
33 , "import", "as", "hiding", "exposing"
33 , "import", "as", "hiding", "exposing"
34 , "export"
34 , "export"
35 , "deriving"
35 , "deriving"
36− , "input", "output", "loopback"
36+ , "input", "output", "foreign"
37 ]
37 ]
38
38
39
39
src/Transform/Canonicalize.hs+8−8
@@ -85,7 +85,7 @@ moduleHelp interfaces modul@(Module.Module _ _ exports _ decls) =
85 case wire of
85 case wire of
86 D.Input name _ -> name
86 D.Input name _ -> name
87 D.Output name _ _ -> name
87 D.Output name _ _ -> name
88− D.Loopback (D.Mailbox name _) -> name
88+ D.Loopback (D.Address name _) -> name
89 D.Loopback (D.Promise name _ _ _) -> name
89 D.Loopback (D.Promise name _ _ _) -> name
90
90
91
91
@@ -216,21 +216,21 @@ declaration env decl =
216 D.Wire <$>
216 D.Wire <$>
217 case wire of
217 case wire of
218 D.Input name tipe ->
218 D.Input name tipe ->
219− do tipe' <- canonicalize Canonicalize.tipe "input" name env tipe
219+ do tipe' <- canonicalize Canonicalize.tipe "foreign input" name env tipe
220− Wire.checkInput name tipe'
220+ Wire.checkForeignInput name tipe'
221 return (D.Input name tipe')
221 return (D.Input name tipe')
222
222
223 D.Output name expr tipe ->
223 D.Output name expr tipe ->
224 do expr' <- expression env expr
224 do expr' <- expression env expr
225− tipe' <- canonicalize Canonicalize.tipe "output" name env tipe
225+ tipe' <- canonicalize Canonicalize.tipe "foreign output" name env tipe
226− Wire.checkOutput name tipe'
226+ Wire.checkForeignOutput name tipe'
227 return (D.Output name expr' tipe')
227 return (D.Output name expr' tipe')
228
228
229 D.Loopback (D.ValidLoopback name maybeExpr tipe) ->
229 D.Loopback (D.ValidLoopback name maybeExpr tipe) ->
230 do maybeExpr' <- T.traverse (expression env) maybeExpr
230 do maybeExpr' <- T.traverse (expression env) maybeExpr
231− tipe' <- canonicalize Canonicalize.tipe "loopback" name env tipe
231+ tipe' <- canonicalize Canonicalize.tipe "input" name env tipe
232− loopback' <- Wire.loopback name maybeExpr' tipe'
232+ input' <- Wire.input name maybeExpr' tipe'
233− return (D.Loopback loopback')
233+ return (D.Loopback input')
234
234
235 D.Fixity assoc prec op ->
235 D.Fixity assoc prec op ->
236 return $ D.Fixity assoc prec op
236 return $ D.Fixity assoc prec op
src/Transform/Canonicalize/Wire.hs+34−34
@@ -1,4 +1,4 @@
1−module Transform.Canonicalize.Wire (checkInput, checkOutput, loopback) where
1+module Transform.Canonicalize.Wire (checkForeignInput, checkForeignOutput, input) where
2
2
3import Control.Applicative ((<$>))
3import Control.Applicative ((<$>))
4import Control.Monad.Error (forM_, throwError)
4import Control.Monad.Error (forM_, throwError)
@@ -17,45 +17,45 @@ throw err =
17 throwError [ P.vcat err ]
17 throwError [ P.vcat err ]
18
18
19
19
20−checkInput :: String -> ST.CanonicalType -> Env.Canonicalizer [P.Doc] ()
20+checkForeignInput :: String -> ST.CanonicalType -> Env.Canonicalizer [P.Doc] ()
21−checkInput name tipe =
21+checkForeignInput name tipe =
22− checkWire In name tipe tipe
22+ checkForeign In name tipe tipe
23
23
24
24
25−checkOutput :: String -> ST.CanonicalType -> Env.Canonicalizer [P.Doc] ()
25+checkForeignOutput :: String -> ST.CanonicalType -> Env.Canonicalizer [P.Doc] ()
26−checkOutput name tipe =
26+checkForeignOutput name tipe =
27− checkWire Out name tipe tipe
27+ checkForeign Out name tipe tipe
28
28
29
29
30data Direction = In | Out
30data Direction = In | Out
31
31
32
32
33−checkWire
33+checkForeign
34 :: Direction
34 :: Direction
35 -> String
35 -> String
36 -> ST.CanonicalType
36 -> ST.CanonicalType
37 -> ST.CanonicalType
37 -> ST.CanonicalType
38 -> Env.Canonicalizer [P.Doc] ()
38 -> Env.Canonicalizer [P.Doc] ()
39−checkWire direction name rootType tipe =
39+checkForeign direction name rootType tipe =
40 case tipe of
40 case tipe of
41 ST.Aliased _ args t ->
41 ST.Aliased _ args t ->
42− checkWire direction name rootType (ST.dealias args t)
42+ checkForeign direction name rootType (ST.dealias args t)
43
43
44 ST.App (ST.Type signal) [t]
44 ST.App (ST.Type signal) [t]
45 | Var.isStream signal ->
45 | Var.isStream signal ->
46− validWireType False (Just Stream) direction name rootType t
46+ validForeignType False (Just Stream) direction name rootType t
47
47
48 | Var.isVarying signal ->
48 | Var.isVarying signal ->
49− validWireType False (Just Varying) direction name rootType t
49+ validForeignType False (Just Varying) direction name rootType t
50
50
51 _ ->
51 _ ->
52− validWireType False Nothing direction name rootType tipe
52+ validForeignType False Nothing direction name rootType tipe
53
53
54
54
55data Signal = Stream | Varying
55data Signal = Stream | Varying
56
56
57
57
58−validWireType
58+validForeignType
59 :: Bool
59 :: Bool
60 -> Maybe Signal
60 -> Maybe Signal
61 -> Direction
61 -> Direction
@@ -63,12 +63,12 @@ validWireType
63 -> ST.CanonicalType
63 -> ST.CanonicalType
64 -> ST.CanonicalType
64 -> ST.CanonicalType
65 -> Env.Canonicalizer [P.Doc] ()
65 -> Env.Canonicalizer [P.Doc] ()
66−validWireType seenFunc seenSignal direction name rootType tipe =
66+validForeignType seenFunc seenSignal direction name rootType tipe =
67 let valid localType =
67 let valid localType =
68− validWireType seenFunc seenSignal direction name rootType localType
68+ validForeignType seenFunc seenSignal direction name rootType localType
69
69
70 err kind =
70 err kind =
71− throw (wireError name direction rootType tipe kind)
71+ throw (foreignError name direction rootType tipe kind)
72 in
72 in
73 case tipe of
73 case tipe of
74 ST.Aliased _ args t ->
74 ST.Aliased _ args t ->
@@ -112,7 +112,7 @@ validWireType seenFunc seenSignal direction name rootType tipe =
112
112
113 Nothing ->
113 Nothing ->
114 forM_ (ST.collectLambdas tipe)
114 forM_ (ST.collectLambdas tipe)
115− (validWireType True seenSignal direction name rootType)
115+ (validForeignType True seenSignal direction name rootType)
116
116
117 ST.Record _ (Just _) ->
117 ST.Record _ (Just _) ->
118 err "It contains extended records with free type variables"
118 err "It contains extended records with free type variables"
@@ -121,22 +121,22 @@ validWireType seenFunc seenSignal direction name rootType tipe =
121 mapM_ (\(k,v) -> (,) k <$> valid v) fields
121 mapM_ (\(k,v) -> (,) k <$> valid v) fields
122
122
123
123
124−wireError
124+foreignError
125 :: String
125 :: String
126 -> Direction
126 -> Direction
127 -> ST.CanonicalType
127 -> ST.CanonicalType
128 -> ST.CanonicalType
128 -> ST.CanonicalType
129 -> String
129 -> String
130 -> [P.Doc]
130 -> [P.Doc]
131−wireError name direction rootType localType problemMessage =
131+foreignError name direction rootType localType problemMessage =
132− [ P.text (dir "Input" "Output" ++ " Error:")
132+ [ P.text ("Foreign " ++ dir "Input" "Output" ++ " Error:")
133 , P.nest 4 $
133 , P.nest 4 $
134 P.vcat
134 P.vcat
135− [ txt [ "The ", wire, " named '", name, "' has an invalid type.\n" ]
135+ [ txt [ "The foreign ", wire, " named '", name, "' has an invalid type.\n" ]
136 , P.nest 4 (PP.pretty rootType) <> P.text "\n"
136 , P.nest 4 (PP.pretty rootType) <> P.text "\n"
137 , txt [ problemMessage, ":\n" ]
137 , txt [ problemMessage, ":\n" ]
138 , P.nest 4 (PP.pretty localType) <> P.text "\n"
138 , P.nest 4 (PP.pretty localType) <> P.text "\n"
139− , txt [ "Acceptable values for ", wire, "s include:" ]
139+ , txt [ "Acceptable values for foreign ", wire, "s include:" ]
140 , txt [ " Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, Tuples, unit values," ]
140 , txt [ " Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, Tuples, unit values," ]
141 , txt [ " Json.Values, ", dir "" "first-order functions, promises, ", "and concrete records." ]
141 , txt [ " Json.Values, ", dir "" "first-order functions, promises, ", "and concrete records." ]
142 ]
142 ]
@@ -153,12 +153,12 @@ wireError name direction rootType localType problemMessage =
153 dir "input" "output"
153 dir "input" "output"
154
154
155
155
156−loopback
156+input
157 :: String
157 :: String
158 -> Maybe Canonical.Expr
158 -> Maybe Canonical.Expr
159 -> ST.CanonicalType
159 -> ST.CanonicalType
160 -> Env.Canonicalizer [P.Doc] D.CanonicalLoopback
160 -> Env.Canonicalizer [P.Doc] D.CanonicalLoopback
161−loopback name maybeExpr tipe =
161+input name maybeExpr tipe =
162 case maybeExpr of
162 case maybeExpr of
163 Nothing ->
163 Nothing ->
164 case ST.deepDealias tipe of
164 case ST.deepDealias tipe of
@@ -168,12 +168,12 @@ loopback name maybeExpr tipe =
168 ]
168 ]
169 Nothing
169 Nothing
170 | Var.isStream stream && Var.isAddress address && a == b ->
170 | Var.isStream stream && Var.isAddress address && a == b ->
171− return (D.Mailbox name tipe)
171+ return (D.Address name tipe)
172
172
173
173
174 _ ->
174 _ ->
175− throw $ loopbackError name tipe $
175+ throw $ inputError name tipe $
176− [ P.text "A loopback like this must be a Mailbox." ]
176+ [ P.text "An input like this must be a Stream.Input" ]
177
177
178 Just expr ->
178 Just expr ->
179 case ST.deepDealias tipe of
179 case ST.deepDealias tipe of
@@ -187,20 +187,20 @@ loopback name maybeExpr tipe =
187 return (D.Promise name promiseType expr tipe)
187 return (D.Promise name promiseType expr tipe)
188
188
189 _ ->
189 _ ->
190− throw $ loopbackError name tipe $
190+ throw $ inputError name tipe $
191− [ P.text "A loopback that runs promises must be a stream of results."
191+ [ P.text "An input that runs promises must be a stream of results."
192 , P.text "Something like the following:\n"
192 , P.text "Something like the following:\n"
193 , P.text " Stream (Result Http.Error String)"
193 , P.text " Stream (Result Http.Error String)"
194 , P.text " Stream (Result x ())"
194 , P.text " Stream (Result x ())"
195 ]
195 ]
196
196
197
197
198−loopbackError :: String -> ST.CanonicalType -> [Doc] -> [Doc]
198+inputError :: String -> ST.CanonicalType -> [Doc] -> [Doc]
199−loopbackError name tipe message =
199+inputError name tipe message =
200− [ P.text "Loopback Error:"
200+ [ P.text "Input Error:"
201 , P.nest 4 $
201 , P.nest 4 $
202 P.vcat $
202 P.vcat $
203− [ P.text ("The loopback named '" ++ name ++ "' has an invalid type.\n")
203+ [ P.text ("The input named '" ++ name ++ "' has an invalid type.\n")
204 , P.nest 4 (PP.pretty tipe) <> P.text "\n"
204 , P.nest 4 (PP.pretty tipe) <> P.text "\n"
205 ]
205 ]
206 ++ message
206 ++ message
src/Transform/Declaration.hs+7−7
@@ -69,7 +69,7 @@ combineAnnotations =
69 (:) (D.Wire (D.Input name tipe)) <$> go wireRest
69 (:) (D.Wire (D.Input name tipe)) <$> go wireRest
70
70
71 D.OutputDefinition name _ ->
71 D.OutputDefinition name _ ->
72− Left (errorMessage "output" name)
72+ Left (errorMessage "foreign output" name)
73
73
74 D.OutputAnnotation name tipe ->
74 D.OutputAnnotation name tipe ->
75 case wireRest of
75 case wireRest of
@@ -78,10 +78,10 @@ combineAnnotations =
78 (:) (D.Wire (D.Output name expr' tipe)) <$> go rest
78 (:) (D.Wire (D.Output name expr' tipe)) <$> go rest
79
79
80 _ ->
80 _ ->
81− Left (errorMessage "output" name)
81+ Left (errorMessage "foreign output" name)
82
82
83 D.LoopbackDefinition name _tipe ->
83 D.LoopbackDefinition name _tipe ->
84− Left (errorMessage "loopback" name)
84+ Left (errorMessage "input" name)
85
85
86 D.LoopbackAnnotation name tipe ->
86 D.LoopbackAnnotation name tipe ->
87 case wireRest of
87 case wireRest of
@@ -149,10 +149,10 @@ toDefs moduleName decl =
149 D.Input name tipe ->
149 D.Input name tipe ->
150 [ definition name (A.none $ E.Input name tipe) tipe ]
150 [ definition name (A.none $ E.Input name tipe) tipe ]
151
151
152− D.Loopback loopback ->
152+ D.Loopback input ->
153− case loopback of
153+ case input of
154− D.Mailbox name tipe ->
154+ D.Address name tipe ->
155− [ definition name (A.none $ E.LoopbackIn name E.Mailbox) tipe ]
155+ [ definition name (A.none $ E.LoopbackIn name E.Address) tipe ]
156
156
157 D.Promise name promiseType expr resultType ->
157 D.Promise name promiseType expr resultType ->
158 let dummyName =
158 let dummyName =