Ejemplo n.º 1
0
        private bool MatchLexerRules(char character, IReadOnlyList <ILexerRule> lexerRules, List <ILexeme> lexemes)
        {
            var anyMatches = false;

            for (var i = 0; i < lexerRules.Count; i++)
            {
                var lexerRule = lexerRules[i];
                if (!lexerRule.CanApply(character))
                {
                    continue;
                }
                var factory = _lexemeFactoryRegistry.Get(lexerRule.LexerRuleType);
                var lexeme  = factory.Create(lexerRule, Position);

                if (!lexeme.Scan(character))
                {
                    FreeLexeme(lexeme);
                    continue;
                }

                if (!anyMatches)
                {
                    anyMatches = true;
                    lexemes.Clear();
                }

                lexemes.Add(lexeme);
            }

            return(anyMatches);
        }
Ejemplo n.º 2
0
    private bool MatchesNewLexemes(char character)
    {
        var newLexerRules     = ParseEngine.GetExpectedLexerRules();
        var anyMatchingLexeme = false;

        for (var i = 0; i < newLexerRules.Count; i++)
        {
            var lexerRule = newLexerRules[i];
            var factory   = _lexemeFactoryRegistry.Get(lexerRule.LexerRuleType);
            var lexeme    = factory.Create(lexerRule, Position);
            if (!lexeme.Scan(character))
            {
                factory.Free(lexeme);
                continue;
            }
            anyMatchingLexeme = true;
            _existingLexemes.Add(lexeme);
        }

        SharedPools.Default <List <ILexerRule> >().ClearAndFree(newLexerRules);
        return(anyMatchingLexeme);
    }