summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Parser.hs14
-rw-r--r--src/Test.hs5
2 files changed, 19 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
diff --git a/src/Test.hs b/src/Test.hs
index b2644b6..b6a85ae 100644
--- a/src/Test.hs
+++ b/src/Test.hs
@@ -96,6 +96,11 @@ instance ExprType Regex where
textExprValue _ = T.pack "<regex>"
emptyVarValue = either error id $ regexCompile T.empty
+instance ExprType a => ExprType [a] where
+ textExprType _ = "[" <> textExprType @a Proxy <> "]"
+ textExprValue x = "[" <> T.intercalate ", " (map textExprValue x) <> "]"
+ emptyVarValue = []
+
data SomeVarValue = forall a. ExprType a => SomeVarValue a
data RecordSelector a = forall b. ExprType b => RecordSelector (a -> b)