From 4afe27c6da9cf37ca3666ff95c5cb096e03fb20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Fri, 2 Sep 2022 21:02:01 +0200 Subject: Regex expression instance --- src/Parser.hs | 1 + src/Test.hs | 35 ++++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) (limited to 'src') 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 "" + emptyVarValue = either error id $ compile defaultCompOpt defaultExecOpt T.empty data SomeVarValue = forall a. ExprType a => SomeVarValue a -- cgit v1.2.3