Skip to content

how can i get the height of CST #1928

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

You must be logged in to vote

Hey @963334657,

I don't believe there's a builtin way of calculating the depth of the CST. What do you want to do in case the depth is too large? If you just throw an error it might make sense to just end parsing early in that case:

class Parser {
  depth = 0;
  SomeRule = this.Rule('rule', () => {
    this.ACTION(() => {
      if (++depth > threshold) throw new Error('too much recursion');
    });
    // ...
    this.ACTION(() => {
      depth--;
    });
  });
}

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@963334657
Comment options

Answer selected by 963334657
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