Parse local variables
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user