@@ -18,8 +18,6 @@ import qualified AST.Literal as L
18import qualified AST.Pattern as P
18import qualified AST.Pattern as P
19import qualified AST.Variable as Var
19import qualified AST.Variable as Var
20import qualified Reporting.Annotation as A
20import qualified Reporting.Annotation as A
21−import qualified Reporting.Crash as Crash
22−import qualified Reporting.Region as R
25-------- Basic Terms --------
23-------- Basic Terms --------
@@ -136,65 +134,40 @@ parensTerm =
137recordTerm :: IParser Source.Expr
135recordTerm :: IParser Source.Expr
138recordTerm =
136recordTerm =
139− addLocation $
137+ addLocation $ brackets $ choice $
140− brackets (choice [ misc, record ])
143− E.Record <$> commaSep field
147− patterns <- spacePrefix Pattern.term
150− return (label, makeFunction patterns body)
153− do nextParser <- try miscStarter
158− do start <- getMyPosition
159− record <- addLocation (E.rawVar <$> rLabel)
138+ [ do starter <- try (addLocation rLabel)
160 whitespace
139 whitespace
162− [ string "-" >> return (afterMinus start record)
141+ [ update starter
163− , string "|" >> return (afterBar record)
142+ , literal starter
144+ , return (E.Record [])
147+ update (A.A ann starter) =
150+ fields <- commaSep1 field
151+ return (E.Update (A.A ann (E.rawVar starter)) fields)
166− afterMinus start record =
153+ literal (A.A _ starter) =
168− end <- getMyPosition
169− let subRecord' = E.Remove record field
170− maybe <- optionMaybe (try (whitespace >> string "|"))
177− padded equals
154+ do try equals
178− E.Insert (A.at start end subRecord') field <$> expr
155+ whitespace
182 whitespace
157 whitespace
184− [ do equals
159+ [ do try comma
185 whitespace
160 whitespace
186− E.Insert record field <$> expr
161+ fields <- commaSep field
187− , do leftArrow
162+ return (E.Record ((starter, value) : fields))
188− whitespace
163+ , return (E.Record [(starter, value)])
190− updates <- spaceyPrefixBy comma update
191− return (E.Modify record ((field,value) : updates))
194− update =
166+ field =
195− do lbl <- rLabel
167+ do key <- rLabel
196− padded leftArrow
168+ padded equals
197− (,) lbl <$> expr
169+ value <- expr
200term :: IParser Source.Expr
173term :: IParser Source.Expr
@@ -222,8 +195,7 @@ appExpr =
223expr :: IParser Source.Expr
196expr :: IParser Source.Expr
225− addLocation (choice [ letExpr, caseExpr ])
198+ addLocation (choice [ letExpr, caseExpr, ifExpr ])
227 <|> lambdaExpr
199 <|> lambdaExpr
228 <|> binaryExpr
200 <|> binaryExpr
229 <?> "an expression"
201 <?> "an expression"
@@ -234,45 +206,31 @@ binaryExpr =
234 Binop.binops appExpr lastExpr anyOp
206 Binop.binops appExpr lastExpr anyOp
236 lastExpr =
208 lastExpr =
237− addLocation (choice [ letExpr, caseExpr ])
209+ addLocation (choice [ letExpr, caseExpr, ifExpr ])
239 <|> lambdaExpr
210 <|> lambdaExpr
240 <?> "an expression"
211 <?> "an expression"
243−ifExpr :: IParser Source.Expr
214+ifExpr :: IParser Source.Expr'
245− do start <- getMyPosition
216+ ifHelp []
248− makeExpr <- normal <|> multiIf
249− end <- getMyPosition
250− return (makeExpr (R.Region start end))
253− do condition <- expr
254− padded (reserved "then")
256− whitespace <?> "an 'else' branch"
257− reserved "else" <?> "an 'else' branch"
260− return $ \region -> A.A region (E.MultiIf [(condition, thenBranch)] elseBranch)
263− do branches <- spaceSep1 multiBranch
264− return $ \region -> A.A region (E.MultiIf branches (crash region))
266− crash region =
219+ifHelp :: [(Source.Expr, Source.Expr)] -> IParser Source.Expr'
267− A.A region (E.Crash (Crash.IncompleteMultiIf region))
220+ifHelp branches =
268−
221+ do try (reserved "if")
271− whitespace
222+ whitespace
272− condition <- expr
223+ condition <- expr
273− padded rightArrow
224+ padded (reserved "then")
274− branch <- expr
225+ thenBranch <- expr
275− return (condition, branch)
226+ whitespace <?> "an 'else' branch"
227+ reserved "else" <?> "an 'else' branch"
229+ let newBranches = (condition, thenBranch) : branches
231+ [ ifHelp newBranches
232+ , E.If (reverse newBranches) <$> expr
278lambdaExpr :: IParser Source.Expr
236lambdaExpr :: IParser Source.Expr