Пример #1
0
        public static string GetRouteTemplate(RazorSyntaxTree syntaxTree)
        {
            Block expression;
            Span  route;

            if (TryFindPageDirectiveBlocks(syntaxTree.Root, out expression, out route) &&
                route != null)
            {
                var trimmed = route.Content.Trim();
                return(trimmed.Substring(1, trimmed.Length - 2));
            }

            return(null);
        }
        public static void AddVirtualSyntaxTree(this RazorCodeDocument document, RazorSyntaxTree syntaxTree)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (syntaxTree == null)
            {
                throw new ArgumentNullException(nameof(syntaxTree));
            }

            GetVirtualSyntaxTrees(document).Add(syntaxTree);
        }
        public static void SetSyntaxTree(this RazorCodeDocument document, RazorSyntaxTree syntaxTree)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (syntaxTree == null)
            {
                throw new ArgumentNullException(nameof(syntaxTree));
            }

            document.Items[typeof(RazorSyntaxTree)] = syntaxTree;
        }
Пример #4
0
        public RazorChunkTree Execute(RazorCodeDocument document, RazorSyntaxTree syntaxTree)
        {
            var classInfo = document.GetClassName();

            var generator = new RazorChunkGenerator(classInfo.Class, classInfo.Namespace, document.Source.Filename, _host);

            syntaxTree.Root.Accept(generator);
            foreach (var error in syntaxTree.Diagnostics)
            {
                generator.VisitError(error);
            }
            generator.OnComplete();

            return(new DefaultRazorChunkTree(generator.Context.ChunkTreeBuilder.Root));
        }
Пример #5
0
        public RazorSyntaxTree Execute(RazorCodeDocument document, RazorSyntaxTree syntaxTree)
        {
            Block expression;
            Span  route;

            if (!TryFindPageDirectiveBlocks(syntaxTree.Root, out expression, out route))
            {
                return(syntaxTree);
            }

            var builder = new BlockBuilder(syntaxTree.Root);

            builder.Children.Remove(expression);
            builder.Children.Remove(route);

            return(RazorSyntaxTree.Create(builder.Build(), syntaxTree.Diagnostics));
        }
Пример #6
0
        public RazorSyntaxTree Execute(RazorCodeDocument document, RazorSyntaxTree syntaxTree)
        {
            var resolver = Engine.Features.OfType <TagHelperFeature>().FirstOrDefault()?.Resolver;

            if (resolver == null)
            {
                // No TagHelpers, so nothing to do.
                return(syntaxTree);
            }

            var visitor     = new TagHelperDirectiveSpanVisitor(resolver, document.ErrorSink);
            var descriptors = visitor.GetDescriptors(syntaxTree.Root);

            var rewriter = new TagHelperParseTreeRewriter(new TagHelperDescriptorProvider(descriptors));

            var context = new RewritingContext(syntaxTree.Root, document.ErrorSink);

            rewriter.Rewrite(context);
            return(RazorSyntaxTree.Create(context.SyntaxTree, context.ErrorSink.Errors));
        }
Пример #7
0
        public static RazorSyntaxTree Parse(RazorSourceDocument document)
        {
            if (document == null)
            {
                throw new ArgumentException(nameof(document));
            }

            var codeParser   = new PageCodeParser();
            var markupParser = new HtmlMarkupParser();

            var parser = new OldParser.RazorParser(codeParser, markupParser, new NullTagHelperDescriptorResolver());

            ParserResults result;

            using (var reader = document.CreateReader())
            {
                result = parser.Parse(reader);
            }

            return(RazorSyntaxTree.Create(result.Document, result.ParserErrors));
        }