Line comments
This commit is contained in:
parent
671ce54dd3
commit
6cd5a9353c
@ -18,11 +18,13 @@ peg::parser! {
|
|||||||
rule whitespace() = [' ' | '\t' ]
|
rule whitespace() = [' ' | '\t' ]
|
||||||
rule whitespace_or_newline() = [' ' | '\t' | '\n' ]
|
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 block_comment() = "/*" (block_comment() / !"*/" [_])* "*/"
|
||||||
|
rule line_comment() = "//" (!['\n'] [_])* &"\n"
|
||||||
|
|
||||||
|
|
||||||
pub rule program() -> AST =
|
pub rule program() -> AST =
|
||||||
__ statements:(statement() ** delimiter() ) __ { AST { id: Default::default(), statements: statements.into() } }
|
__ statements:(statement() ** delimiter() ) __ { AST { id: Default::default(), statements: statements.into() } }
|
||||||
@ -38,7 +40,7 @@ peg::parser! {
|
|||||||
stmt:statement() delimiter()+ { stmt }
|
stmt:statement() delimiter()+ { stmt }
|
||||||
|
|
||||||
rule statement() -> Statement =
|
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 =
|
rule statement_kind() -> StatementKind =
|
||||||
__ import:import() { StatementKind::Import(import) } /
|
__ import:import() { StatementKind::Import(import) } /
|
||||||
|
@ -1305,4 +1305,7 @@ fn comments() {
|
|||||||
|
|
||||||
let source = "1 + /* hella */ bro */ 2";
|
let source = "1 + /* hella */ bro */ 2";
|
||||||
assert_fail_expr!(source, binop("+", expr(NatLiteral(1)), expr(NatLiteral(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))]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user