internal virtual RazorSyntaxTree ParseDocument(RazorLanguageVersion version, string document, IEnumerable <DirectiveDescriptor> directives, bool designTime = false, RazorParserFeatureFlags featureFlags = null, string fileKind = null)
        {
            directives ??= Array.Empty <DirectiveDescriptor>();

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

            var options = CreateParserOptions(version, directives, designTime, featureFlags, fileKind);
            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.ParseDocument().CreateRed();

            var diagnostics = context.ErrorSink.Errors;

            var codeDocument = RazorCodeDocument.Create(source);

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

            codeDocument.SetSyntaxTree(syntaxTree);

            var defaultDirectivePass = new DefaultDirectiveSyntaxTreePass();

            syntaxTree = defaultDirectivePass.Execute(codeDocument, syntaxTree);

            return(syntaxTree);
        }
Exemple #2
0
        internal virtual RazorSyntaxTree ParseDocument(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 codeParser   = new CSharpCodeParser(directives, context);
            var markupParser = new HtmlMarkupParser(context);

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

            markupParser.ParseDocument();

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

            var codeDocument = RazorCodeDocument.Create(source);

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

            codeDocument.SetSyntaxTree(syntaxTree);

            var defaultDirectivePass = new DefaultDirectiveSyntaxTreePass();

            syntaxTree = defaultDirectivePass.Execute(codeDocument, syntaxTree);

            return(syntaxTree);
        }
Exemple #3
0
        public virtual RazorSyntaxTree Parse(RazorSourceDocument source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var context      = new ParserContext(source, Options);
            var codeParser   = new CSharpCodeParser(Options.Directives, context);
            var markupParser = new HtmlMarkupParser(context);

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

            var diagnostics = context.ErrorSink.Errors;

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

            return(RazorSyntaxTree.Create(root, source, diagnostics, Options));
        }
        public virtual RazorSyntaxTree Parse(RazorSourceDocument source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var context      = new ParserContext(source, Options);
            var codeParser   = new CSharpCodeParser(Options.Directives, context);
            var markupParser = new HtmlMarkupParser(context);

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

            markupParser.ParseDocument();

            var root = context.Builder.Build();

            // Temporary code while we're still using legacy diagnostics in the SyntaxTree.
            var diagnostics = context.ErrorSink.Errors.Select(error => RazorDiagnostic.Create(error));

            return(RazorSyntaxTree.Create(root, source, diagnostics, Options));
        }