diff --git a/schala-lang/language/src/parsing/new.rs b/schala-lang/language/src/parsing/new.rs index b2ebf78..d5e119f 100644 --- a/schala-lang/language/src/parsing/new.rs +++ b/schala-lang/language/src/parsing/new.rs @@ -18,11 +18,13 @@ peg::parser! { rule whitespace() = [' ' | '\t' ] rule whitespace_or_newline() = [' ' | '\t' | '\n' ] - rule _ = quiet!{ (block_comment() / whitespace())* } + rule _ = quiet!{ (block_comment() / line_comment() / whitespace())* } - rule __ = quiet!{ (block_comment() / whitespace_or_newline())* } + rule __ = quiet!{ (block_comment() / line_comment() / whitespace_or_newline())* } rule block_comment() = "/*" (block_comment() / !"*/" [_])* "*/" + rule line_comment() = "//" (!['\n'] [_])* &"\n" + pub rule program() -> AST = __ statements:(statement() ** delimiter() ) __ { AST { id: Default::default(), statements: statements.into() } } @@ -38,7 +40,7 @@ peg::parser! { stmt:statement() delimiter()+ { stmt } rule statement() -> Statement = - pos:position!() kind:statement_kind() { Statement { id: Default::default(), location: pos.into(), kind } } + _ pos:position!() kind:statement_kind() _ { Statement { id: Default::default(), location: pos.into(), kind } } rule statement_kind() -> StatementKind = __ import:import() { StatementKind::Import(import) } / diff --git a/schala-lang/language/src/parsing/test.rs b/schala-lang/language/src/parsing/test.rs index 8cdb9e9..fab7538 100644 --- a/schala-lang/language/src/parsing/test.rs +++ b/schala-lang/language/src/parsing/test.rs @@ -1305,4 +1305,7 @@ fn comments() { let source = "1 + /* hella */ bro */ 2"; assert_fail_expr!(source, binop("+", expr(NatLiteral(1)), expr(NatLiteral(2)))); + + let source = "5//no man\n"; + assert_ast!(source, vec![exst(NatLiteral(5))]); }