summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2022-09-02 21:02:01 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2022-09-02 21:02:01 +0200
commit4afe27c6da9cf37ca3666ff95c5cb096e03fb20b (patch)
tree7a53dfde812823faff4a673c47214b760f66dd4a /src
parent6e183bf63ad75da44a030d0d6f5060e8b745d2ca (diff)
Regex expression instance
Diffstat (limited to 'src')
-rw-r--r--src/Parser.hs1
-rw-r--r--src/Test.hs35
2 files changed, 21 insertions, 15 deletions
diff --git a/src/Parser.hs b/src/Parser.hs
index 027c358..5a5ec28 100644
--- a/src/Parser.hs
+++ b/src/Parser.hs
@@ -259,6 +259,7 @@ someExpr = join inner <?> "expression"
literal = label "literal" $ choice
[ return . SomeExpr <$> integerLiteral
, return . SomeExpr <$> quotedString
+ , return . SomeExpr <$> regex
]
variable = label "variable" $ do
diff --git a/src/Test.hs b/src/Test.hs
index 7d932af..a2419a7 100644
--- a/src/Test.hs
+++ b/src/Test.hs
@@ -67,25 +67,30 @@ unpackVarName = T.unpack . textVarName
class Typeable a => ExprType a where
- textExprType :: proxy a -> Text
- textExprValue :: a -> Text
- emptyVarValue :: a
+ textExprType :: proxy a -> Text
+ textExprValue :: a -> Text
+ emptyVarValue :: a
instance ExprType Integer where
- textExprType _ = T.pack "integer"
- textExprValue x = T.pack (show x)
- emptyVarValue = 0
-
-instance ExprType Text where
- textExprType _ = T.pack "string"
- textExprValue x = T.pack (show x)
- emptyVarValue = T.empty
+ textExprType _ = T.pack "integer"
+ textExprValue x = T.pack (show x)
+ emptyVarValue = 0
instance ExprType Bool where
- textExprType _ = T.pack "bool"
- textExprValue True = T.pack "true"
- textExprValue False = T.pack "false"
- emptyVarValue = False
+ textExprType _ = T.pack "bool"
+ textExprValue True = T.pack "true"
+ textExprValue False = T.pack "false"
+ emptyVarValue = False
+
+instance ExprType Text where
+ textExprType _ = T.pack "string"
+ textExprValue x = T.pack (show x)
+ emptyVarValue = T.empty
+
+instance ExprType Regex where
+ textExprType _ = T.pack "regex"
+ textExprValue _ = T.pack "<regex>"
+ emptyVarValue = either error id $ compile defaultCompOpt defaultExecOpt T.empty
data SomeVarValue = forall a. ExprType a => SomeVarValue a