Beispiel #1
0
            public TemplateGroupRuleReturnScope(TemplateGroupWrapper group, CommonTree tree)
            {
                Contract.Requires <ArgumentNullException>(group != null, "group");
                Contract.Requires <ArgumentNullException>(tree != null, "tree");

                _group = group;
                _tree  = tree;
            }
Beispiel #2
0
            public TemplateGroupRuleReturnScope([NotNull] TemplateGroupWrapper group, [NotNull] CommonTree tree)
            {
                Requires.NotNull(group, nameof(group));
                Requires.NotNull(tree, nameof(tree));

                _group = group;
                _tree  = tree;
            }
Beispiel #3
0
        private TemplateGroupRuleReturnScope BuiltAstForGroupTemplates(TemplateGroupWrapper group)
        {
            ITreeAdaptor adaptor = new CommonTreeAdaptor();
            object       tree    = adaptor.Nil();

            foreach (var template in group.CompiledTemplates)
            {
                adaptor.AddChild(tree, template.Ast);
            }

            return(new TemplateGroupRuleReturnScope(group, (CommonTree)tree));
        }
Beispiel #4
0
        protected override void ReParseImpl()
        {
            var outputWindow = OutputWindowService.TryGetPane(PredefinedOutputWindowPanes.TvlIntellisense);

            try
            {
                Stopwatch stopwatch = Stopwatch.StartNew();

                var snapshot = TextBuffer.CurrentSnapshot;
                SnapshotCharStream         input  = new SnapshotCharStream(snapshot, new Span(0, snapshot.Length));
                GroupLexer                 lexer  = new GroupLexer(input);
                CommonTokenStream          tokens = new CommonTokenStream(lexer);
                GroupParserWrapper         parser = new GroupParserWrapper(tokens);
                List <ParseErrorEventArgs> errors = new List <ParseErrorEventArgs>();
                parser.ParseError += (sender, e) =>
                {
                    errors.Add(e);

                    string message = e.Message;

                    ITextDocument document;
                    if (TextBuffer.Properties.TryGetProperty(typeof(ITextDocument), out document) && document != null)
                    {
                        string fileName = document.FilePath;
                        var    line     = snapshot.GetLineFromPosition(e.Span.Start);
                        message = string.Format("{0}({1},{2}): {3}", fileName, line.LineNumber + 1, e.Span.Start - line.Start.Position + 1, message);
                    }

                    if (message.Length > 100)
                    {
                        message = message.Substring(0, 100) + " ...";
                    }

                    if (outputWindow != null)
                    {
                        outputWindow.WriteLine(message);
                    }

                    if (errors.Count > 100)
                    {
                        throw new OperationCanceledException();
                    }
                };

                TemplateGroupWrapper group = new TemplateGroupWrapper('<', '>');
                parser.group(group, "/");
                TemplateGroupRuleReturnScope returnScope = BuiltAstForGroupTemplates(group);

                // Also parse the input using the V4 lexer/parser for downstream operations that make use of it
                IList <Antlr4.Runtime.IToken>   v4tokens;
                TemplateParser.GroupFileContext v4result = ParseWithAntlr4(snapshot, out v4tokens);

                OnParseComplete(new StringTemplateParseResultEventArgs(snapshot, errors, stopwatch.Elapsed, tokens.GetTokens(), returnScope, v4tokens, v4result));
            }
            catch (Exception e) when(!ErrorHandler.IsCriticalException(e))
            {
                try
                {
                    if (outputWindow != null)
                    {
                        outputWindow.WriteLine(e.Message);
                    }
                }
                catch (Exception ex2) when(!ErrorHandler.IsCriticalException(ex2))
                {
                }
            }
        }