Skip to content

Typing for rules created in parser constructor #2040

Answered by msujew
khkiley asked this question in Q&A
Discussion options

You must be logged in to vote

Oh, I see that's what you mean. For TypeScript, you need to perform the assignments manually for the compiler to pick it up. Instead of performing the RULE calls inside of the constructor, you can also move them outside of it:

class SomeParser extends EmbeddedActionsParser {
  constructor() {
    super(tokens, {
      recoveryEnabled: true
    });
    this.performSelfAnalysis();
  }
  
  private numericExpression = this.RULE(...);
  private expression = this.RULE('expression', () => {
    ...
    this.SUBRULE(this.numericExpression);
  });
}

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@msujew
Comment options

Answer selected by khkiley
@bd82
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants