Skip to content

ActionTranslator - Reserved words escaping #4851

Open
@dudemaga

Description

@dudemaga

I’m not sure how applicable this is to targets other than Typescript.

If you use a label in a rule named as a reserved words, you get bad behaviour when using a token property reference.

Example:

Grammar.g4
rule: number=INT { (if $number.int==0) this.notifyErrorListeners("Error", $number, undefined);};

In the generated file you get:
if ((localctx._number != null ? Number(localctx._number.text) : 0)==0) this.notifyErrorListeners("Error", localctx._number_, undefined);

You can see that the TokenRef which uses escapedName is correct and uses _number_ but that the TokenPropertyRef which uses label is incorrect and uses _number

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions