@@ -136,65 +136,40 @@ parensTerm =
136136
137137recordTerm :: IParser Source.Expr
138138recordTerm =
139− addLocation $
140− brackets (choice [ misc, record ])
141− where
142− record =
143− E.Record <$> commaSep field
144−
145− field =
146− do label <- rLabel
147− patterns <- spacePrefix Pattern.term
148− padded equals
149− body <- expr
150− return (label, makeFunction patterns body)
151−
152− misc =
153− do nextParser <- try miscStarter
154− whitespace
155− nextParser
156−
157− miscStarter =
158− do start <- getMyPosition
159− record <- addLocation (E.rawVar <$> rLabel)
139+ addLocation $ brackets $ choice $
140+ [ do starter <- try (addLocation rLabel)
160141 whitespace
161142 choice
162− [ string "-" >> return (afterMinus start record)
163− , string "|" >> return (afterBar record)
143+ [ update starter
144+ , literal starter
164145 ]
146+ , return (E.Record [])
147+ ]
148+ where
149+ update (A.A ann starter) =
150+ do try (string "|")
151+ whitespace
152+ fields <- commaSep1 field
153+ return (E.Update (A.A ann (E.rawVar starter)) fields)
165154
166− afterMinus start record =
167− do field <- rLabel
168− end <- getMyPosition
169− let subRecord' = E.Remove record field
170− maybe <- optionMaybe (try (whitespace >> string "|"))
171− case maybe of
172− Nothing ->
173− return subRecord'
174− Just _ ->
175− do whitespace
176− field <- rLabel
177− padded equals
178− E.Insert (A.at start end subRecord') field <$> expr
179−
180− afterBar record =
181− do field <- rLabel
155+ literal (A.A _ starter) =
156+ do try equals
157+ whitespace
158+ value <- expr
182159 whitespace
183160 choice
184− [ do equals
161+ [ do try comma
185162 whitespace
186− E.Insert record field <$> expr
187− , do leftArrow
188− whitespace
189− value <- expr
190− updates <- spaceyPrefixBy comma update
191− return (E.Modify record ((field,value) : updates))
163+ fields <- commaSep field
164+ return (E.Record ((starter, value) : fields))
165+ , return (E.Record [(starter, value)])
192166 ]
193167
194− update =
195− do lbl <- rLabel
196− padded leftArrow
197− (,) lbl <$> expr
168+ field =
169+ do key <- rLabel
170+ padded equals
171+ value <- expr
172+ return (key, value)
198173
199174
200175term :: IParser Source.Expr