Exemple #1
0
 internal LexemeEnumerator(LexemeSource <TToken> lexemeSource)
 {
     _lexemeSource  = lexemeSource;
     _pointer       = BufferSize - 1;
     _lexemeBuffer  = new Lexeme <TToken> [BufferSize];
     _operandBuffer = new int[BufferSize];
     _bufferSize    = BufferSize;
     Current        = default;
 }
Exemple #2
0
                public virtual void Mount(LexemeSource <TToken> lexemeSource, ParserContext parserContext, Parser <TGrammar, TToken> parser)
                {
                    _poolDictionary = _threadLocalPoolDictionary.Value;

                    LexemeSource  = lexemeSource;
                    TextSource    = lexemeSource.TextSource;
                    ParserContext = parserContext;

                    if (ParserContext != null)
                    {
                        ParserContext.ParserAutomataContext = this;
                    }
                }
Exemple #3
0
            public LexerProcess(Lexer <TGrammar, TToken> lexer, LexemeSource <TToken> lexemeSource)
            {
                var textSource   = lexemeSource.TextSource;
                var lexerContext = lexer.CreateContext(lexemeSource);

                if (textSource is StringTextSource stringTextSource)
                {
                    _process = new LexerAutomata.SpanProcess(stringTextSource, lexer, lexerContext);
                }
                else
                {
                    _process = new LexerAutomata.ReaderProcess(textSource, lexer, lexerContext);
                }
            }
Exemple #4
0
                public virtual void Dispose()
                {
                    TextSource      = null;
                    LexemeSource    = null;
                    _poolDictionary = null;

                    if (ParserContext == null)
                    {
                        return;
                    }

                    ParserContext.Dispose();

                    ParserContext.ParserAutomataContext = null;
                    ParserContext = null;
                }
Exemple #5
0
        protected void RunCore <TContext>(LexemeSource <TToken> lexemeSource, TContext context) where TContext : AutomataContext
        {
            using var instructionReader = new LexemeStreamInstructionReader(lexemeSource);

            RunCore(instructionReader, context);
        }
Exemple #6
0
        private protected AutomataResult PartialRunCore <TContext>(LexemeSource <TToken> lexemeSource, TContext context) where TContext : AutomataContext
        {
            using var instructionReader = new LexemeStreamInstructionReader(lexemeSource);

            return(PartialRunCore(instructionReader, context));
        }
Exemple #7
0
 public LexemeStreamInstructionReader(LexemeSource <TToken> lexemeSource)
 {
     _lexemeSource = lexemeSource;
 }
Exemple #8
0
 protected LexerContext(LexemeSource <TToken> lexemeSource)
 {
     LexemeSource = lexemeSource;
 }
Exemple #9
0
                public VisitorAutomataContext MountVisitorContext(Visitor visitor, ParserAutomata parserAutomata, LexemeSource <TToken> lexemeSource, ParserContext parserContext, Parser <TGrammar, TToken> parser)
                {
                    var pool = GetVisitorContextPool(visitor.GetType());

                    VisitorAutomataContext context;

                    lock (pool)
                        context = pool.Count > 0 ? pool.Pop() : new VisitorAutomataContext(visitor, this, parserAutomata);

                    context.Mount(lexemeSource, parserContext, parser);

                    return(context);
                }
Exemple #10
0
                public SyntaxTreeAutomataContext MountSyntaxTreeContext(ParserAutomata parserAutomata, LexemeSource <TToken> lexemeSource, ParserContext parserContext, Parser <TGrammar, TToken> parser)
                {
                    SyntaxTreeAutomataContext context;

                    lock (SyntaxTreeContextPool)
                        context = SyntaxTreeContextPool.Count > 0 ? SyntaxTreeContextPool.Pop() : new SyntaxTreeAutomataContext(this, parserAutomata);

                    context.Mount(lexemeSource, parserContext, parser);

                    return(context);
                }
Exemple #11
0
                public ProcessAutomataContext MountProcessContext(ParserAutomata parserAutomata, LexemeSource <TToken> lexemeSource, ParserContext parserContext, Parser <TGrammar, TToken> parser)
                {
                    ProcessAutomataContext context;

                    lock (ProcessContextPool)
                        context = ProcessContextPool.Count > 0 ? ProcessContextPool.Pop() : new ProcessAutomataContext(this, parserAutomata);

                    context.Mount(lexemeSource, parserContext, parser);

                    return(context);
                }