aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Parser.hs
diff options
context:
space:
mode:
authorMarvin Borner2022-08-07 18:11:21 +0200
committerMarvin Borner2022-08-07 18:13:00 +0200
commita614ac0ed73ae6e12c0c15d057c93a5c96d1e08c (patch)
treeaaae1668cfaa4c51608e026a8eaf2c37452a48b9 /src/Parser.hs
parentd2a5d69f42d74e8382ca29c8c166eba3a79d20d5 (diff)
Things
lol
Diffstat (limited to 'src/Parser.hs')
-rw-r--r--src/Parser.hs53
1 files changed, 27 insertions, 26 deletions
diff --git a/src/Parser.hs b/src/Parser.hs
index 54a5a62..accda90 100644
--- a/src/Parser.hs
+++ b/src/Parser.hs
@@ -6,7 +6,6 @@ module Parser
import Control.Monad ( ap
, void
)
-import Data.Functor.Identity
import Data.Void
import Helper
import Text.Megaparsec hiding ( parseTest )
@@ -17,8 +16,8 @@ type Parser = Parsec Void String
-- exactly one space
-- TODO: replace many scs with sc
-sc :: Parser ()
-sc = void $ char ' '
+-- sc :: Parser ()
+-- sc = void $ char ' '
-- zero or more spaces
scs :: Parser ()
@@ -63,10 +62,10 @@ importPath = some $ oneOf "./_+-" <|> letterChar <|> digitChar
parseAbstraction :: Parser Expression
parseAbstraction = do
- symbol "[" <?> "opening abstraction"
- exp <- parseExpression
- symbol "]" <?> "closing abstraction"
- pure $ Abstraction exp
+ _ <- symbol "[" <?> "opening abstraction"
+ e <- parseExpression
+ _ <- symbol "]" <?> "closing abstraction"
+ pure $ Abstraction e
parseApplication :: Parser Expression
parseApplication = do
@@ -109,41 +108,43 @@ parseSingleton =
parseExpression :: Parser Expression
parseExpression = do
scs
- expr <- parseApplication <|> parseSingleton
+ e <- parseApplication <|> parseSingleton
scs
- pure expr <?> "expression"
+ pure e <?> "expression"
parseEvaluate :: Parser Instruction
parseEvaluate = Evaluate <$> parseExpression
parseDefine :: Int -> Parser Instruction
parseDefine lvl = do
+ inp <- getInput
var <- defIdentifier
scs
- exp <- parseExpression
+ e <- parseExpression
-- TODO: Fix >1 sub-defs
subs <-
(try $ newline *> (many (parseBlock (lvl + 1)))) <|> (try eof >> return [])
- pure $ Define var exp subs
+ pure $ Define var e subs inp
parseReplDefine :: Parser Instruction
parseReplDefine = do
+ inp <- getInput
var <- defIdentifier
scs
- symbol "="
+ _ <- symbol "="
scs
- exp <- parseExpression
- pure $ Define var exp []
+ e <- parseExpression
+ pure $ Define var e [] inp
parseComment :: Parser ()
parseComment = do
- string "# " <?> "comment"
- some $ noneOf "\r\n"
+ _ <- string "# " <?> "comment"
+ _ <- some $ noneOf "\r\n"
return ()
parseImport :: Parser Instruction
parseImport = do
- string ":import " <?> "import"
+ _ <- string ":import " <?> "import"
scs
path <- importPath
scs
@@ -153,25 +154,25 @@ parseImport = do
parsePrint :: Parser Instruction
parsePrint = do
- string ":print " <?> "print"
+ _ <- string ":print " <?> "print"
scs
- exp <- parseExpression
+ e <- parseExpression
scs
- pure $ Evaluate exp
+ pure $ Evaluate e
parseTest :: Parser Instruction
parseTest = do
- string ":test " <?> "test"
- exp1 <- parseExpression
+ _ <- string ":test " <?> "test"
+ e1 <- parseExpression
scs
- symbol "="
+ _ <- symbol "="
scs
- exp2 <- parseExpression
- pure $ Test exp1 exp2
+ e2 <- parseExpression
+ pure $ Test e1 e2
parseCommentBlock :: Parser Instruction
parseCommentBlock = do
- sepEndBy1 parseComment newline
+ _ <- sepEndBy1 parseComment newline
eof
return Comment