tricu

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

commit 8a2dc2dfcf7228c8a612562ee8c4bc54bd41cd71
parent dbe9cbd6c132e61235ac7cf5348a8b6457b02d64
Author: James Eversole <james@eversole.co>
Date:   Sun, 29 Dec 2024 12:22:24 -0600

Additional tests

Diffstat:
MREADME.md | 2+-
Msrc/Lexer.hs | 2--
Msrc/Parser.hs | 8++++----
Mtest/Spec.hs | 12++++++++++++
4 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/README.md b/README.md @@ -19,7 +19,7 @@ tricu is the word for "tree" in Lojban: `(x1) is a tree of species/cultivar (x2) ## What does it look like? ``` --- Anything after `--` on a line is a comment +-- Anything after `--` on a single line is a comment -- We can define functions or "variables" as Tree Calculus values false = t _ = t diff --git a/src/Lexer.hs b/src/Lexer.hs @@ -79,10 +79,8 @@ comment :: Lexer LToken comment = do string "--" content <- many (satisfy (/= '\n')) - optional (char '\n') pure (LComment content) - sc :: Lexer () sc = skipMany (void (char ' ') <|> void (char '\t') <|> void comment) diff --git a/src/Parser.hs b/src/Parser.hs @@ -33,12 +33,9 @@ parseTricu input = parseSingle :: String -> TricuAST parseSingle input = case runParser parseExpression "" (lexTricu input) of - Left err -> error $ handleParseError err + Left err -> error $ handleParseError err Right ast -> ast -scnParser :: Parser () -scnParser = skipMany (satisfy isNewline) - parseExpression :: Parser TricuAST parseExpression = choice [ try parseFunction @@ -50,6 +47,9 @@ parseExpression = choice , parseLiteral ] +scnParser :: Parser () +scnParser = skipMany (satisfy isNewline) + parseFunction :: Parser TricuAST parseFunction = do LIdentifier name <- satisfy isIdentifier diff --git a/test/Spec.hs b/test/Spec.hs @@ -145,6 +145,18 @@ parserTests = testGroup "Parser Tests" let input = "x = (\\a : a)\nx (t)" expect = [SFunc "x" [] (SLambda ["a"] (SVar "a")),SApp (SVar "x") TLeaf] parseTricu input @?= expect + , testCase "Comments 1" $ do + let input = "(t) (t) -- (t)" + expect = [SApp TLeaf TLeaf] + parseTricu input @?= expect + , testCase "Comments 2" $ do + let input = "(t) -- (t) -- (t)" + expect = [TLeaf] + parseTricu input @?= expect +-- , testCase "Comments with no terms" $ do +-- let input = unlines ["-- (t)", "(t t)"] +-- expect = [] +-- parseTricu input @?= expect ] integrationTests :: TestTree