Parse local variables

This commit is contained in:
2024-11-06 22:23:49 +01:00
parent e2d4b76c0b
commit 060496fc6e
11 changed files with 115 additions and 91 deletions

View File

@@ -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