Skip to content

Commit

Permalink
Исправлен выброс исключения диагностики DoubleNegatives при наборе ко…
Browse files Browse the repository at this point in the history
…да/ошибках разбора кода
  • Loading branch information
nixel2007 committed Feb 9, 2025
1 parent fc5bd74 commit 165184b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ public ParseTree visitExpression(BSLParser.ExpressionContext ctx) {
}

var operation = operands.peek();
assert operation != null; // для спокойствия сонара
// В случае ошибок парсинга выражения, operation может быть null
if (operation == null) {
recursionLevel--;
return ctx;
}

if (operation.getRepresentingAst() == null) {
operation.setRepresentingAst(ctx);
Expand All @@ -127,13 +131,24 @@ public ParseTree visitExpression(BSLParser.ExpressionContext ctx) {
@Override
public ParseTree visitMember(BSLParser.MemberContext ctx) {

// В случае ошибки парсинга member может быть пустой.
if (ctx.getChildCount() == 0) {
return ctx;
}

// нужен ручной dispatch на конкретного child,
// т.к. нет отдельного правила для подвыражения в скобках
// constValue
// | complexIdentifier
// | (( LPAREN expression RPAREN ) modifier*) // нечего оверрайдить !
// | (WAIT_KEYWORD (IDENTIFIER | globalMethodCall))

// constValue
// | complexIdentifier
// | (( LPAREN expression RPAREN ) modifier*) // нечего оверрайдить !
// | (IDENTIFIER | globalMethodCall)
// | waitExpression

var unaryModifier = ctx.unaryModifier();
var childIndex = 0;
if (unaryModifier != null) {
Expand Down
28 changes: 28 additions & 0 deletions src/test/resources/diagnostics/DoubleNegativesDiagnostic.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,31 @@
// NoSuchElementException
Запись = РегистрыСведений.ЗаданияКПересчетуСтатуса.СоздатьМенеджерЗаписи();
Запись.Записать(Истина);

// C ошибкой разбора
// Вынесено в отдельную процедуру в блоке subAfterCodeBlock, т.к. иначе парсер ломается целиком и expression tree builder
// ничего не строит
Процедура Тест()

Если Истина Тогда

// C ошибкой разбора
Если Тогда

КонецЕсли;

// С ошибкой разбора
Пока А Цикл
Если
#Если Сервер Тогда
F
#Иначе
G
#КонецЕсли
Тогда
КонецЕсли;
КонецЦикла;

КонецЕсли;

КонецПроцедуры

0 comments on commit 165184b

Please sign in to comment.