summaryrefslogtreecommitdiff
path: root/lib/Language/Elna/Parser.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2024-09-24 22:20:57 +0200
committerEugen Wissner <belka@caraus.de>2024-09-24 22:20:57 +0200
commitb30bbcab2892f9c41d6b1057eb09804e2d9be4e6 (patch)
treebd6db707f8bef38be0ac967f170e0d822142422f /lib/Language/Elna/Parser.hs
parente66ccf46f445f04fbbeb1b0bfb273b806d22f65b (diff)
downloadelna-b30bbcab2892f9c41d6b1057eb09804e2d9be4e6.tar.gz
Parse call statements
Diffstat (limited to 'lib/Language/Elna/Parser.hs')
-rw-r--r--lib/Language/Elna/Parser.hs60
1 files changed, 30 insertions, 30 deletions
diff --git a/lib/Language/Elna/Parser.hs b/lib/Language/Elna/Parser.hs
index 57ebb1b..5583601 100644
--- a/lib/Language/Elna/Parser.hs
+++ b/lib/Language/Elna/Parser.hs
@@ -4,7 +4,7 @@ module Language.Elna.Parser
) where
import Control.Monad (void)
--- import Control.Monad.Combinators.Expr (Operator(..), makeExprParser)
+import Control.Monad.Combinators.Expr ({-Operator(..), -} makeExprParser)
import Data.Text (Text)
import qualified Data.Text as Text
import Data.Void (Void)
@@ -17,19 +17,19 @@ import Language.Elna.AST
, TypeExpression(..)
, VariableDeclaration(..)
{-, VariableAccess(..)
- , Condition(..)
+ , Condition(..)-}
, Expression(..)
- , Literal(..)-}
+ , Literal(..)
)
import Text.Megaparsec
( Parsec
, (<?>)
- --, MonadParsec(..)
+ , MonadParsec(..)
, eof
, optional
, between
, sepBy
- --, choice
+ , choice
)
import qualified Text.Megaparsec.Char.Lexer as Lexer
import Text.Megaparsec.Char
@@ -44,32 +44,32 @@ import Data.Maybe (isJust)
-- import Data.Functor (($>))
type Parser = Parsec Void Text
-{-
-typeDefinitionP :: Parser Declaration
-typeDefinitionP = TypeDefinition
- <$> (symbol "type" *> identifierP)
- <*> (symbol "=" *> typeExpressionP)
- <* semicolonP
- <?> "type definition"
literalP :: Parser Literal
literalP
- = HexadecimalLiteral <$> (string "0x" *> lexeme Lexer.hexadecimal)
- <|> IntegerLiteral <$> lexeme Lexer.decimal
- <|> CharacterLiteral <$> lexeme charP
+ = {- HexadecimalLiteral <$> (string "0x" *> lexeme Lexer.hexadecimal)
+ <|> -} IntegerLiteral <$> lexeme Lexer.decimal
+ {- <|> CharacterLiteral <$> lexeme charP
<|> BooleanLiteral <$> (symbol "true" $> True)
<|> BooleanLiteral <$> (symbol "false" $> False)
where
charP = fromIntegral . fromEnum
- <$> between (char '\'') (char '\'') Lexer.charLiteral
-
+ <$> between (char '\'') (char '\'') Lexer.charLiteral -}
+{-
+typeDefinitionP :: Parser Declaration
+typeDefinitionP = TypeDefinition
+ <$> (symbol "type" *> identifierP)
+ <*> (symbol "=" *> typeExpressionP)
+ <* semicolonP
+ <?> "type definition"
+-}
termP :: Parser Expression
termP = choice
[ parensP expressionP
, LiteralExpression <$> literalP
- , VariableExpression <$> variableAccessP
+ -- , VariableExpression <$> variableAccessP
]
-
+{-
variableAccessP :: Parser VariableAccess
variableAccessP = do
identifier <- identifierP
@@ -97,10 +97,10 @@ operatorTable =
]
prefix name f = Prefix (f <$ symbol name)
binary name f = InfixL (f <$ symbol name)
-
+-}
expressionP :: Parser Expression
-expressionP = makeExprParser termP operatorTable
-
+expressionP = makeExprParser termP [] -- operatorTable
+{-
conditionP :: Parser Condition
conditionP = do
lhs <- expressionP
@@ -185,21 +185,21 @@ statementP
{-<|> CompoundStatement <$> blockP (many statementP)
<|> try assignmentP
<|> try ifElseP
- <|> try whileP
- <|> try callP -}
+ <|> try whileP -}
+ <|> try callP
<?> "statement"
- {-where
- ifElseP = IfStatement
+ where
+ callP = CallStatement
+ <$> identifierP
+ <*> parensP (sepBy expressionP commaP)
+ <* semicolonP
+ {-ifElseP = IfStatement
<$> (symbol "if" *> parensP conditionP)
<*> statementP
<*> optional (symbol "else" *> statementP)
whileP = WhileStatement
<$> (symbol "while" *> parensP conditionP)
<*> statementP
- callP = CallStatement
- <$> identifierP
- <*> parensP (sepBy expressionP commaP)
- <* semicolonP
assignmentP = AssignmentStatement
<$> variableAccessP
<* symbol ":="