Skip to content

Commit

Permalink
src/Parser: [add] parsing of evaluate options
Browse files Browse the repository at this point in the history
	- [add] parseDetailed, parseCallByValue
	- [update] parseEvaluate to parse options
	- [remove] parseEvaluateDetailed
  • Loading branch information
Sandro Lovnički committed Sep 7, 2019
1 parent 23ca9fb commit 1b3521f
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ languageDef =
, ":run"
, ":print"
, ":d"
, ":b"
, ":cbv"
]
, Token.reservedOpNames = [ "="
, "."
Expand Down Expand Up @@ -149,17 +149,26 @@ parseDefine = do
y <- parseExpression
return $ Define var y

-- Evaluate with options
parseDetailed :: Parser EvaluateOption
parseDetailed = do
reserved ":d"
return Detailed

parseCallByValue :: Parser EvaluateOption
parseCallByValue = do
reserved ":cbv"
return CallByValue

parseEvaluate :: Parser Command
parseEvaluate = do
ex <- parseExpression
return $ Evaluate ex

parseEvaluateDetailed :: Parser Command
parseEvaluateDetailed = do
reserved ":d"
det <- option None parseDetailed
spaces
cbv <- option None parseCallByValue
spaces
ex <- parseExpression
return $ EvaluateDetailed ex
exp <- parseExpression
return $ Evaluate det cbv exp
-----------------------------------

parseImport :: Parser Command
parseImport = do
Expand Down Expand Up @@ -209,7 +218,6 @@ parsePrint = do

parseLine :: Parser Command
parseLine = try parseDefine
<|> parseEvaluateDetailed
<|> parseImport
<|> parseExport
<|> parseReview
Expand Down

0 comments on commit 1b3521f

Please sign in to comment.