diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2023-02-20 19:50:36 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2023-02-20 19:50:36 +0100 |
commit | 82e4bdcaaefa88913a0dacf3496747251909219f (patch) | |
tree | b649928867f520681491b3488a17a8f52f681550 /src/Parser.hs | |
parent | f8c6706d5eefb8e4ebcdee7c963e8fe22fd9efab (diff) |
For statement
Diffstat (limited to 'src/Parser.hs')
-rw-r--r-- | src/Parser.hs | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/Parser.hs b/src/Parser.hs index 19a1cf0..9ba702b 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -387,13 +387,38 @@ letStatement = do off <- stateOffset <$> getParserState name <- varName osymbol "=" - SomeExpr (e :: Expr a) <- someExpr + SomeExpr e <- someExpr localState $ do - addVarName off $ TypedVarName @a name + let tname = TypedVarName name + addVarName off tname void $ eol body <- testBlock indent - return [Let line name e body] + return [Let line tname e body] + +forStatement :: TestParser [TestStep] +forStatement = do + line <- getSourceLine + ref <- L.indentLevel + wsymbol "for" + voff <- stateOffset <$> getParserState + name <- varName + + wsymbol "in" + loff <- stateOffset <$> getParserState + SomeExpr e <- someExpr + let err = parseError $ FancyError loff $ S.singleton $ ErrorFail $ T.unpack $ + "expected a list, expression has type '" <> textExprType e <> "'" + ExprListUnpacker unpack _ <- maybe err return $ exprListUnpacker e + + symbol ":" + scn + indent <- L.indentGuard scn GT ref + localState $ do + let tname = TypedVarName name + addVarName voff tname + body <- testBlock indent + return [For line tname (UnOp unpack e) body] class (Typeable a, Typeable (ParamRep a)) => ParamType a where type ParamRep a :: Type @@ -634,6 +659,7 @@ testBlock indent = concat <$> go testStep :: TestParser [TestStep] testStep = choice [ letStatement + , forStatement , testLocal , testWith , testNode |