aboutsummaryrefslogtreecommitdiff
path: root/src/Micro/Parser.hs
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-09-12 20:16:42 +0100
committerJuan J. Martinez <jjm@usebox.net>2022-09-12 20:16:42 +0100
commit8fe1fc0c2b0b10f64c43498481e738221fe03bb3 (patch)
tree3a934f555abfbee3881f171377f64dd2f31107d0 /src/Micro/Parser.hs
parentfea91d8e7e61693d8ece149bac91d7acda16453d (diff)
downloadmicro-lang-hs-8fe1fc0c2b0b10f64c43498481e738221fe03bb3.tar.gz
micro-lang-hs-8fe1fc0c2b0b10f64c43498481e738221fe03bb3.zip
Track local variables, WIP code gen
Diffstat (limited to 'src/Micro/Parser.hs')
-rw-r--r--src/Micro/Parser.hs26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/Micro/Parser.hs b/src/Micro/Parser.hs
index 89f5bc0..2ac6b13 100644
--- a/src/Micro/Parser.hs
+++ b/src/Micro/Parser.hs
@@ -106,7 +106,7 @@ fdef ident priv anon pos = do
do
x <- fStatement
pure $ [x]
- <|> grVar True
+ <|> grVar True True
return $ Func ident args rtyp (concat $ body) priv anon pos
function :: Bool -> Parser Expr
@@ -117,26 +117,26 @@ function priv = do
fdef ident priv False pos
-- ident: type = value
-varWithValue :: Bool -> Parser Expr
-varWithValue priv = do
+varWithValue :: Bool -> Bool -> Parser Expr
+varWithValue local priv = do
(ident, typ, _, pos) <- arg
reservedOp "=" <?> "assignation"
value <- expr
- return $ Var ident typ value priv pos
+ return $ Var ident typ value priv local pos
-- group variable declaration
-grVar :: Bool -> Parser [Expr]
-grVar priv = do
+grVar :: Bool -> Bool -> Parser [Expr]
+grVar local priv = do
reserved "var"
- xs <- parens $ commaSep $ varWithValue priv
+ xs <- parens $ commaSep $ varWithValue local priv
reservedOp ";"
return $ xs
-- variable declaration
-var :: Bool -> Parser Expr
-var priv = do
+var :: Bool -> Bool -> Parser Expr
+var local priv = do
reserved "var"
- x <- varWithValue priv
+ x <- varWithValue priv local
reservedOp ";"
return $ x
@@ -194,12 +194,12 @@ exprStmt = do
-- statements that appear in functions
fStatement :: Parser Expr
-fStatement = try exprStmt <|> var True <|> return'
+fStatement = try exprStmt <|> var True True <|> return'
-- top level statement
statement :: Parser Expr
statement =
- try exprStmt <|> try (privateDf var)
+ try exprStmt <|> try (privateDf (var False))
<|> return' -- this will raise an error
module' :: Parser Expr
@@ -217,7 +217,7 @@ program = do
do
x <- try (privateDf function) <|> statement
pure $ [x]
- <|> privateDfn grVar
+ <|> privateDfn (grVar False)
return $ [m] ++ (concat $ n)
parse :: Parser [Expr]