Block comments
This commit is contained in:
parent
13353f8801
commit
c67adc3a38
@ -15,12 +15,14 @@ enum ExtendedPart<'a> {
|
|||||||
peg::parser! {
|
peg::parser! {
|
||||||
pub grammar schala_parser() for str {
|
pub grammar schala_parser() for str {
|
||||||
|
|
||||||
rule whitespace() = [' ' | '\t' ]*
|
rule whitespace() = [' ' | '\t' ]
|
||||||
rule whitespace_or_newline() = [' ' | '\t' | '\n' ]*
|
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 =
|
pub rule program() -> AST =
|
||||||
__ statements:(statement() ** delimiter() ) __ { AST { id: Default::default(), statements: statements.into() } }
|
__ statements:(statement() ** delimiter() ) __ { AST { id: Default::default(), statements: statements.into() } }
|
||||||
@ -210,7 +212,7 @@ peg::parser! {
|
|||||||
|
|
||||||
//TODO make the definition of operators more complex
|
//TODO make the definition of operators more complex
|
||||||
rule operator() -> &'input str =
|
rule operator() -> &'input str =
|
||||||
quiet!{$( ['+' | '-' | '*' | '/' | '%' | '<' | '>' | '=' | '!' | '$' | '&' | '|' | '?' | '^' | '`']+ )} /
|
quiet!{!"*/" s:$( ['+' | '-' | '*' | '/' | '%' | '<' | '>' | '=' | '!' | '$' | '&' | '|' | '?' | '^' | '`']+ ) { s } } /
|
||||||
expected!("operator")
|
expected!("operator")
|
||||||
|
|
||||||
rule extended_expr(struct_ok: bool) -> ExpressionKind =
|
rule extended_expr(struct_ok: bool) -> ExpressionKind =
|
||||||
|
@ -1291,3 +1291,18 @@ fn blocks() {
|
|||||||
assert_eq!(block.unwrap(), vec![exst(Value(qn!(a)))].into());
|
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