Skip to content

Cpp, Go, JavaScript, Python2/3: Template rendering error. #2016

Closed

Description

@AndreiPashkin

Here is an example grammar:

grammar Test;

expression: op=NOT args+=expression
          | args+=expression (op=AND args+=expression)+
          | args+=expression (op=OR args+=expression)+
          | IDENTIFIER
          ;
AND : 'and' ;
OR : 'or' ;
NOT : 'not' ;
IDENTIFIER : [a-zA-Z_][a-zA-Z0-9_]* ;
WS : [ \t\r\n]+ -> skip ;

For Cpp, Go, JavaScript, Python2/3 target languages version 4.7 throws such errors while generating code:

error(32):  code generation template recRuleAltStartAction has missing, misnamed, or incomplete arg list; missing isListLabel

For the rest of the languages it works.

I believe that the error is in the templates since in the recRuleAltStartAction templates for the problematic languages argument isListLabel is not present while in the templates of the ok-languages it is present.

Activity

  1. ericvergnaud commented on Sep 19, 2017

    @ericvergnaud
    Contributor
  2. parrt commented on Sep 19, 2017

    @parrt
    Member

    With the Java target, all is ok:

    varmint:/tmp $ alias a4.7.1
    alias a4.7.1='java -cp "/Users/parrt/.m2/repository/org/antlr/antlr4/4.7.1-SNAPSHOT/antlr4-4.7.1-SNAPSHOT-complete.jar:$CLASSPATH" org.antlr.v4.Tool'
    varmint:/tmp $ a4.7.1 Test.g4
    varmint:/tmp $ 

    @ericvergnaud Looks like Swift, Java, C# are ok and have this argument. Probably should add to others.

    screen shot 2017-09-19 at 1 02 16 pm

    It appears to be needed:

    recRuleAltStartAction(ruleName, ctxName, label, isListLabel) ::= <<
    _localctx = new <ctxName>Context(_parentctx, _parentState);
    <if(label)>
    <if(isListLabel)>
    _localctx.<label>.add(_prevctx);
    <else>
    _localctx.<label> = _prevctx;
    <endif>
    <endif>
    <if(label)>_localctx.<label> = _prevctx;<endif>
    pushNewRecursionContext(_localctx, _startState, RULE_<ruleName>);
    >>
    
  3. ericvergnaud commented on Sep 19, 2017

    @ericvergnaud
    Contributor
  4. parrt commented on Sep 19, 2017

    @parrt
    Member
  5. parrt commented on Sep 21, 2017

    @parrt
    Member

    It's a bug in the Java target template.I believe that

    <if(label)>_localctx.<label> = _prevctx;<endif>
    

    was left in after creating the if statement right above it. I have created a unit test that should make everybody fail. I will see if I can figure out the other targets.

  6. added a commit that references this issue on Sep 21, 2017
  7. parrt commented on Sep 21, 2017

    @parrt
    Member

    See PR #2022 I think i have it all fixed but it uncovered a C++ target prediction issue.

  8. added this to the 4.7.1 milestone on Sep 21, 2017
  9. 12 remaining items

  10. added this to the 4.11 milestone on Aug 27, 2022
  11. added a commit that references this issue on Aug 27, 2022
  12. parrt commented on Aug 27, 2022

    @parrt
    Member

    Hoping to resolve with #3841

  13. added 2 commits that reference this issue on Aug 27, 2022
  14. parrt commented on Aug 28, 2022

    @parrt
    Member

    C++ and Go fail on this still but runtime now and not compilation.

  15. added a commit that references this issue on Aug 29, 2022
    51150ab
  16. parrt commented on Aug 29, 2022

    @parrt
    Member

    Fixed-ish by #3841

  17. KvanTTT commented on Aug 31, 2022

    @KvanTTT
    Member

    Please close since it's fixed.

  18. added a commit that references this issue on Sep 2, 2022
    5592e63
  19. added 3 commits that reference this issue on Sep 9, 2022
    e78a7f0
    e33c906
    cc5cc1a
  20. added a commit that references this issue on Dec 21, 2022
    2c75e64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions