diff options
-rw-r--r-- | src/Parser.hs | 1 | ||||
-rw-r--r-- | src/Test.hs | 35 |
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 |