aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Parser.hs
diff options
context:
space:
mode:
authorMarvin Borner2022-04-22 00:49:47 +0200
committerMarvin Borner2022-04-22 00:49:47 +0200
commit3b90d4f15ebad7dc15d78195397559bcca3bd8fb (patch)
treea2a77a0758fd5c5b6c6fc4d636a5e611101c9427 /src/Parser.hs
parentcf3258b2cf6a7022fcaa26ff071cb4d2a0c9bdec (diff)
Balanced ternary something
I don't even know anymore. What's happening? Quite confusing.
Diffstat (limited to 'src/Parser.hs')
-rw-r--r--src/Parser.hs26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/Parser.hs b/src/Parser.hs
index 1669bcd..6fbeca4 100644
--- a/src/Parser.hs
+++ b/src/Parser.hs
@@ -1,5 +1,9 @@
-module Parser where
+module Parser
+ ( parseLine
+ , parseReplLine
+ ) where
+import Control.Monad ( ap )
import Data.Functor.Identity
import Helper
import Text.Parsec
@@ -8,8 +12,8 @@ import qualified Text.Parsec.Token as Token
languageDef :: GenLanguageDef String u Identity
languageDef = emptyDef { Token.commentLine = "#"
- , Token.identStart = letter
- , Token.identLetter = alphaNum <|> char '?'
+ , Token.identStart = letter <|> char '_'
+ , Token.identLetter = alphaNum <|> oneOf "?!'_"
, Token.reservedOpNames = ["[", "]", "="]
}
@@ -49,6 +53,16 @@ parseBruijn = do
spaces
pure $ Bruijn $ (read . pure) idx
+parseNumeral :: Parser Expression
+parseNumeral = do
+ num <- number
+ spaces
+ pure $ decimalToTernary num
+ where
+ sign = (char '-' >> return negate) <|> (char '+' >> return id)
+ nat = read <$> many1 digit
+ number = ap sign nat
+
parseVariable :: Parser Expression
parseVariable = do
var <- identifier
@@ -57,7 +71,11 @@ parseVariable = do
parseSingleton :: Parser Expression
parseSingleton =
- parseBruijn <|> parseAbstraction <|> parens parseApplication <|> parseVariable
+ parseBruijn
+ <|> parseNumeral
+ <|> parseAbstraction
+ <|> parens parseApplication
+ <|> parseVariable
parseExpression :: Parser Expression
parseExpression = do