aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Parser.hs
diff options
context:
space:
mode:
authorMarvin Borner2022-08-13 19:46:25 +0200
committerMarvin Borner2022-08-13 19:46:25 +0200
commita3794ffdf8d59dce1cea7cd44f8d96142045dd36 (patch)
tree1c9deed21c219a2aec1936196b4fbf22c5ff4756 /src/Parser.hs
parentcf76a2e33b708dd2bec72a782af214cbd792bb58 (diff)
Bird combinators
Diffstat (limited to 'src/Parser.hs')
-rw-r--r--src/Parser.hs27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/Parser.hs b/src/Parser.hs
index 44bae87..82fe98b 100644
--- a/src/Parser.hs
+++ b/src/Parser.hs
@@ -18,15 +18,15 @@ sc :: Parser ()
sc = void $ char ' '
infixOperator :: Parser String
-infixOperator = some $ oneOf "!?*@:+-#$%^&<>/|~="
+infixOperator = some $ oneOf "!?*@.:+-#$%^&<>/|~="
prefixOperator :: Parser String
-prefixOperator = some $ oneOf "!?*@:+-#$%^&<>/|~="
+prefixOperator = some $ oneOf "!?*@.:+-#$%^&<>/|~="
-- def identifier disallows the import prefix dots
defIdentifier :: Parser String
defIdentifier =
- ((:) <$> (letterChar <|> char '_') <*> many (alphaNumChar <|> oneOf "?!'_-"))
+ ((:) <$> (letterChar <|> char '_') <*> many (alphaNumChar <|> oneOf "?!'_-*"))
<|> ((\l i r -> [l] ++ i ++ [r]) <$> char '(' <*> infixOperator <*> char ')'
)
<|> ((\p i -> p ++ [i]) <$> prefixOperator <*> char '(')
@@ -35,7 +35,8 @@ defIdentifier =
-- TODO: write as extension to defIdentifier
identifier :: Parser String
identifier =
- ((:) <$> (letterChar <|> char '_') <*> many (alphaNumChar <|> oneOf "?!'_-."))
+ ((:) <$> (letterChar <|> char '_') <*> many (alphaNumChar <|> oneOf "?!'_-*.")
+ )
<?> "identifier"
namespace :: Parser String
@@ -84,16 +85,20 @@ specialEscape =
parseString :: Parser Expression
parseString = do
- str <- between
- (char '\"')
- (char '\"')
- (some $ (char '\\' *> specialEscape) <|> (satisfy (`notElem` "\"\\")))
- pure (stringToExpression str) <?> "string"
+ str <-
+ between
+ (char '\"')
+ (char '\"')
+ (some $ (char '\\' *> specialEscape) <|> (satisfy (`notElem` "\"\\")))
+ <?> "quoted string"
+ pure $ stringToExpression str
parseChar :: Parser Expression
parseChar = do
- ch <- between (char '\'') (char '\'') (satisfy (`notElem` "\"\\"))
- pure (charToExpression ch) <?> "char"
+ ch <-
+ between (char '\'') (char '\'') (satisfy (`notElem` "\"\\"))
+ <?> "quoted char"
+ pure $ charToExpression ch
parseVariable :: Parser Expression
parseVariable = do