public override object VisitImportDefinition([NotNull] LGFileParser.ImportDefinitionContext context)
            {
                var importStr = context.IMPORT().GetText();

                var matchResult = ImportRegex.Match(importStr);

                if (matchResult.Success && matchResult.Groups.Count == 3)
                {
                    var description = matchResult.Groups[1].Value?.Trim();
                    var id          = matchResult.Groups[2].Value?.Trim();

                    var sourceRange = new SourceRange(context, this.templates.Id);
                    var import      = new TemplateImport(description, id, sourceRange);
                    this.templates.Imports.Add(import);
                }

                return(null);
            }
예제 #2
0
            /// <inheritdoc/>
            public override object VisitImportDefinition([NotNull] LGFileParser.ImportDefinitionContext context)
            {
                var importStr = context.IMPORT().GetText();

                var matchResult = ImportRegex.Match(importStr);

                if (!matchResult.Success || (matchResult.Groups.Count != 3 && matchResult.Groups.Count != 4))
                {
                    _templates.Diagnostics.Add(BuildTemplatesDiagnostic(TemplateErrors.ImportFormatError, context));
                    return(null);
                }

                var description = matchResult.Groups[1].Value?.Trim();
                var id          = matchResult.Groups[2].Value?.Trim();

                var sourceRange = new SourceRange(context, _templates.Source);
                var import      = new TemplateImport(description, id, sourceRange);

                if (matchResult.Groups.Count == 4)
                {
                    var asAlias = matchResult.Groups[3].Value?.Trim();
                    if (!string.IsNullOrWhiteSpace(asAlias))
                    {
                        var asAliasArray = Regex.Split(asAlias, @"\s+");
                        if (asAliasArray.Length != 2 || asAliasArray[0] != "as")
                        {
                            _templates.Diagnostics.Add(BuildTemplatesDiagnostic(TemplateErrors.ImportFormatError, context));
                            return(null);
                        }
                        else
                        {
                            import.Alias = asAliasArray[1].Trim();
                        }
                    }
                }

                _templates.Imports.Add(import);

                return(null);
            }