tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

commit 66cc5fdd27a35d41185bfb8026fd30293907b5cf
parent 7d97b85f7456e60a4e99181c16dc6c12ad8e58b9
Author: James Eversole <james@eversole.co>
Date:   Fri,  3 Jan 2025 10:31:35 -0600

Drop parseVarWithoutAssignment

Additionally sorts gitignore and adds attempted decoding of lists back
to the REPL

Diffstat:
M.gitignore | 14+++++++-------
Msrc/Parser.hs | 9+--------
Msrc/REPL.hs | 4+++-
Mtest/Spec.hs | 2+-
4 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -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* diff --git a/src/Parser.hs b/src/Parser.hs @@ -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 diff --git a/src/REPL.hs b/src/REPL.hs @@ -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 diff --git a/test/Spec.hs b/test/Spec.hs @@ -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"