Пример #1
0
        private bool NextTypeRequiresConcat(RegExToken.TokenType type)
        {
            switch (type)
            {
                case RegExToken.TokenType.Accept:
                case RegExToken.TokenType.OperatorOpenParanthesis:
                    return true;

            }
            return false;
        }
Пример #2
0
 private bool PreceedingTypeRequiresConcat(RegExToken.TokenType type)
 {
     switch (type)
     {
         case RegExToken.TokenType.OperatorMul:
         case RegExToken.TokenType.OperatorQuestion:
         case RegExToken.TokenType.OperatorPlus:
         case RegExToken.TokenType.Accept:
         case RegExToken.TokenType.OperatorCloseParanthesis:
         case RegExToken.TokenType.NumberedRepeat:
             return true;
     }
     return false;
 }
Пример #3
0
        private IEnumerable <RegExToken> TokensWithImplicitConcat()
        {
            RegExToken lastToken = null;

            for (var token = lexer.NextToken(); token != null;)
            {
                // If the last token was accept and this new token is also accept we need to insert a concat operator
                // between the two.
                if (lastToken != null &&
                    PreceedingTypeRequiresConcat(lastToken.Type) &&
                    NextTypeRequiresConcat(token.Type))
                {
                    yield return(new RegExToken {
                        Type = RegExToken.TokenType.OperatorConcat
                    });
                }

                yield return(token);

                lastToken = token;
                token     = lexer.NextToken();
            }
        }