Merge pull request #146 from msftrncs/ImproveEndlessLoopDet

Improve endless loop detection
This commit is contained in:
Alexandru Dima 2021-01-29 14:33:23 +01:00 коммит произвёл GitHub
Родитель a891faa871 5146f83e79
Коммит 036dcad6a6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 183 добавлений и 1 удалений

Просмотреть файл

@ -1434,7 +1434,14 @@ export class StackElement implements StackElementDef {
}
public hasSameRuleAs(other: StackElement): boolean {
return this.ruleId === other.ruleId;
let el: StackElement | null = this;
while (el && el._enterPos === other._enterPos) {
if (el.ruleId === other.ruleId) {
return true;
}
el = el.parent;
}
return false;
}
}

Просмотреть файл

@ -0,0 +1,79 @@
{
"name": "infinite-loop-grammar",
"scopeName": "source.infinite-loop",
"patterns": [
{
"name": "start",
"begin": "\\A",
"end": "$",
"patterns": [
{
"name": "negative-look-ahead",
"match": "(?!a)"
}
]
},
{
"include": "#test"
},
{
"include": "#not_a_problem"
}
],
"repository": {
"test": {
"name": "test",
"begin": "(?=test)",
"end": "$",
"patterns": [
{
"include": "#test_this"
}
]
},
"test_this": {
"name": "test_this",
"begin": "(?=test this)",
"end": "$",
"patterns": [
{
"include": "#test_this_line"
}
]
},
"test_this_line": {
"name": "test_this_line",
"begin": "(?=test this line)",
"end": "$",
"patterns": [
{
"include": "#test"
}
]
},
"spaces":
{
"name": "spaces",
"begin": "^(?=\\s)",
"end": "(?=\\S)"
},
"not_a_problem":
{
"name": "not_a_problem",
"begin": "(?=not)",
"end": "\\z",
"patterns": [
{
"name": "not",
"match": "\\Gnot"
},
{
"include": "#not_a_problem"
},
{
"include": "#spaces"
}
]
}
}
}

Просмотреть файл

@ -1710,5 +1710,101 @@
]
}
]
},
{
"grammars": [
"fixtures/infinite-loop.json"
],
"grammarPath": "fixtures/infinite-loop.json",
"desc": "Issue #145",
"lines": [
{
"line": "abc",
"tokens": [
{
"value": "a",
"scopes": [
"source.infinite-loop",
"start"
]
},
{
"value": "bc",
"scopes": [
"source.infinite-loop"
]
}
]
},
{
"line": "test this line",
"tokens": [
{
"value": "test this line",
"scopes": [
"source.infinite-loop",
"test",
"test_this",
"test_this_line"
]
}
]
},
{
"line": "not",
"tokens": [
{
"value": "not",
"scopes": [
"source.infinite-loop",
"test",
"test_this",
"test_this_line"
]
}
]
},
{
"line": " not",
"tokens": [
{
"value": " ",
"scopes": [
"source.infinite-loop"
]
},
{
"value": "not",
"scopes": [
"source.infinite-loop",
"not_a_problem",
"not"
]
}
]
},
{
"line": " not",
"tokens": [
{
"value": " ",
"scopes": [
"source.infinite-loop",
"not_a_problem",
"spaces"
]
},
{
"value": "not",
"scopes": [
"source.infinite-loop",
"not_a_problem",
"not_a_problem",
"not"
]
}
]
}
]
}
]