@@ -132,8 +132,11 @@ parensTerm =
132132recordTerm :: IParser Source.Expr
133133recordTerm =
134134 addLocation $
135− brackets $ choice [ misc, record ]
135+ brackets (choice [ misc, record ])
136136 where
137+ record =
138+ E.Record <$> commaSep field
139+
137140 field =
138141 do label <- rLabel
139142 patterns <- spacePrefix Pattern.term
@@ -141,38 +144,53 @@ recordTerm =
141144 body <- expr
142145 return (label, makeFunction patterns body)
143146
144− record =
145− E.Record <$> commaSep field
146−
147− change =
148− do lbl <- rLabel
149− padded (string "<-")
150− (,) lbl <$> expr
151−
152− remove r =
153− do string "-"
147+ misc =
148+ do nextParser <- try miscStarter
154149 whitespace
155− E.Remove r <$> rLabel
150+ nextParser
156151
157− insert r =
158− do string "|"
152+ miscStarter =
153+ do start <- getMyPosition
154+ record <- addLocation (E.rawVar <$> rLabel)
159155 whitespace
160− E.Insert r <$> rLabel <*> (padded equals >> expr)
156+ choice
157+ [ string "-" >> return (afterMinus start record)
158+ , string "|" >> return (afterBar record)
159+ ]
161160
162− modify r =
163− do string "|"
161+ afterMinus start record =
162+ do field <- rLabel
163+ end <- getMyPosition
164+ let subRecord' = E.Remove record field
165+ maybe <- optionMaybe (try (whitespace >> string "|"))
166+ case maybe of
167+ Nothing ->
168+ return subRecord'
169+ Just _ ->
170+ do whitespace
171+ field <- rLabel
172+ padded equals
173+ E.Insert (A.at start end subRecord') field <$> expr
174+
175+ afterBar record =
176+ do field <- rLabel
164177 whitespace
165− E.Modify r <$> commaSep1 change
178+ choice
179+ [ do equals
180+ whitespace
181+ E.Insert record field <$> expr
182+ , do string "<-"
183+ whitespace
184+ value <- expr
185+ updates <- spaceyPrefixBy comma update
186+ return (E.Modify record ((field,value) : updates))
187+ ]
188+
189+ update =
190+ do lbl <- rLabel
191+ padded (string "<-")
192+ (,) lbl <$> expr
166193
167− misc =
168− try $ do
169− record <- addLocation (E.rawVar <$> rLabel)
170− opt <- padded (optionMaybe (addLocation (remove record)))
171− case opt of
172− Just e@(A.A _ e') ->
173− try (insert e) <|> return e'
174− Nothing ->
175− try (insert record) <|> try (modify record)
176194
177195
178196term :: IParser Source.Expr