Esempio n. 1
0
        private string ExtractId(LGFileParser.ImportDefinitionContext parseTree)
        {
            // content: [xxx](yyy)
            var content = parseTree.GetText();
            var lastOpenBracketIndex = content.LastIndexOf('(');

            return(content.Substring(lastOpenBracketIndex + 1, content.Length - lastOpenBracketIndex - 2));
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LGImport"/> class.
        /// </summary>
        /// <param name="parseTree">The parse tree of this template.</param>
        /// <param name="source">Source of this import.</param>
        public LGImport(LGFileParser.ImportDefinitionContext parseTree, string source = "")
        {
            ParseTree = parseTree;
            Source    = source;

            Description = ExtractDescription(parseTree);
            Id          = ExtractId(parseTree);
        }
Esempio n. 3
0
        private string ExtractDescription(LGFileParser.ImportDefinitionContext parseTree)
        {
            // content: [xxx](yyy)
            var content = parseTree.GetText();
            var closeSquareBracketIndex = content.IndexOf(']');

            return(content.Substring(1, closeSquareBracketIndex - 1));
        }
            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);
            }
Esempio n. 5
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);
            }
Esempio n. 6
0
 private string ExtractId(LGFileParser.ImportDefinitionContext parseTree) => parseTree.IMPORT_PATH()?.GetText()?.Trim('(').Trim(')');
Esempio n. 7
0
 private string ExtractDescription(LGFileParser.ImportDefinitionContext parseTree) => parseTree.IMPORT_DESC()?.GetText()?.Trim('[').Trim(']');
Esempio n. 8
0
 /// <summary>
 /// Enter a parse tree produced by <see cref="LGFileParser.importDefinition"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void EnterImportDefinition([NotNull] LGFileParser.ImportDefinitionContext context)
 {
 }
Esempio n. 9
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="LGFileParser.importDefinition"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitImportDefinition([NotNull] LGFileParser.ImportDefinitionContext context)
 {
     return(VisitChildren(context));
 }