--- a/crates/jrsonnet-parser/src/lib.rs +++ b/crates/jrsonnet-parser/src/lib.rs @@ -30,11 +30,14 @@ grammar jsonnet_parser() for str { use peg::ParseLiteral; + rule eof() = quiet!{![_]} / expected!("") + rule eol() = "\n" / eof() + /// Standard C-like comments rule comment() - = "//" (!['\n'][_])* "\n" + = "//" (!eol()[_])* eol() / "/*" ("\\*/" / "\\\\" / (!("*/")[_]))* "*/" - / "#" (!['\n'][_])* "\n" + / "#" (!eol()[_])* eol() rule single_whitespace() = quiet!{([' ' | '\r' | '\n' | '\t'] / comment())} / expected!("") rule _() = single_whitespace()* @@ -562,6 +565,15 @@ } #[test] + fn missing_newline_between_comment_and_eof() { + parse!( + "{a:1} + + //+213" + ); + } + + #[test] fn default_param_before_nondefault() { parse!("local x(foo = 'foo', bar) = null; null"); }