Daniel Sun created GROOVY-12322:
-----------------------------------

             Summary: Inline the nls parser rule
                 Key: GROOVY-12322
                 URL: https://issues.apache.org/jira/browse/GROOVY-12322
             Project: Groovy
          Issue Type: Improvement
            Reporter: Daniel Sun


h3. Motivation

{{GroovyParser.g4}} used a shared helper for optional newlines:

{noformat}
nls : NL* ;
sep : (NL | SEMI)+ ;
{noformat}

Because {{sep}} can start with {{NL}}, {{FOLLOW(nls)}} contains {{NL}}. The 
star inside {{nls}} is therefore not LL(1) at the rule level: generated 
{{nls()}} always uses adaptivePredict, even at call sites where a simple 
{{while (LA(1)==NL)}} would be correct. The rule also allocates a 
{{NlsContext}} for every invocation, including the empty match.

{{classOrInterfaceModifiersOpt}} already inlined {{NL*}} for this reason, with 
a comment not to put {{nls}} back.

Same class of prediction-cost reduction as GROOVY-12173, applied to newline 
handling.

h3. Changes

* Delete the {{nls}} rule and write {{NL*}} at every former call site, so each 
site has its own star decision.
* Teach {{GroovydocManager}} to read {{NL}} terminals as direct children 
(comments are lexed as {{NL}}). {{sep}} still wraps mixed {{NL}} / {{SEMI}} 
sequences.

h3. Compatibility

* Language and AST for correct programs are unchanged.
* Parse-tree shape changes: no {{NlsContext}}; empty matches produce no child. 
{{NlsContext}} is generated parser API, not a stability covenant.
* No public API additions.




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

Reply via email to