From 060496fc6ee331e2710ff8ade23317a0a79cbd6c Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Wed, 6 Nov 2024 22:23:49 +0100 Subject: Parse local variables --- lib/Language/Elna/Frontend/Parser.hs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'lib/Language/Elna/Frontend/Parser.hs') diff --git a/lib/Language/Elna/Frontend/Parser.hs b/lib/Language/Elna/Frontend/Parser.hs index a8e61d2..98638f7 100644 --- a/lib/Language/Elna/Frontend/Parser.hs +++ b/lib/Language/Elna/Frontend/Parser.hs @@ -16,7 +16,7 @@ import Language.Elna.Frontend.AST , Statement(..) , TypeExpression(..) , VariableDeclaration(..) - --, VariableAccess(..) + , VariableAccess(..) , Condition(..) , Expression(..) , Literal(..) @@ -64,7 +64,7 @@ termP :: Parser Expression termP = choice [ parensP expressionP , LiteralExpression <$> literalP - -- , VariableExpression <$> variableAccessP + , VariableExpression <$> variableAccessP ] operatorTable :: [[Operator Parser Expression]] @@ -91,13 +91,13 @@ operatorTable = expressionP :: Parser Expression expressionP = makeExprParser termP operatorTable -{- + variableAccessP :: Parser VariableAccess -variableAccessP = do +variableAccessP = VariableAccess <$> identifierP {- do identifier <- identifierP indices <- many $ bracketsP expressionP - pure $ foldr (flip ArrayAccess) (VariableAccess identifier) indices --} + pure $ foldr (flip ArrayAccess) (VariableAccess identifier) indices -} + conditionP :: Parser Condition conditionP = do lhs <- expressionP @@ -187,8 +187,8 @@ statementP = EmptyStatement <$ semicolonP <|> ifElseP <|> CompoundStatement <$> blockP (many statementP) - {-<|> try assignmentP - <|> try whileP -} + <|> try assignmentP + -- <|> try whileP <|> callP "statement" where @@ -202,12 +202,12 @@ statementP <*> optional (symbol "else" *> statementP) {-whileP = WhileStatement <$> (symbol "while" *> parensP conditionP) - <*> statementP + <*> statementP -} assignmentP = AssignmentStatement <$> variableAccessP <* symbol ":=" <*> expressionP - <* semicolonP -} + <* semicolonP variableDeclarationP :: Parser VariableDeclaration variableDeclarationP = VariableDeclaration -- cgit v1.2.3