aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Parser.hs
diff options
context:
space:
mode:
authorMarvin Borner2023-07-30 21:18:20 +0200
committerMarvin Borner2023-07-30 21:18:20 +0200
commitf24d3960976eeb9633889721f79c7b2f978d74b5 (patch)
tree81a891590381786d264b073e3ad2c8750e898994 /src/Parser.hs
parentceb1f3303253d16334ded220e45dd76338e28f66 (diff)
Added uniform function call syntax support (UFCS)
Also disallows dots in identifiers. Probably shouldn't be overused but allows things like `(+5).(replicate (+3)).sum` which is pretty fun tbh.
Diffstat (limited to 'src/Parser.hs')
-rw-r--r--src/Parser.hs25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/Parser.hs b/src/Parser.hs
index bad7ad3..12214a0 100644
--- a/src/Parser.hs
+++ b/src/Parser.hs
@@ -41,9 +41,10 @@ mathematicalArrow = satisfy isMathematicalOperator
where isMathematicalOperator c = '←' <= c && c <= '⇿'
-- "'" can't be in special chars because of 'c' char notation and prefixation
+-- "." can't be in special chars because of namespaced functions and UFCS syntax
specialChar :: Parser Char
specialChar =
- oneOf "!?*@.,:;+-_#$%^&<>/\\|{}~="
+ oneOf "!?*@,:;+-_#$%^&<>/\\|{}~="
<|> mathematicalOperator
<|> mathematicalArrow
@@ -183,14 +184,20 @@ parsePrefix = do
parseSingleton :: Parser Expression
parseSingleton =
- parseBruijn
- <|> try parseNumeral
- <|> parseString
- <|> parseChar
- <|> parseAbstraction
- <|> try parseFunction
- <|> parsePrefix
- <|> try (parens parseMixfix <?> "enclosed mixfix chain")
+ let parseSingletonExpression =
+ parseBruijn
+ <|> try parseNumeral
+ <|> parseString
+ <|> parseChar
+ <|> parseAbstraction
+ <|> try parseFunction
+ <|> parsePrefix
+ <|> try (parens parseMixfix <?> "enclosed mixfix chain")
+ parseUniformCall = do
+ g <- parseSingletonExpression
+ f <- some $ char '.' >> parseSingletonExpression
+ pure $ foldr1 Application (reverse (g : f))
+ in try parseUniformCall <|> parseSingletonExpression
parseExpression :: Parser Expression
parseExpression = do