on master help sign in
make it possible to parse (-- line comments
6b646d8Evan Czaplicki
compiler/src/Parse/Expression.hs+40−32
@@ -128,38 +128,46 @@ chompListEnd start entries =
128tuple :: A.Position -> Parser E.Expr Src.Expr
128tuple :: A.Position -> Parser E.Expr Src.Expr
129tuple start@(A.Position row col) =
129tuple start@(A.Position row col) =
130 inContext E.Tuple (word1 0x28 {-(-} E.Start) $
130 inContext E.Tuple (word1 0x28 {-(-} E.Start) $
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
131− oneOf E.TupleIndentExpr1
140+ oneOf E.TupleIndentExpr1
132− [
141+ [
133− do op <- Symbol.operator E.TupleIndentExpr1 E.TupleOperatorReserved
142+ do op <- Symbol.operator E.TupleIndentExpr1 E.TupleOperatorReserved
134− if op == "-"
143+ if op == "-"
135− then
144+ then
136− oneOf E.TupleOperatorClose
145+ oneOf E.TupleOperatorClose
137− [
146+ [
138− do word1 0x29 {-)-} E.TupleOperatorClose
147+ do word1 0x29 {-)-} E.TupleOperatorClose
139− addEnd start (Src.Op op)
148+ addEnd start (Src.Op op)
140− ,
149+ ,
141− do (entry, end) <-
150+ do (entry, end) <-
142− specialize E.TupleExpr $
151+ specialize E.TupleExpr $
143− do negatedExpr@(A.At (A.Region _ end) _) <- term
152+ do negatedExpr@(A.At (A.Region _ end) _) <- term
144− Space.chomp E.Space
153+ Space.chomp E.Space
145− let exprStart = A.Position row (col + 2)
154+ let exprStart = A.Position row (col + 2)
146− let expr = A.at exprStart end (Src.Negate negatedExpr)
155+ let expr = A.at exprStart end (Src.Negate negatedExpr)
147− chompExprEnd exprStart (State [] expr [] end)
156+ chompExprEnd exprStart (State [] expr [] end)
148− Space.checkIndent end E.TupleIndentEnd
157+ Space.checkIndent end E.TupleIndentEnd
149− chompTupleEnd start entry []
158+ chompTupleEnd start entry []
150− ]
159+ ]
151− else
160+ else
152− do word1 0x29 {-)-} E.TupleOperatorClose
161+ do word1 0x29 {-)-} E.TupleOperatorClose
153− addEnd start (Src.Op op)
162+ addEnd start (Src.Op op)
154− ,
163+ ,
155− do word1 0x29 {-)-} E.TupleIndentExpr1
164+ do word1 0x29 {-)-} E.TupleIndentExpr1
156− addEnd start Src.Unit
165+ addEnd start Src.Unit
157− ,
166+ ,
158− do Space.chompAndCheckIndent E.TupleSpace E.TupleIndentExpr1
159− (entry, end) <- specialize E.TupleExpr expression
167+ do (entry, end) <- specialize E.TupleExpr expression
160− Space.checkIndent end E.TupleIndentEnd
168+ Space.checkIndent end E.TupleIndentEnd
161− chompTupleEnd start entry []
169+ chompTupleEnd start entry []
162− ]
170+ ]
163
171
164
172
165chompTupleEnd :: A.Position -> Src.Expr -> [Src.Expr] -> Parser E.Tuple Src.Expr
173chompTupleEnd :: A.Position -> Src.Expr -> [Src.Expr] -> Parser E.Tuple Src.Expr