summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2023-04-24 22:11:51 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2023-04-24 22:11:51 +0200
commit7ed6a184f15975d694657124c01d00ef6b394531 (patch)
tree371f1abdffbc094904cf690474e21c21f8d005a8
parentbb0a52edc8d0e846c72f9703acb09e6882a1726e (diff)
Fix parsing of two-element lists
-rw-r--r--src/Parser/Expr.hs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/Parser/Expr.hs b/src/Parser/Expr.hs
index d609e6c..eefc5cc 100644
--- a/src/Parser/Expr.hs
+++ b/src/Parser/Expr.hs
@@ -136,32 +136,36 @@ list = label "list" $ do
let enumErr off = parseError $ FancyError off $ S.singleton $ ErrorFail $ T.unpack $
"list range enumeration not defined for '" <> textExprType x <> "'"
- choice
+ let exprList = foldr (liftA2 (:)) (Pure [])
+ SomeExpr <$> choice
[do symbol "]"
- return $ SomeExpr $ fmap (:[]) x
+ return $ exprList [x]
,do off <- stateOffset <$> getParserState
osymbol ".."
ExprEnumerator fromTo _ <- maybe (enumErr off) return $ exprEnumerator x
y <- typedExpr
symbol "]"
- return $ SomeExpr $ fromTo <$> x <*> y
+ return $ fromTo <$> x <*> y
,do symbol ","
y <- typedExpr
choice
- [do off <- stateOffset <$> getParserState
+ [do symbol "]"
+ return $ exprList [x, y]
+
+ ,do off <- stateOffset <$> getParserState
osymbol ".."
ExprEnumerator _ fromThenTo <- maybe (enumErr off) return $ exprEnumerator x
z <- typedExpr
symbol "]"
- return $ SomeExpr $ fromThenTo <$> x <*> y <*> z
+ return $ fromThenTo <$> x <*> y <*> z
,do symbol ","
xs <- listOf typedExpr
symbol "]"
- return $ SomeExpr $ foldr (liftA2 (:)) (Pure []) (x:y:xs)
+ return $ exprList (x:y:xs)
]
]