Allow block comments with /* */ (#421)

This commit is contained in:
Andrew Twyman 2025-09-11 12:17:32 -07:00 committed by GitHub
parent 03db60d94c
commit f95a27b412
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View file

@ -1,13 +1,15 @@
// Grammar for the "Podlang" language. Used for describing POD2 Custom // Grammar for the "Podlang" language. Used for describing POD2 Custom
// Predicates and Proof Requests. // Predicates and Proof Requests.
// Silent rules (`_`) are automatically handled by Pest between other rules. // Note: Silent rules (`_`) generate no tokens. WHITESPACE and COMMENT are
// special names known to Pest. If defined they are implicitly allowed between
// any others rules.
// WHITESPACE matches one or more spaces, tabs, or newlines. // WHITESPACE matches one or more spaces, tabs, or newlines.
WHITESPACE = _{ (" " | "\t" | NEWLINE)+ } WHITESPACE = _{ (" " | "\t" | NEWLINE)+ }
// COMMENT matches '//' followed by any characters until the end of the line. // COMMENT matches a line comment (//...\n) or block comment (/*...*/).
// Also silent. COMMENT = _{ ("//" ~ (!NEWLINE ~ ANY)* | "/*" ~ (!"*/" ~ ANY)* ~ "*/" ) }
COMMENT = _{ "//" ~ (!NEWLINE ~ ANY)* }
// Define rules for identifiers (predicate names, variable names without '?') // Define rules for identifiers (predicate names, variable names without '?')
// Must start with alpha or _, followed by alpha, numeric, or _ // Must start with alpha or _, followed by alpha, numeric, or _

View file

@ -54,12 +54,17 @@ mod tests {
assert_parses(Rule::document, " "); assert_parses(Rule::document, " ");
assert_parses(Rule::document, "\n\n"); assert_parses(Rule::document, "\n\n");
assert_parses(Rule::document, "// comment only"); assert_parses(Rule::document, "// comment only");
assert_parses(Rule::document, "/* comment only */");
} }
#[test] #[test]
fn test_parse_comment() { fn test_parse_comment() {
assert_parses(Rule::document, "// This is a comment\n"); assert_parses(Rule::document, "// This is a comment\n");
assert_parses(Rule::document, " // Indented comment"); assert_parses(Rule::document, " // Indented comment");
assert_parses(Rule::document, "/* This is a comment*/\n");
assert_fails(Rule::document, "/* Wrong closing characters/*\n");
assert_parses(Rule::literal_array, "[1// No nested comments /*\n, 2]");
assert_parses(Rule::literal_array, "[1/* No nested comments //*/, 2]\n");
} }
#[test] #[test]