-
We have defined a set of syntax for the formula, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
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--;
});
});
} |
Beta Was this translation helpful? Give feedback.
-
You may be able to add the depth information on the tree by overriding some methods in the treeBuilder trait, chevrotain/packages/chevrotain/src/parse/parser/traits/tree_builder.ts Lines 218 to 227 in 93c78cd |
Beta Was this translation helpful? Give feedback.
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: