Ejemplo n.º 1
0
        public virtual void Parse(LookaheadTextReader input, ParserVisitor visitor)
        {
            ParserResults results = ParseCore(new SeekableTextReader(input));

            // Replay the results on the visitor
            visitor.Visit(results);
        }
        protected internal virtual ParserResults ParseTemplateCore(LookaheadTextReader input, CancellationToken? cancelToken) {
            // Setup the consumer
            SyntaxTreeBuilderVisitor treeBuilder = new SyntaxTreeBuilderVisitor() { CancelToken = cancelToken };

            // Construct the parser
            RazorParser parser = CreateParser();
            Debug.Assert(parser != null);
            parser.Parse(input, treeBuilder);

            // Return the results
            return treeBuilder.Results;
        }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
0
 public virtual ParserResults Parse(LookaheadTextReader input)
 {
     return ParseCore(new SeekableTextReader(input));
 }
Ejemplo n.º 5
0
 private ParserResults SyncParseCore(LookaheadTextReader input) {
     SyntaxTreeBuilderVisitor listener = new SyntaxTreeBuilderVisitor();
     Parse(input, listener);
     return listener.Results;
 }
Ejemplo n.º 6
0
 public virtual ParserResults Parse(LookaheadTextReader input) {
     return SyncParseCore(input);
 }
 protected void ReadToEnd(StringBuilder builder, LookaheadTextReader reader)
 {
     builder.Append(reader.ReadToEnd());
 }
 private static void AdvanceReader(int offset, LookaheadTextReader reader)
 {
     for (int i = 0; i < offset; i++)
     {
         reader.Read();
     }
 }
 private static void RunAll(Action<StringBuilder, LookaheadTextReader>[] readerCommands, StringBuilder builder, LookaheadTextReader reader)
 {
     foreach (Action<StringBuilder, LookaheadTextReader> readerCommand in readerCommands)
     {
         readerCommand(builder, reader);
     }
 }
 protected void CancelBacktrack(StringBuilder builder, LookaheadTextReader reader)
 {
     reader.CancelBacktrack();
 }
Ejemplo 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();
        }
Ejemplo n.º 12
0
 public virtual ParserContext CreateParserRun(LookaheadTextReader input, ParserBase codeParser, MarkupParser markupParser, ParserVisitor listener) {
     return new ParserContext(input, codeParser, markupParser, SelectActiveParser(codeParser, markupParser), listener);
 }
        protected internal virtual GeneratorResults GenerateCodeCore(LookaheadTextReader input, string className, string rootNamespace, string sourceFileName, CancellationToken? cancelToken) {
            className = className ?? Host.DefaultClassName;
            rootNamespace = rootNamespace ?? Host.DefaultNamespace;

            // Set up the code generator
            RazorCodeGenerator generator = CreateCodeGenerator(className, rootNamespace, sourceFileName);
            generator.DesignTimeMode = Host.DesignTimeMode;

            // Setup the consumers
            SyntaxTreeBuilderVisitor treeBuilder = new SyntaxTreeBuilderVisitor() { CancelToken = cancelToken };
            VisitorPair consumer = new VisitorPair(treeBuilder, generator);

            // Run the parser
            RazorParser parser = CreateParser();
            Debug.Assert(parser != null);
            parser.Parse(input, consumer);

            // Post process code
            Host.PostProcessGeneratedCode(generator.GeneratedCode, generator.GeneratedNamespace, generator.GeneratedClass, generator.GeneratedExecuteMethod);

            // Extract design-time mappings
            IDictionary<int, GeneratedCodeMapping> designTimeLineMappings = null;
            if (Host.DesignTimeMode) {
                designTimeLineMappings = generator.CodeMappings;
            }

            // Collect results and return
            return new GeneratorResults(treeBuilder.Results, generator.GeneratedCode, designTimeLineMappings);
        }