This commit is contained in:
Henning Dieterichs 2023-05-26 18:24:33 +02:00 committed by GitHub
parent f104f9bd62
commit b369129cf2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -60,7 +60,7 @@ class Parser {
this._itemsConstructed = 0;
this._itemsFromCache = 0;
let result = this.parseList(SmallImmutableSet.getEmpty());
let result = this.parseList(SmallImmutableSet.getEmpty(), 0);
if (!result) {
result = ListAstNode.getEmpty();
}
@ -70,6 +70,7 @@ class Parser {
private parseList(
openedBracketIds: SmallImmutableSet<OpeningBracketId>,
level: number,
): AstNode | null {
const items: AstNode[] = [];
@ -86,7 +87,7 @@ class Parser {
break;
}
child = this.parseChild(openedBracketIds);
child = this.parseChild(openedBracketIds, level + 1);
}
if (child.kind === AstNodeKind.List && child.childrenLength === 0) {
@ -129,6 +130,7 @@ class Parser {
private parseChild(
openedBracketIds: SmallImmutableSet<number>,
level: number,
): AstNode {
this._itemsConstructed++;
@ -142,8 +144,13 @@ class Parser {
return token.astNode as TextAstNode;
case TokenKind.OpeningBracket: {
if (level > 300) {
// To prevent stack overflows
return new TextAstNode(token.length);
}
const set = openedBracketIds.merge(token.bracketIds);
const child = this.parseList(set);
const child = this.parseList(set, level + 1);
const nextToken = this.tokenizer.peek();
if (