diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-01-31 22:26:15 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-01-31 22:26:28 +0100 |
commit | e4e11a9e23790b0662dadd20e346924782e30ae0 (patch) | |
tree | c48ab5975d4bf4f646261b1922c46ba803b1453a | |
parent | 7e36aa5ccb1575ca141b865dc7b8abe39a6c0581 (diff) |
Support parentheses in expressions
-rw-r--r-- | nl/parentest.nl | 4 | ||||
-rw-r--r-- | parser.hs | 9 |
2 files changed, 12 insertions, 1 deletions
diff --git a/nl/parentest.nl b/nl/parentest.nl new file mode 100644 index 0000000..3fe69e9 --- /dev/null +++ b/nl/parentest.nl @@ -0,0 +1,4 @@ +i32 main() { + 1 + (2 + 3); + return 0; +}
\ No newline at end of file @@ -102,7 +102,14 @@ pExpression :: Parser Expression pExpression = E.buildExpressionParser exprTable pExLit pExLit :: Parser Expression -pExLit = exLit_ <$> pLiteral +pExLit = (exLit_ <$> pLiteral) <|> pParenExpr + +pParenExpr :: Parser Expression +pParenExpr = do + symbol "(" + e <- pExpression + symbol ")" + return e pLiteral :: Parser Literal pLiteral = (LitInt <$> pInteger) <|> (LitInt <$> pCharStr) <|> (LitString <$> pString) |