diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2025-04-16 21:44:20 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-04-18 22:25:18 +0200 |
commit | baa086bd025ce49a75d8cc9d64d24615ab960357 (patch) | |
tree | f1ce6d3a889a91a3efaa43c08e26171267f6dc38 /src/Parser/Expr.hs | |
parent | f0eed671c65a31eeb34ece14547bea79eb753728 (diff) |
Shell interpreter for test script
Changelog: Experimental shell interpreter
Diffstat (limited to 'src/Parser/Expr.hs')
-rw-r--r-- | src/Parser/Expr.hs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/Parser/Expr.hs b/src/Parser/Expr.hs index 5d60973..54f2757 100644 --- a/src/Parser/Expr.hs +++ b/src/Parser/Expr.hs @@ -11,6 +11,8 @@ module Parser.Expr ( literal, variable, + stringExpansion, + checkFunctionArguments, functionArguments, ) where @@ -94,8 +96,8 @@ someExpansion = do , between (char '{') (char '}') someExpr ] -stringExpansion :: ExprType a => Text -> (forall b. ExprType b => Expr b -> [Maybe (Expr a)]) -> TestParser (Expr a) -stringExpansion tname conv = do +expressionExpansion :: ExprType a => Text -> (forall b. ExprType b => Expr b -> [ Maybe (Expr a) ]) -> TestParser (Expr a) +expressionExpansion tname conv = do off <- stateOffset <$> getParserState SomeExpr e <- someExpansion let err = do @@ -105,6 +107,13 @@ stringExpansion tname conv = do maybe err return $ listToMaybe $ catMaybes $ conv e +stringExpansion :: TestParser (Expr Text) +stringExpansion = expressionExpansion (T.pack "string") $ \e -> + [ cast e + , fmap (T.pack . show @Integer) <$> cast e + , fmap (T.pack . show @Scientific) <$> cast e + ] + numberLiteral :: TestParser SomeExpr numberLiteral = label "number" $ lexeme $ do x <- L.scientific @@ -131,11 +140,7 @@ quotedString = label "string" $ lexeme $ do , char 't' >> return '\t' ] (Pure (T.singleton c) :) <$> inner - ,do e <- stringExpansion (T.pack "string") $ \e -> - [ cast e - , fmap (T.pack . show @Integer) <$> cast e - , fmap (T.pack . show @Scientific) <$> cast e - ] + ,do e <- stringExpansion (e:) <$> inner ] Concat <$> inner @@ -153,7 +158,7 @@ regex = label "regular expression" $ lexeme $ do , anySingle >>= \c -> return (Pure $ RegexPart $ T.pack ['\\', c]) ] (s:) <$> inner - ,do e <- stringExpansion (T.pack "regex") $ \e -> + ,do e <- expressionExpansion (T.pack "regex") $ \e -> [ cast e , fmap RegexString <$> cast e , fmap (RegexString . T.pack . show @Integer) <$> cast e |