Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default all rule refs to have labels in _localctx with same name with option to turn off #8

Closed
parrt opened this issue Feb 11, 2012 · 2 comments

Comments

@parrt
Copy link
Member

parrt commented Feb 11, 2012

RuleContext object labels:

e : e '+' egets labels e1 and e2
a : e (',' e)*gets List e and NO e1, e2

Rules with multiple alternatives and non-unique elements, get no automatic labels. The reason is, you can get rules like this
a : ID+ | ID ;

have to label alt or element. even for e : expr '++' | expr '--' ;

-Xno-auto-ctx-labels option or something like that to turn off all of this overhead? better name?

Try to get labeled alt labels into alt context.

don't forget to sort out list vs regular labels. ID+ gets ID and ID_list but ID should be the list now.

@parrt
Copy link
Member Author

parrt commented Feb 12, 2012

Sam points out better to have getters to avoid fields. most of time fast enough. Add:

getA() -> single element, or list
getA(i) -> single at ith position

no need for -Xno-auto-ctx-labels

@parrt
Copy link
Member Author

parrt commented Feb 14, 2012

Ok, got Sam's idea in for getters. from

    statement
        : block
        |   ASSERT expression (':' expression)? ';'
        |   'if' parExpression statement ('else' statement)?
        |   'for' '(' forControl ')' statement
        |   'while' parExpression statement
        |   'do' statement 'while' parExpression ';'
        |   'try' block
            ( catches 'finally' block
            | catches
            | 'finally' block
            )
        |   'switch' parExpression '{' switchBlockStatementGroups '}'
        |   'synchronized' parExpression block
        |   'return' expression? ';'
        |   'throw' expression ';'
        |   'break' Identifier? ';'
        |   'continue' Identifier? ';'
        |   ';'
        |   statementExpression ';'
        |   Identifier ':' statement
        ;

we get:

public static class statementContext extends ParserRuleContext<Token> {
    public blockContext block(int i) {
        return (blockContext)getRuleContext(blockContext.class,i);
    }
    public List<expressionContext> expression() {
        return (List<expressionContext>)getRuleContexts(expressionContext.class);
    }
    public parExpressionContext parExpression() {
        return (parExpressionContext)getRuleContext(parExpressionContext.class,0);
    }
    public statementContext statement(int i) {
        return (statementContext)getRuleContext(statementContext.class,i);
    }
    public List<catchesContext> catches() {
        return (List<catchesContext>)getRuleContexts(catchesContext.class);
    }
    public expressionContext expression(int i) {
        return (expressionContext)getRuleContext(expressionContext.class,i);
    }
    public statementExpressionContext statementExpression() {
        return (statementExpressionContext)getRuleContext(statementExpressionContext.class,0);
    }
    public List<blockContext> block() {
        return (List<blockContext>)getRuleContexts(blockContext.class);
    }
    public List<statementContext> statement() {
        return (List<statementContext>)getRuleContexts(statementContext.class);
    }
    public switchBlockStatementGroupsContext switchBlockStatementGroups() {
        return (switchBlockStatementGroupsContext)getRuleContext(switchBlockStatementGroupsContext.class,0);
    }
    public Token ASSERT() { return getToken(JavaLRParser.ASSERT, 0); }
    public forControlContext forControl() {
        return (forControlContext)getRuleContext(forControlContext.class,0);
    }
    public Token Identifier() { return getToken(JavaLRParser.Identifier, 0); }
    public catchesContext catches(int i) {
        return (catchesContext)getRuleContext(catchesContext.class,i);
    }
    public statementContext(ParserRuleContext<Token> parent, int state) {
        super(parent, state);
    }
    @Override
    public void enterRule(ParseTreeListener<Token> listener) {
        if ( listener instanceof JavaLRListener ) ((JavaLRListener)listener).enter(this);
    }
    @Override
    public void exitRule(ParseTreeListener<Token> listener) {
        if ( listener instanceof JavaLRListener ) ((JavaLRListener)listener).exit(this);
    }
}

parrt added a commit that referenced this issue Feb 15, 2012
…05f2379

Removed redundant check for null
@antlr antlr closed this as completed in cdb420f Feb 15, 2012
parrt pushed a commit that referenced this issue Jun 30, 2015
Drops support of .Net versions < 3.5.
Official support by Microsoft is dropped since 2011, see
http://stackoverflow.com/questions/2713392/when-will-microsoft-end-mains
tream-support-for-existing-versions-of-the-net-fra
People in need of support of older versions should use Sam Harwell ’s
version
parrt pushed a commit that referenced this issue Jun 30, 2015
parrt pushed a commit that referenced this issue Jun 30, 2015
parrt pushed a commit that referenced this issue Nov 7, 2016
Additionally a warning was fixed (std::move prevents copy elision)
@ericvergnaud ericvergnaud mentioned this issue Nov 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant