This commit is contained in:
Rachel Lambda Samuelsson 2024-06-10 18:22:04 +02:00
parent c986d42bf2
commit 9f8624d2c7

View File

@ -42,7 +42,6 @@ ns = between skipSpace skipSpace
opTable :: [[Operator Parser Syn]]
opTable =
[ [ prefix "!" Not
, prefix "fix" Fix
]
, [ binary "*" Mul
, binary "/" Div
@ -69,8 +68,8 @@ parseSyn ctx = ns (makeExprParser (parseInnerSyn ctx) opTable)
parseInnerSyn :: Ctx -> Parser Syn
parseInnerSyn ctx = do
l <- many (try (ns goL))
r <- many (try (ns goR))
l <- many (ns goL)
r <- many (ns goR)
let lr = l ++ r
guard (not (null lr))
pure (foldl1 App lr)
@ -85,13 +84,14 @@ parseInnerSyn ctx = do
goR = choice [ parseIf ctx
, parseLam ctx
, parseLet ctx
, parseFix ctx
]
parseId :: Parser String
parseId = unpack <$> P.takeWhile1P Nothing isLetter
parseIL :: Parser Syn
parseIL = IL <$> L.signed skipSpace (L.lexeme skipSpace L.decimal)
parseIL = IL <$> L.lexeme skipSpace L.decimal
parseUL :: Parser Syn
parseUL = chunk "unit" >> pure UL
@ -146,6 +146,14 @@ parseLam ctx = do
skipSpace
Lam <$> parseSyn (name : ctx)
parseFix :: Ctx -> Parser Syn
parseFix ctx = do
chunk "fix"
skipSpace
res <- parseSyn ctx
skipSpace
pure (Fix res)
parseIf :: Ctx -> Parser Syn
parseIf ctx = do
chunk "if"