Drop parseVarWithoutAssignment

Additionally sorts gitignore and adds attempted decoding of lists back
to the REPL
This commit is contained in:
James Eversole 2025-01-03 10:31:35 -06:00
parent 8c33e5ce66
commit 3eb28a2c62
4 changed files with 12 additions and 17 deletions

14
.gitignore vendored
View File

@ -1,11 +1,11 @@
bin/
/result
/config.dhall
/Dockerfile
.stack-work/
*.swp
dist*
*.txt
*~
.env
.stack-work/
/Dockerfile
/config.dhall
/result
WD
*.hs.txt
bin/
dist*

View File

@ -54,16 +54,9 @@ parseFunction = do
parseAtomicBase :: Parser TricuAST
parseAtomicBase = choice
[ try parseVarWithoutAssignment
, parseTreeLeaf
[ parseTreeLeaf
, parseGrouped
]
parseVarWithoutAssignment :: Parser TricuAST
parseVarWithoutAssignment = do
LIdentifier name <- satisfy isIdentifier
if (name == "t" || name == "__result")
then fail $ "Reserved keyword: " ++ name ++ " cannot be assigned."
else notFollowedBy (satisfy (== LAssign)) *> return (SVar name)
parseLambda :: Parser TricuAST
parseLambda = between (satisfy (== LOpenParen)) (satisfy (== LCloseParen)) $ do

View File

@ -66,4 +66,6 @@ decodeResult tc = case toNumber tc of
Right num -> show num
Left _ -> case toString tc of
Right str -> "\"" ++ str ++ "\""
Left _ -> formatResult TreeCalculus tc
Left _ -> case toList tc of
Right list -> "[" ++ intercalate ", " (map decodeResult list) ++ "]"
Left _ -> formatResult TreeCalculus tc

View File

@ -53,7 +53,7 @@ lexerTests = testGroup "Lexer Tests"
expect = Right [LKeywordT, LStringLiteral "string", LIntegerLiteral 42]
runParser tricuLexer "" input @?= expect
, testCase "Lex invalid token" $ do
let input = "$invalid"
let input = "&invalid"
case runParser tricuLexer "" input of
Left _ -> return ()
Right _ -> assertFailure "Expected lexer to fail on invalid token"