Block comments
This commit is contained in:
parent
13353f8801
commit
c67adc3a38
@ -15,12 +15,14 @@ enum ExtendedPart<'a> {
|
||||
peg::parser! {
|
||||
pub grammar schala_parser() for str {
|
||||
|
||||
rule whitespace() = [' ' | '\t' ]*
|
||||
rule whitespace_or_newline() = [' ' | '\t' | '\n' ]*
|
||||
rule whitespace() = [' ' | '\t' ]
|
||||
rule whitespace_or_newline() = [' ' | '\t' | '\n' ]
|
||||
|
||||
rule _ = quiet!{ whitespace() }
|
||||
rule _ = quiet!{ (block_comment() / whitespace())* }
|
||||
|
||||
rule __ = quiet!{ whitespace_or_newline() }
|
||||
rule __ = quiet!{ (block_comment() / whitespace_or_newline())* }
|
||||
|
||||
rule block_comment() = "/*" (block_comment() / !"*/" [_])* "*/"
|
||||
|
||||
pub rule program() -> AST =
|
||||
__ statements:(statement() ** delimiter() ) __ { AST { id: Default::default(), statements: statements.into() } }
|
||||
@ -210,7 +212,7 @@ peg::parser! {
|
||||
|
||||
//TODO make the definition of operators more complex
|
||||
rule operator() -> &'input str =
|
||||
quiet!{$( ['+' | '-' | '*' | '/' | '%' | '<' | '>' | '=' | '!' | '$' | '&' | '|' | '?' | '^' | '`']+ )} /
|
||||
quiet!{!"*/" s:$( ['+' | '-' | '*' | '/' | '%' | '<' | '>' | '=' | '!' | '$' | '&' | '|' | '?' | '^' | '`']+ ) { s } } /
|
||||
expected!("operator")
|
||||
|
||||
rule extended_expr(struct_ok: bool) -> ExpressionKind =
|
||||
|
@ -1291,3 +1291,18 @@ fn blocks() {
|
||||
assert_eq!(block.unwrap(), vec![exst(Value(qn!(a)))].into());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn comments() {
|
||||
use ExpressionKind::*;
|
||||
|
||||
let source = "1 + /* hella /* bro */ */ 2";
|
||||
assert_expr2!(source, binop("+", expr(NatLiteral(1)), expr(NatLiteral(2))));
|
||||
|
||||
//TODO make sure this error message makes sense
|
||||
let source = "1 + /* hella /* bro */ 2";
|
||||
assert_fail_expr2!(source, "foo");
|
||||
|
||||
let source = "1 + /* hella */ bro */ 2";
|
||||
assert_fail_expr2!(source, binop("+", expr(NatLiteral(1)), expr(NatLiteral(2))));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user