aboutsummaryrefslogtreecommitdiff
path: root/src/Micro/Parser.hs
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-12-21 23:23:47 +0000
committerJuan J. Martinez <jjm@usebox.net>2022-12-21 23:23:47 +0000
commit426c987995c8bc11e1815bef36606eda7a6c0e0a (patch)
treeb916d0054d9bfcfd039917cb0d472a72d7c6768e /src/Micro/Parser.hs
parent87692f1c8c7a4dc48a7bd319a0a0e15070d8e852 (diff)
downloadmicro-lang-hs-426c987995c8bc11e1815bef36606eda7a6c0e0a.tar.gz
micro-lang-hs-426c987995c8bc11e1815bef36606eda7a6c0e0a.zip
Tidy up
Diffstat (limited to 'src/Micro/Parser.hs')
-rw-r--r--src/Micro/Parser.hs30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/Micro/Parser.hs b/src/Micro/Parser.hs
index 2ac6b13..48e1900 100644
--- a/src/Micro/Parser.hs
+++ b/src/Micro/Parser.hs
@@ -64,8 +64,7 @@ variable = do
typ :: Parser Type
typ = do
- p <- identifier
- return $ Type p
+ Type <$> identifier
typFn :: Parser Type
typFn = do
@@ -78,7 +77,8 @@ typFn = do
type' :: Parser Type
type' = do
try typFn
- <|> typ <?> "type"
+ <|> typ
+ <?> "type"
-- argument
arg :: Parser (String, Type, Bool, SourcePos)
@@ -87,7 +87,7 @@ arg = do
i <- identifier
_ <- colonSep <?> "\":\" before type"
t <- type' <?> "type"
- return $ (i, t, True, pos)
+ pure (i, t, True, pos)
-- function definition (common to def and lambda)
fdef :: Ident -> Bool -> Bool -> SourcePos -> Parser Expr
@@ -97,17 +97,16 @@ fdef ident priv anon pos = do
optionMaybe
( do
_ <- colonSep <?> "\":\" before type"
- rtyp <- type' <?> "return type"
- return $ rtyp
+ type' <?> "return type"
)
body <-
braces $
many $
do
x <- fStatement
- pure $ [x]
+ pure [x]
<|> grVar True True
- return $ Func ident args rtyp (concat $ body) priv anon pos
+ pure $ Func ident args rtyp (concat body) priv anon pos
function :: Bool -> Parser Expr
function priv = do
@@ -130,7 +129,7 @@ grVar local priv = do
reserved "var"
xs <- parens $ commaSep $ varWithValue local priv
reservedOp ";"
- return $ xs
+ pure xs
-- variable declaration
var :: Bool -> Bool -> Parser Expr
@@ -138,7 +137,7 @@ var local priv = do
reserved "var"
x <- varWithValue priv local
reservedOp ";"
- return $ x
+ pure x
-- private definition
privateDf :: (Bool -> Parser Expr) -> Parser Expr
@@ -190,7 +189,7 @@ exprStmt :: Parser Expr
exprStmt = do
e <- expr <|> factor
reservedOp ";"
- return $ e
+ pure e
-- statements that appear in functions
fStatement :: Parser Expr
@@ -199,7 +198,8 @@ fStatement = try exprStmt <|> var True True <|> return'
-- top level statement
statement :: Parser Expr
statement =
- try exprStmt <|> try (privateDf (var False))
+ try exprStmt
+ <|> try (privateDf (var False))
<|> return' -- this will raise an error
module' :: Parser Expr
@@ -216,9 +216,9 @@ program = do
many $
do
x <- try (privateDf function) <|> statement
- pure $ [x]
+ pure [x]
<|> privateDfn (grVar False)
- return $ [m] ++ (concat $ n)
+ return $ m : concat n
parse :: Parser [Expr]
parse = program
@@ -229,4 +229,4 @@ parseFromFile filename = do
return $ runParser (scan Micro.Parser.parse) () filename input
parseFromString :: String -> Either ParseError [Expr]
-parseFromString input = runParser (scan Micro.Parser.parse) () "-" input
+parseFromString = runParser (scan Micro.Parser.parse) () "-"