Пример #1
0
            private void CheckTemplateString(string templateString, ParserRuleContext stringSourceContext,
                                             TemplateStringSource templateStringSource, IsblParser.ParameterListContext paramsOfArrayFunction)
            {
                var templateParser = new TemplateStringParser(templateString);
                var paramsParser   = new ParameterListParser(paramsOfArrayFunction);

                templateParser.Parse();
                paramsParser.Parse();
                foreach (var formatItem in templateParser.FormatItems)
                {
                    var foundArg = paramsParser.ParameterValues.FirstOrDefault(a => a.Index == formatItem.Index);
                    if (foundArg == null)
                    {
                        this.FormatItemsWithoutArguments.Add(new IncorrectFormatEntry <FormatItem>
                        {
                            TemplateString       = templateString,
                            Data                 = formatItem,
                            Context              = stringSourceContext,
                            TemplateStringSource = templateStringSource
                        });
                    }
                    else if (foundArg.IsEmpty)
                    {
                        this.FormatItemsWithEmptyArguments.Add(new IncorrectFormatEntry <FormatItem>
                        {
                            TemplateString       = templateString,
                            Data                 = formatItem,
                            Context              = stringSourceContext,
                            TemplateStringSource = templateStringSource
                        });
                    }
                }
                foreach (var parameter in paramsParser.ParameterValues.Where(p => !p.IsEmpty))
                {
                    if (!templateParser.FormatItems.Any(f => f.Index == parameter.Index))
                    {
                        this.ArgumentsWithoutFormatItems.Add(new IncorrectFormatEntry <ParameterValue>
                        {
                            TemplateString       = templateString,
                            Data                 = parameter,
                            Context              = parameter.Context,
                            TemplateStringSource = templateStringSource
                        });
                    }
                }
            }
            public override void EnterFunction([NotNull] IsblParser.FunctionContext context)
            {
                var functionName = context.identifier().GetText();

                if (RuleExceptions.Contains(functionName, StringComparer.OrdinalIgnoreCase))
                {
                    return;
                }
                if (!this.developerFunctions.TryGetValue(functionName, out Function function) &&
                    !this.systemFunctions.TryGetValue(functionName, out function))
                {
                    return;
                }
                var paramsParser = new ParameterListParser(context.parameterList());

                paramsParser.Parse();
                if (paramsParser.ParameterValues.Count > function.Arguments.Count)
                {
                    this.FunctionCalls.Add(context);
                    return;
                }
                // TODO: Сейчас билдер не считает ошибкой, если упустить обязательный параметр функции.
                // За исключением некоторых системных функций. Раскомментировать, когда (и если) поправят билдер.

                //int argIndex = 0;
                //foreach (var arg in function.Arguments
                //  .Where(a => !a.HasDefaultValue)
                //  .OrderBy(a => a.Number))
                //{
                //  if (!paramsParser.ParameterValues.Any(p => p.Index == argIndex && !p.IsEmpty))
                //  {
                //    this.FunctionCalls.Add(context);
                //    return;
                //  }
                //  argIndex++;
                //}
            }