summaryrefslogtreecommitdiff
path: root/src/Parser.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2023-02-05 20:46:04 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2023-02-05 20:46:04 +0100
commit4603b8e9b1d2b99b8286c82d55ac18ba00fe7331 (patch)
tree3041c6fde414555d1f046cc8fd4a5d999ed883bf /src/Parser.hs
parent30b2adf6f0caa11c5d11ff712290c0a60c37afde (diff)
List expression type
Diffstat (limited to 'src/Parser.hs')
-rw-r--r--src/Parser.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Parser.hs b/src/Parser.hs
index b67ce55..51fc0f0 100644
--- a/src/Parser.hs
+++ b/src/Parser.hs
@@ -208,6 +208,19 @@ regex = label "regular expression" $ lexeme $ do
_ <- eval expr -- test regex parsing with empty variables
return expr
+list :: TestParser SomeExpr
+list = label "list" $ do
+ symbol "["
+ SomeExpr x <- someExpr
+ choice
+ [do symbol "]"
+ return $ SomeExpr $ UnOp (:[]) x
+ ,do symbol ","
+ xs <- listOf typedExpr
+ symbol "]"
+ return $ SomeExpr $ foldr (BinOp (:)) (Literal []) (x:xs)
+ ]
+
data SomeExpr = forall a. ExprType a => SomeExpr (Expr a)
data SomeUnOp = forall a b. (ExprType a, ExprType b) => SomeUnOp (a -> b)
@@ -310,6 +323,7 @@ someExpr = join inner <?> "expression"
[ return <$> numberLiteral
, return . SomeExpr <$> quotedString
, return . SomeExpr <$> regex
+ , return <$> list
]
variable = label "variable" $ do