Ejemplo n.º 1
0
 public override ParserContext CreateParserContext(
     ITextDocument input,
     ParserBase codeParser,
     ParserBase markupParser,
     ErrorSink errorSink)
 {
     return base.CreateParserContext(input, codeParser, markupParser, errorSink);
 }
Ejemplo n.º 2
0
 private RazorParser(ParserBase codeParser,
                     ParserBase markupParser,
                     ITagHelperDescriptorResolver tagHelperDescriptorResolver,
                     IEnumerable<ISyntaxTreeRewriter> optimizers)
 {
     CodeParser = codeParser;
     MarkupParser = markupParser;
     TagHelperDescriptorResolver = tagHelperDescriptorResolver;
     Optimizers = optimizers.ToList();
 }
Ejemplo n.º 3
0
 private RazorParser(ParserBase codeParser,
                     ParserBase markupParser,
                     ITagHelperDescriptorResolver tagHelperDescriptorResolver,
                     IEnumerable <ISyntaxTreeRewriter> optimizers)
 {
     CodeParser   = codeParser;
     MarkupParser = markupParser;
     TagHelperDescriptorResolver = tagHelperDescriptorResolver;
     Optimizers = optimizers.ToList();
 }
Ejemplo n.º 4
0
 public virtual ParserContext CreateParserContext(ITextDocument input,
                                                  ParserBase codeParser,
                                                  ParserBase markupParser,
                                                  ErrorSink errorSink)
 {
     return new ParserContext(input,
                              codeParser,
                              markupParser,
                              SelectActiveParser(codeParser, markupParser),
                              errorSink);
 }
