/// <summary>
        /// Creates an instance of a template service.
        /// </summary>
        /// <param name="language">The language the template service to support.</param>
        /// <param name="strictMode">Specifies whether parsing exceptions will be thrown.</param>
        /// <param name="markupParser">The markup parser.</param>
        /// <returns>An instance of <see cref="TemplateService"/>.</returns>
        public static TemplateService CreateTemplateService(Language language = Language.CSharp, bool strictMode = false, MarkupParser markupParser = null)
        {
            var factory = Razor.CompilerServiceFactory;
            var compilerService = factory.CreateCompilerService(language, strictMode, markupParser);

            return new TemplateService(compilerService);
        }
Exemplo n.º 2
0
        public RazorParser(ParserBase codeParser, MarkupParser markupParser) {
            if (codeParser == null) { throw new ArgumentNullException("codeParser"); }
            if (markupParser == null) { throw new ArgumentNullException("markupParser"); }

            MarkupParser = markupParser;
            CodeParser = codeParser;
        }
Exemplo n.º 3
0
        private ParserResults ParseCore(ITextDocument input)
        {
            // Setup the parser context
            ParserContext context = new ParserContext(input, CodeParser, MarkupParser, MarkupParser)
            {
                DesignTimeMode = DesignTimeMode
            };

            MarkupParser.Context = context;
            CodeParser.Context   = context;

            // Execute the parse
            MarkupParser.ParseDocument();

            // Get the result
            ParserResults results = context.CompleteParse();

            // Rewrite whitespace if supported
            Block current = results.Document;

            foreach (ISyntaxTreeRewriter rewriter in Optimizers)
            {
                current = rewriter.Rewrite(current);
            }

            // Return the new result
            return(new ParserResults(current, results.ParserErrors));
        }
        /// <summary>
        /// Initialises a new instance of <see cref="DirectCompilerServiceBase"/>.
        /// </summary>
        /// <param name="codeLanguage">The razor code language.</param>
        /// <param name="codeDomProvider">The code dom provider used to generate code.</param>
        /// <param name="markupParser">The markup parser.</param>
        protected DirectCompilerServiceBase(RazorCodeLanguage codeLanguage, CodeDomProvider codeDomProvider, MarkupParser markupParser)
            : base(codeLanguage, markupParser)
        {
            if (codeDomProvider == null)
                throw new ArgumentNullException("codeDomProvider");

            CodeDomProvider = codeDomProvider;
        }
        /// <summary>
        /// Initialises a new instance of <see cref="CompilerServiceBase"/>
        /// </summary>
        /// <param name="codeLanguage">The code language.</param>
        /// <param name="markupParser">The markup parser.</param>
        protected CompilerServiceBase(RazorCodeLanguage codeLanguage, MarkupParser markupParser)
        {
            if (codeLanguage == null)
                throw new ArgumentNullException("codeLanguage");

            CodeLanguage = codeLanguage;
            MarkupParser = markupParser ?? new HtmlMarkupParser();
        }
        /// <summary>
        /// Creates an instance of a compiler service.
        /// </summary>
        /// <param name="language">The language to support in templates.</param>
        /// <param name="strictMode">Strict mode forces parsing exceptions to be thrown.</param>
        /// <param name="markupParser">The markup parser to use.</param>
        /// <returns>An instance of <see cref="ICompilerService"/>.</returns>
        public ICompilerService CreateCompilerService(Language language = Language.CSharp, bool strictMode = false, MarkupParser markupParser = null)
        {
            switch (language)
            {
                case Language.CSharp:
                    return new CSharpDirectCompilerService(strictMode, markupParser);
            }

            throw new ArgumentException("The language '" + language + "' is not supported.");
        }
Exemplo n.º 7
0
        public RazorParser(ParserBase codeParser, MarkupParser markupParser)
        {
            if (codeParser == null)
            {
                throw new ArgumentNullException("codeParser");
            }
            if (markupParser == null)
            {
                throw new ArgumentNullException("markupParser");
            }

            MarkupParser = markupParser;
            CodeParser   = codeParser;
        }
