示例#1
0
        internal virtual RazorSyntaxTree ParseHtmlBlock(string document, IEnumerable <DirectiveDescriptor> directives, bool designTime = false)
        {
            directives = directives ?? Array.Empty <DirectiveDescriptor>();

            var source  = TestRazorSourceDocument.Create(document, fileName: null);
            var options = CreateParserOptions(directives, designTime);
            var context = new ParserContext(source, options);

            var parser = new HtmlMarkupParser(context);

            parser.CodeParser = new CSharpCodeParser(directives, context)
            {
                HtmlParser = parser,
            };

            parser.ParseBlock();

            var root        = context.Builder.Build();
            var diagnostics = context.ErrorSink.Errors?.Select(error => RazorDiagnostic.Create(error));

            return(RazorSyntaxTree.Create(root, source, diagnostics, options));
        }
示例#2
0
        internal virtual RazorSyntaxTree ParseHtmlBlock(RazorLanguageVersion version, string document, IEnumerable <DirectiveDescriptor> directives, bool designTime = false)
        {
            directives = directives ?? Array.Empty <DirectiveDescriptor>();

            var source = TestRazorSourceDocument.Create(document, filePath: null, relativePath: null, normalizeNewLines: true);

            var options = CreateParserOptions(version, directives, designTime);
            var context = new ParserContext(source, options);

            var codeParser   = new CSharpCodeParser(directives, context);
            var markupParser = new HtmlMarkupParser(context);

            codeParser.HtmlParser   = markupParser;
            markupParser.CodeParser = codeParser;

            var root = markupParser.ParseBlock().CreateRed();

            var diagnostics = context.ErrorSink.Errors;

            var syntaxTree = RazorSyntaxTree.Create(root, source, diagnostics, options);

            return(syntaxTree);
        }