Ejemplo n.º 5
0
        // Internal for testing
        internal static IEnumerable <ISyntaxTreeRewriter> GetDefaultRewriters(ParserBase markupParser)
        {
            return(new ISyntaxTreeRewriter[]
            {
                // TODO: Modify the below WhiteSpaceRewriter & ConditionalAttributeCollapser to handle
                // TagHelperBlock's: https://github.com/aspnet/Razor/issues/117

                // Move whitespace from start of expression block to markup
                new WhiteSpaceRewriter(markupParser.BuildSpan),
                // Collapse conditional attributes where the entire value is literal
                new ConditionalAttributeCollapser(markupParser.BuildSpan),
            });
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of <see cref="RazorParser"/>.
        /// </summary>
        /// <param name="codeParser">The <see cref="ParserBase"/> used for parsing code content.</param>
        /// <param name="markupParser">The <see cref="ParserBase"/> used for parsing markup content.</param>
        /// <param name="tagHelperDescriptorResolver">The <see cref="ITagHelperDescriptorResolver"/> used to resolve
        /// <see cref="TagHelperDescriptor"/>s.</param>
        public RazorParser(ParserBase codeParser,
                           ParserBase markupParser,
                           ITagHelperDescriptorResolver tagHelperDescriptorResolver)
            : this(codeParser,
                  markupParser,
                  tagHelperDescriptorResolver,
                  GetDefaultRewriters(markupParser))
        {
            if (codeParser == null)
            {
                throw new ArgumentNullException(nameof(codeParser));
            }

            if (markupParser == null)
            {
                throw new ArgumentNullException(nameof(markupParser));
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of <see cref="RazorParser"/>.
        /// </summary>
        /// <param name="codeParser">The <see cref="ParserBase"/> used for parsing code content.</param>
        /// <param name="markupParser">The <see cref="ParserBase"/> used for parsing markup content.</param>
        /// <param name="tagHelperDescriptorResolver">The <see cref="ITagHelperDescriptorResolver"/> used to resolve
        /// <see cref="TagHelperDescriptor"/>s.</param>
        public RazorParser(ParserBase codeParser,
                           ParserBase markupParser,
                           ITagHelperDescriptorResolver tagHelperDescriptorResolver)
            : this(codeParser,
                   markupParser,
                   tagHelperDescriptorResolver,
                   GetDefaultRewriters(markupParser))
        {
            if (codeParser == null)
            {
                throw new ArgumentNullException(nameof(codeParser));
            }

            if (markupParser == null)
            {
                throw new ArgumentNullException(nameof(markupParser));
            }
        }
Ejemplo n.º 8
0
        public ParserContext(ITextDocument source,
                             ParserBase codeParser,
                             ParserBase markupParser,
                             ParserBase activeParser,
                             ErrorSink errorSink)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

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

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

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

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

            if (activeParser != codeParser && activeParser != markupParser)
            {
                throw new ArgumentException(RazorResources.ActiveParser_Must_Be_Code_Or_Markup_Parser, nameof(activeParser));
            }

            CaptureOwnerTask();

            Source       = new TextDocumentReader(source);
            CodeParser   = codeParser;
            MarkupParser = markupParser;
            ActiveParser = activeParser;
            _errorSink   = errorSink;
        }
Ejemplo n.º 9
0
        public ParserContext(ITextDocument source,
                             ParserBase codeParser,
                             ParserBase markupParser,
                             ParserBase activeParser,
                             ErrorSink errorSink)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

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

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

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

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

            if (activeParser != codeParser && activeParser != markupParser)
            {
                throw new ArgumentException(RazorResources.ActiveParser_Must_Be_Code_Or_Markup_Parser, nameof(activeParser));
            }

            CaptureOwnerTask();

            Source = new TextDocumentReader(source);
            CodeParser = codeParser;
            MarkupParser = markupParser;
            ActiveParser = activeParser;
            _errorSink = errorSink;
        }
Ejemplo n.º 10
0
 protected abstract ParserBase SelectActiveParser(ParserBase codeParser, ParserBase markupParser);
Ejemplo n.º 11
0
 protected override ParserBase SelectActiveParser(ParserBase codeParser, ParserBase markupParser)
 {
     return codeParser;
 }
Ejemplo n.º 12
0
        private ParserContext SetupTestContext(string document,
            Action<TextReader> positioningAction,
            ParserBase codeParser,
            ParserBase markupParser,
            ParserBase activeParser)
        {
            var context = new ParserContext(
                new SeekableTextReader(new StringReader(document)),
                codeParser,
                markupParser,
                activeParser,
                new ErrorSink());

            positioningAction(context.Source);
            return context;
        }
Ejemplo n.º 13
0
        // Internal for testing
        internal static IEnumerable<ISyntaxTreeRewriter> GetDefaultRewriters(ParserBase markupParser)
        {
            return new ISyntaxTreeRewriter[]
            {
                // TODO: Modify the below WhiteSpaceRewriter & ConditionalAttributeCollapser to handle
                // TagHelperBlock's: https://github.com/aspnet/Razor/issues/117

                // Move whitespace from start of expression block to markup
                new WhiteSpaceRewriter(markupParser.BuildSpan),
                // Collapse conditional attributes where the entire value is literal
                new ConditionalAttributeCollapser(markupParser.BuildSpan),
            };
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Gets an instance of the markup parser and is provided an opportunity to decorate or replace it
        /// </summary>
        /// <param name="incomingMarkupParser">The markup parser</param>
        /// <returns>Either the same markup parser, after modifications, or a different markup parser</returns>
        public virtual ParserBase DecorateMarkupParser(ParserBase incomingMarkupParser)
        {
            if (incomingMarkupParser == null)
            {
                throw new ArgumentNullException(nameof(incomingMarkupParser));
            }

            return incomingMarkupParser;
        }
Ejemplo n.º 15
0
        /// <inheritdoc />
        public override ParserBase DecorateCodeParser(ParserBase incomingCodeParser)
        {
            if (incomingCodeParser == null)
            {
                throw new ArgumentNullException(nameof(incomingCodeParser));
            }

            return new MvcRazorCodeParser();
        }
Ejemplo n.º 16
0
 public override ParserBase DecorateCodeParser(ParserBase parser)
 {
     return new MvcRazorCodeParser();
 }