From f95a27b4129c24fac637e5e2b63c54ec3e0d8e34 Mon Sep 17 00:00:00 2001 From: Andrew Twyman Date: Thu, 11 Sep 2025 12:17:32 -0700 Subject: [PATCH] Allow block comments with /* */ (#421) --- src/lang/grammar.pest | 10 ++++++---- src/lang/parser.rs | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/lang/grammar.pest b/src/lang/grammar.pest index 1dbf6b4..adbd276 100644 --- a/src/lang/grammar.pest +++ b/src/lang/grammar.pest @@ -1,13 +1,15 @@ // Grammar for the "Podlang" language. Used for describing POD2 Custom // 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 = _{ (" " | "\t" | NEWLINE)+ } -// COMMENT matches '//' followed by any characters until the end of the line. -// Also silent. -COMMENT = _{ "//" ~ (!NEWLINE ~ ANY)* } +// COMMENT matches a line comment (//...\n) or block comment (/*...*/). +COMMENT = _{ ("//" ~ (!NEWLINE ~ ANY)* | "/*" ~ (!"*/" ~ ANY)* ~ "*/" ) } // Define rules for identifiers (predicate names, variable names without '?') // Must start with alpha or _, followed by alpha, numeric, or _ diff --git a/src/lang/parser.rs b/src/lang/parser.rs index 0fc4fd4..b16d658 100644 --- a/src/lang/parser.rs +++ b/src/lang/parser.rs @@ -54,12 +54,17 @@ mod tests { assert_parses(Rule::document, " "); assert_parses(Rule::document, "\n\n"); assert_parses(Rule::document, "// comment only"); + assert_parses(Rule::document, "/* comment only */"); } #[test] fn test_parse_comment() { assert_parses(Rule::document, "// This is a comment\n"); 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]