diff --git a/README.md b/README.md index bb19e44..62ff109 100644 --- 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 index 9c69420..58b3a45 100644 --- 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 index b5b404b..f0e2ac0 100644 --- 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 index c182dd8..b8faef9 100644 --- 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