aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Parser.hs
diff options
context:
space:
mode:
authorMarvin Borner2022-08-10 18:53:34 +0200
committerMarvin Borner2022-08-10 18:53:34 +0200
commit792534b3888bc1b9c33047f1c312c4e17a720885 (patch)
treeb0401f5c1ca156858fb7de94a5488151be075c89 /src/Parser.hs
parentcba3d7d21241f8db913e6e2733a8edc3a522ee62 (diff)
Added syntactic sugar for strings & chars
Diffstat (limited to 'src/Parser.hs')
-rw-r--r--src/Parser.hs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Parser.hs b/src/Parser.hs
index 5d62ab0..1d889d3 100644
--- a/src/Parser.hs
+++ b/src/Parser.hs
@@ -73,6 +73,16 @@ parseNumeral = do
number :: Parser Integer
number = ap sign nat
+parseString :: Parser Expression
+parseString = do
+ str <- between (char '\"') (char '\"') (some $ satisfy (`notElem` "\"\\"))
+ pure (stringToExpression str) <?> "string"
+
+parseChar :: Parser Expression
+parseChar = do
+ ch <- between (char '\'') (char '\'') (satisfy (`notElem` "\"\\"))
+ pure (charToExpression ch) <?> "char"
+
parseVariable :: Parser Expression
parseVariable = do
var <- identifier
@@ -82,6 +92,8 @@ parseSingleton :: Parser Expression
parseSingleton =
parseBruijn
<|> parseNumeral
+ <|> parseString
+ <|> parseChar
<|> parseAbstraction
<|> (parens parseApplication <?> "enclosed application")
<|> parseVariable