Additional test cases and bug fixes for subtle issues

This commit is contained in:
James Eversole
2024-12-19 19:53:32 -06:00
parent 602048dc53
commit d13b2f52e7
2 changed files with 30 additions and 2 deletions

View File

@ -20,6 +20,7 @@ data SaplingAST
deriving (Show, Eq, Ord)
parseSapling :: String -> SaplingAST
parseSapling "" = error "Empty input provided to parseSapling"
parseSapling input = case runParser parseExpression "" (lexSapling input) of
Left err -> error "Failed to parse input"
Right ast -> ast
@ -122,8 +123,14 @@ parseListLiteral = do
satisfy (== LCloseBracket)
return (SList elements)
--parseListItem :: Parser SaplingAST
--parseListItem = parseGroupedItem <|> parseSingleItem
parseListItem :: Parser SaplingAST
parseListItem = parseGroupedItem <|> parseSingleItem
parseListItem = choice
[ parseGroupedItem -- Handle expressions inside parentheses
, parseListLiteral -- Allow nested lists
, parseSingleItem -- Handle single tokens like `t` or identifiers
]
parseGroupedItem :: Parser SaplingAST
parseGroupedItem = do