Daniel Sun created GROOVY-12400:
-----------------------------------

             Summary: Add an inline Antlr4 parser covering-set with XML AST 
dumps
                 Key: GROOVY-12400
                 URL: https://issues.apache.org/jira/browse/GROOVY-12400
             Project: Groovy
          Issue Type: Improvement
            Reporter: Daniel Sun


The Antlr4 parser is covered mainly by resource files under 
{{src/test-resources/core}} and {{fail}}, driven from {{GroovyParserTest}} and 
{{SyntaxErrorTest}}.

h3. Problem

* Positive coverage is spread across many resource files, so a single grammar 
production is hard to find and to pin down.
* A successful {{CONVERSION}} is not the same as a correct AST: node type, 
operators, and source positions can still be wrong.
* Negative coverage often points at a file under {{fail/}} instead of locking 
the caret diagnostic next to the snippet.

h3. Approach

Add two JUnit 5 classes distilled from the groovy-parser (Parrot) lab corpus, 
with Groovy source inlined in each test method (the same shape as 
{{SyntaxErrorTest}}'s missing-delimiter cases).

* {{ParserPositiveSyntaxTest}} — valid snippets compiled through 
{{CONVERSION}}. Assert a pretty-printed XML dump of the module AST, with 
{{line}} / {{column}} / {{lastLine}} / {{lastColumn}} on every node 
({{AstXmlDumper}}).
* {{ParserNegativeSyntaxTest}} — invalid snippets. Assert the full caret 
diagnostic via {{expectParseError}}.
* Helpers on {{TestUtils}}: {{parseModule}}, {{expectAst}}, {{dumpAst}}, 
{{expectParseSuccess}}.

Classic Groovy snippets were cross-checked against groovy-parser's Antlr2 
parser. Constructs Antlr2 cannot parse (records, switch expressions, {{var}}, 
{{outer.new Inner()}}, and similar Parrot additions) lock the Antlr4 AST.

{{XStreamUtils.toXML}} is extracted as the in-memory form of 
{{groovy.ast=xml}}. The covering-set dump is a compact XML visitor instead: 
reflecting the whole {{ModuleNode}} graph is too noisy (and brittle on modern 
JDKs) for inline assertions.




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to