on master help sign in
Fix bug in parsing expressions like (-1, 100)

Need to add chompTupleEnd after seeing that (- is the beginning of a negative number or some other negated expression.

commit189ba1004cb2ae8a3bf63810f6f032ed2a329749 authorEvan Czaplicki <evancz@users.noreply.github.com> dateTue 7 May 2019, 14:10 (7 years ago) parent2bc07b6
1 file changed+14−11
compiler/src/Parse/Expression.hs+14−11
compiler/src/Parse/Expression.hs+14−11
@@ -128,9 +128,9 @@ 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.TupleOpen
131+ oneOf E.TupleIndentExpr1
132132 [
133− do op <- Symbol.operator E.TupleOpen E.TupleOperatorReserved
133+ do op <- Symbol.operator E.TupleIndentExpr1 E.TupleOperatorReserved
134134 if op == "-"
135135 then
136136 oneOf E.TupleOperatorClose
@@ -138,21 +138,24 @@ tuple start@(A.Position row col) =
138138 do word1 0x29 {-)-} E.TupleOperatorClose
139139 addEnd start (Src.Op op)
140140 ,
141− specialize E.TupleExpr $
142− do negatedExpr@(A.At (A.Region _ end) _) <- term
143− Space.chomp E.Space
144− let exprStart = A.Position row (col + 2)
145− let expr = A.at exprStart end (Src.Negate negatedExpr)
146− fst <$> chompExprEnd exprStart (State [] expr [] end)
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 []
147150 ]
148151 else
149152 do word1 0x29 {-)-} E.TupleOperatorClose
150153 addEnd start (Src.Op op)
151154 ,
152− do word1 0x29 {-)-} E.TupleOpen
155+ do word1 0x29 {-)-} E.TupleIndentExpr1
153156 addEnd start Src.Unit
154157 ,
155− do Space.chompAndCheckIndent E.TupleSpace E.TupleIndentExpr
158+ do Space.chompAndCheckIndent E.TupleSpace E.TupleIndentExpr1
156159 (entry, end) <- specialize E.TupleExpr expression
157160 Space.checkIndent end E.TupleIndentEnd
158161 chompTupleEnd start entry []
@@ -163,7 +166,7 @@ chompTupleEnd :: A.Position -> Src.Expr -> [Src.Expr] -> Parser E.Tuple Src.Expr
163166chompTupleEnd start firstExpr revExprs =
164167 oneOf E.TupleEnd
165168 [ do word1 0x2C {-,-} E.TupleEnd
166− Space.chompAndCheckIndent E.TupleSpace E.TupleIndentExpr
169+ Space.chompAndCheckIndent E.TupleSpace E.TupleIndentExprN
167170 (entry, end) <- specialize E.TupleExpr expression
168171 Space.checkIndent end E.TupleIndentEnd
169172 chompTupleEnd start firstExpr (entry : revExprs)