on master help sign in
make it possible to parse (-- line comments

Another tricky case with the operators-as-functions syntax.

commit6b646d898c100ad531c17c0c41e618808ce4529c authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 11 Jul 2019, 15:07 (7 years ago) parentb64b554
1 file changed+40−32
compiler/src/Parse/Expression.hs+40−32
compiler/src/Parse/Expression.hs+40−32
@@ -128,38 +128,46 @@ chompListEnd start entries =
128128tuple :: A.Position -> Parser E.Expr Src.Expr
129129tuple start@(A.Position row col) =
130130 inContext E.Tuple (word1 0x28 {-(-} E.Start) $
131− oneOf E.TupleIndentExpr1
132− [
133− do op <- Symbol.operator E.TupleIndentExpr1 E.TupleOperatorReserved
134− if op == "-"
135− then
136− oneOf E.TupleOperatorClose
137− [
138− do word1 0x29 {-)-} E.TupleOperatorClose
139− addEnd start (Src.Op op)
140− ,
141− do (entry, end) <-
142− specialize E.TupleExpr $
143− do negatedExpr@(A.At (A.Region _ end) _) <- term
144− Space.chomp E.Space
145− let exprStart = A.Position row (col + 2)
146− let expr = A.at exprStart end (Src.Negate negatedExpr)
147− chompExprEnd exprStart (State [] expr [] end)
148− Space.checkIndent end E.TupleIndentEnd
149− chompTupleEnd start entry []
150− ]
151− else
152− do word1 0x29 {-)-} E.TupleOperatorClose
153− addEnd start (Src.Op op)
154− ,
155− do word1 0x29 {-)-} E.TupleIndentExpr1
156− addEnd start Src.Unit
157− ,
158− do Space.chompAndCheckIndent E.TupleSpace E.TupleIndentExpr1
159− (entry, end) <- specialize E.TupleExpr expression
160− Space.checkIndent end E.TupleIndentEnd
161− chompTupleEnd start entry []
162− ]
131+ do before <- getPosition
132+ Space.chompAndCheckIndent E.TupleSpace E.TupleIndentExpr1
133+ after <- getPosition
134+ if before /= after
135+ then
136+ do (entry, end) <- specialize E.TupleExpr expression
137+ Space.checkIndent end E.TupleIndentEnd
138+ chompTupleEnd start entry []
139+ else
140+ oneOf E.TupleIndentExpr1
141+ [
142+ do op <- Symbol.operator E.TupleIndentExpr1 E.TupleOperatorReserved
143+ if op == "-"
144+ then
145+ oneOf E.TupleOperatorClose
146+ [
147+ do word1 0x29 {-)-} E.TupleOperatorClose
148+ addEnd start (Src.Op op)
149+ ,
150+ do (entry, end) <-
151+ specialize E.TupleExpr $
152+ do negatedExpr@(A.At (A.Region _ end) _) <- term
153+ Space.chomp E.Space
154+ let exprStart = A.Position row (col + 2)
155+ let expr = A.at exprStart end (Src.Negate negatedExpr)
156+ chompExprEnd exprStart (State [] expr [] end)
157+ Space.checkIndent end E.TupleIndentEnd
158+ chompTupleEnd start entry []
159+ ]
160+ else
161+ do word1 0x29 {-)-} E.TupleOperatorClose
162+ addEnd start (Src.Op op)
163+ ,
164+ do word1 0x29 {-)-} E.TupleIndentExpr1
165+ addEnd start Src.Unit
166+ ,
167+ do (entry, end) <- specialize E.TupleExpr expression
168+ Space.checkIndent end E.TupleIndentEnd
169+ chompTupleEnd start entry []
170+ ]
163171
164172
165173chompTupleEnd :: A.Position -> Src.Expr -> [Src.Expr] -> Parser E.Tuple Src.Expr