Exemplo n.º 8
0
        public virtual void Parse(LookaheadTextReader input, ParserVisitor visitor)
        {
            // Setup the parser context
            ParserContext context = new ParserContext(input, CodeParser, MarkupParser, MarkupParser, visitor)
            {
                DesignTimeMode = DesignTimeMode
            };

            MarkupParser.Context = context;
            CodeParser.Context   = context;

            // Execute the context
            try {
                MarkupParser.ParseDocument();
            }
            finally {
                context.OnComplete();
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initialises a new instance of <see cref="RazorCompiler"/>
        /// </summary>
        /// <param name="provider">The language provider used to create language services.</param>
        /// <param name="baseType">[Optional] The template base type.</param>
        /// <param name="parser">[Optional] The markup parser.</param>
        public RazorCompiler(ILanguageProvider provider, Type baseType = null, MarkupParser parser = null)
        {
            if (provider == null)
                throw new ArgumentNullException("provider");

            if (baseType != null && !typeof(ITemplate).IsAssignableFrom(baseType))
                throw new ArgumentException(
                    string.Format("{0} is not a valid template base.  Templates must inherit from ITemplate.",
                                  baseType.FullName));

            // Need to initialise this type to ensure assemblies are loaded for referencing. Eugh....
            var temp1 = Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags.None;

            languageProvider = provider;
            templateBaseType = baseType;

            markupParser = parser ?? new HtmlMarkupParser();

            Namespaces = new List<string> { "System", "System.Collections.Generic", "System.Linq" };
        }
Exemplo n.º 10
0
        private ParserResults ParseCore(ITextDocument input)
        {
            // Setup the parser context
            ParserContext context = new ParserContext(input, CodeParser, MarkupParser, MarkupParser)
            {
                DesignTimeMode = DesignTimeMode
            };

            MarkupParser.Context = context;
            CodeParser.Context   = context;

            // Execute the parse
            MarkupParser.ParseDocument();

            // Get the result
            ParserResults results = context.CompleteParse();

            // Rewrite whitespace if supported
            Block current = results.Document;

            foreach (ISyntaxTreeRewriter rewriter in Optimizers)
            {
                current = rewriter.Rewrite(current);
            }

            // Link the leaf nodes into a chain
            Span prev = null;

            foreach (Span node in current.Flatten())
            {
                node.Previous = prev;
                if (prev != null)
                {
                    prev.Next = node;
                }
                prev = node;
            }

            // Return the new result
            return(new ParserResults(current, results.ParserErrors));
        }
Exemplo n.º 11
0
        public ParserContext(LookaheadTextReader source, ParserBase codeParser, MarkupParser markupParser, ParserBase activeParser, ParserVisitor visitor)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (codeParser == null)
            {
                throw new ArgumentNullException("codeParser");
            }
            if (markupParser == null)
            {
                throw new ArgumentNullException("markupParser");
            }
            if (activeParser == null)
            {
                throw new ArgumentNullException("activeParser");
            }
            if (visitor == null)
            {
                throw new ArgumentNullException("visitor");
            }
            if (activeParser != codeParser && activeParser != markupParser)
            {
                throw new ArgumentException(RazorResources.ActiveParser_Must_Be_Code_Or_Markup_Parser, "activeParser");
            }

            CaptureOwnerTask();

            Source       = source;
            CodeParser   = codeParser;
            MarkupParser = markupParser;
            ActiveParser = activeParser;
            _visitorStack.Push(visitor);
            ResetBuffers();
        }
Exemplo n.º 12
0
 protected override ParserBase SelectActiveParser(ParserBase codeParser, MarkupParser markupParser) {
     return markupParser;
 }
Exemplo n.º 13
0
 public virtual ParserContext CreateParserRun(LookaheadTextReader input, ParserBase codeParser, MarkupParser markupParser, ParserVisitor listener) {
     return new ParserContext(input, codeParser, markupParser, SelectActiveParser(codeParser, markupParser), listener);
 }
Exemplo n.º 14
0
 private ParserContext SetupTestRun(string document, Action<TextReader> positioningAction, ParserBase codeParser, MarkupParser markupParser, ParserBase activeParser, ParserVisitor listener) {
     ParserContext context = new ParserContext(new BufferingTextReader(new StringReader(document)), codeParser, markupParser, activeParser, listener);
     positioningAction(context.Source);
     context.ResetBuffers();
     return context;
 }
Exemplo n.º 15
0
        public ParserContext(LookaheadTextReader source, ParserBase codeParser, MarkupParser markupParser, ParserBase activeParser, ParserVisitor visitor) {
            if (source == null) { throw new ArgumentNullException("source"); }
            if (codeParser == null) { throw new ArgumentNullException("codeParser"); }
            if (markupParser == null) { throw new ArgumentNullException("markupParser"); }
            if (activeParser == null) { throw new ArgumentNullException("activeParser"); }
            if (visitor == null) { throw new ArgumentNullException("visitor"); }
            if (activeParser != codeParser && activeParser != markupParser) {
                throw new ArgumentException(RazorResources.ActiveParser_Must_Be_Code_Or_Markup_Parser, "activeParser");
            }

            CaptureOwnerTask();

            Source = source;
            CodeParser = codeParser;
            MarkupParser = markupParser;
            ActiveParser = activeParser;
            _visitorStack.Push(visitor);
            ResetBuffers();
        }
 /// <summary>
 /// Initialises a new instance of <see cref="VBDirectCompilerService"/>.
 /// </summary>
 /// <param name="strictMode">Specifies whether the strict mode parsing is enabled.</param>
 /// <param name="markupParser">The markup parser to use.</param>
 public VBDirectCompilerService(bool strictMode = true, MarkupParser markupParser = null)
     : base(
         new VBRazorCodeLanguage(strictMode),
         new VBCodeProvider(),
         markupParser) { }
Exemplo n.º 17
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 MarkupParser DecorateMarkupParser(MarkupParser incomingMarkupParser) {
     if (incomingMarkupParser == null) { throw new ArgumentNullException("incomingMarkupParser"); }
     return incomingMarkupParser;
 }
Exemplo n.º 18
0
 /// <summary>
 /// Creates an instance of a <see cref="TemplateService"/>.
 /// </summary>
 /// <param name="provider">[Optional] The language provider to use.</param>
 /// <param name="templateBaseType">[Optional] The base template type.</param>
 /// <param name="parser">[Optional] The markup parser to use.</param>
 /// <returns>A new instance of <see cref="TemplateService"/>.</returns>
 public static TemplateService CreateTemplateService(ILanguageProvider provider = null, Type templateBaseType = null, MarkupParser parser = null)
 {
     return new TemplateService(provider, templateBaseType, parser);
 }
Exemplo n.º 19
0
 protected abstract ParserBase SelectActiveParser(ParserBase codeParser, MarkupParser markupParser);