/// <summary> /// Синтаксическая ошиюка. /// </summary> /// <param name="recognizer">Распознаватель.</param> /// <param name="offendingSymbol">Предлагаемый токен.</param> /// <param name="line">Строка.</param> /// <param name="charPositionInLine">Колонка.</param> /// <param name="msg">Сообщение.</param> /// <param name="e">Исключение.</param> public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e) { // TODO: Разобраться с начальной и конечной позицией. var start = offendingSymbol.ToTextPosition(); // TODO: Добавить определение кода ошибки. report.AddError("", msg, document, start); }
public override void Apply(IReport report, IDocument document, IContext context) { var tree = document.GetSyntaxTree(); var walker = new ParseTreeWalker(); var listener = new UsingNonExistingLocalizationStringListener(context); walker.Walk(listener, tree); foreach (var entry in listener.Entries) { var description = string.Format(Resources.LocalizationStringNotFound, entry.LocalizationStringGroup, entry.LocalizationStringName); report.AddError(Code, description, document, entry.Context.GetTextPosition()); } }
public override void Apply(IReport report, IDocument document, IContext context) { var tree = document.GetSyntaxTree(); var walker = new ParseTreeWalker(); var listener = new IncorrectFunctionParamsCountListener(context); walker.Walk(listener, tree); foreach (var funcCall in listener.FunctionCalls) { var description = Resources.WrongFunctionArgumentsCount; report.AddError(Code, description, document, funcCall.identifier().GetTextPosition()); } }
/// <summary> /// Применить правило. /// </summary> /// <param name="report">Отчет.</param> /// <param name="document">Документ.</param> /// <param name="context">Контекст.</param> public override void Apply(IReport report, IDocument document, IContext context) { var tree = document.GetSyntaxTree(); var walker = new ParseTreeWalker(); var listener = new NotExistReferenceListener(context); walker.Walk(listener, tree); foreach (var entry in listener.UsingReferenceEntries) { report.AddError(Code, string.Format(Resources.UsingNotExistedReference, entry.ReferenceName), document, entry.Context.GetTextPosition()); } }
public override void Apply(IReport report, IDocument document, IContext context) { var tree = document.GetSyntaxTree(); var walker = new ParseTreeWalker(); var listener = new IncorrectFormatStringListener(context); walker.Walk(listener, tree); foreach (var entry in listener.FormatItemsWithoutArguments) { var description = string.Format(Resources.ArgumentForTemplateNotFound, entry.Data.Text, entry.Data.Index, entry.TemplateString); var position = entry.Context.GetTextPosition(); if (entry.TemplateStringSource == IncorrectFormatStringListener.TemplateStringSource.StringConstant) { // Подсвечиваем некорректный описатель прямо в строковой константе. var startIndex = position.StartIndex; position.StartIndex = startIndex + entry.Data.Pos.StartIndex; position.EndIndex = startIndex + entry.Data.Pos.EndIndex; position.Column = entry.Data.Pos.Line == 0 ? position.Column + entry.Data.Pos.Column : entry.Data.Pos.Column; position.Line += entry.Data.Pos.Line; } report.AddError(FormatItemNotFoundRuleCode, description, document, position); } foreach (var entry in listener.FormatItemsWithEmptyArguments) { var description = string.Format(Resources.EmptyFormatArgument, entry.Data.Text, entry.Data.Index, entry.TemplateString); var position = entry.Context.GetTextPosition(); if (entry.TemplateStringSource == IncorrectFormatStringListener.TemplateStringSource.StringConstant) { // Подсвечиваем некорректный описатель прямо в строковой константе. var startIndex = position.StartIndex; position.StartIndex = startIndex + entry.Data.Pos.StartIndex; position.EndIndex = startIndex + entry.Data.Pos.EndIndex; position.Column = entry.Data.Pos.Line == 0 ? position.Column + entry.Data.Pos.Column : entry.Data.Pos.Column; position.Line += entry.Data.Pos.Line; } report.AddWarning(EmptyArgumentForFormatItemRuleCode, description, document, position); } foreach (var incorrectFormatEntry in listener.ArgumentsWithoutFormatItems) { var description = string.Format(Resources.RedutantFormatArgument, incorrectFormatEntry.Data.Text, incorrectFormatEntry.Data.Index, incorrectFormatEntry.TemplateString); report.AddWarning(ArgumentForFormatItemNotFound, description, document, incorrectFormatEntry.Context.GetTextPosition()); } }
/// <summary> /// Применить правило. /// </summary> /// <param name="report">Отчет.</param> /// <param name="document">Документ.</param> /// <param name="context">Контекст.</param> public override void Apply(IReport report, IDocument document, IContext context) { var tree = document.GetSyntaxTree(); var walker = new ParseTreeWalker(); var listener = new NotAssignedVariablesListener(context, document); walker.Walk(listener, tree); foreach (var notAssignedVariable in listener.NotAssignedVariables) { report.AddError(Code, string.Format(Resources.UsingNotAssignedVariable, notAssignedVariable.GetText()), document, notAssignedVariable.Start.ToTextPosition()); } foreach (var uncertainVariable in listener.UncertainVariables) { report.AddWarning(Code, string.Format(Resources.VariableCanHasUncertainedValue, uncertainVariable.GetText()), document, uncertainVariable.Start.ToTextPosition()); } }