Line comments

This commit is contained in:
Greg Shuflin 2021-11-13 13:18:02 -08:00
parent 671ce54dd3
commit 6cd5a9353c
2 changed files with 8 additions and 3 deletions

View File

@ -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) } /

View File

@ -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))]);
}