Ejemplo n.º 1
0
        protected List <Token> OutputFilter(List <Token> lexes)
        {
            var outputPattern = new StartEndTokensPattern(
                TokenType.OUTPUT_OPERATOR,
                TokenType.LINE_END);
            var outputPatternResult = outputPattern.GetMatch(lexes);

            while (outputPatternResult.IsFullMatch)
            {
                var outputLexes = lexes.GetRange(outputPatternResult.Start + 1, outputPatternResult.Length - 2);
                lexes.RemoveRange(outputPatternResult.Start + 1, outputPatternResult.Length - 2);
                var inputText  = TokenUtils.TokensToString(outputLexes);
                var newTextLex = new Token(TokenType.TEXT, inputText);
                lexes.Insert(outputPatternResult.Start + 1, newTextLex);
                outputPatternResult = outputPattern.GetMatch(lexes, outputPatternResult.Start + 1);
            }

            return(lexes);
        }
Ejemplo n.º 2
0
        protected List <Token> StringUniteFilter(List <Token> lexes)
        {
            var strStartPattern = AnyOfTokensPatternBuilder
                                  .Reset()
                                  .Or(TokenType.DOUBLE_QUOTE)
                                  .Or(TokenType.SINGLE_QUOTE)
                                  .Build();
            var strStartPatternResult = strStartPattern.GetMatch(lexes);

            while (strStartPatternResult.IsFullMatch)
            {
                var quoteType       = lexes[strStartPatternResult.Start].TokenType;
                var quotePattern    = new StartEndTokensPattern(quoteType, quoteType);
                var quotePatternRes = quotePattern.GetMatch(lexes, strStartPatternResult.Start);
                var textLexes       = lexes.GetRange(strStartPatternResult.Start + 1, quotePatternRes.Length - 2);
                lexes.RemoveRange(strStartPatternResult.Start, quotePatternRes.Length);
                var text       = TokenUtils.TokensToString(textLexes);
                var newTextLex = new Token(TokenType.TEXT, text);
                lexes.Insert(strStartPatternResult.Start, newTextLex);
                strStartPatternResult = strStartPattern.GetMatch(lexes, strStartPatternResult.Start);
            }

            return(lexes);
        }