private static ScriptOrClassResult RewriteTokensScript(CommonTokenStream tokens) { IList<string> scripts = new List<string>(); IList<string> classes = new List<string>(); IList<UniformPair<int>> tokenIndexRanges = new List<UniformPair<int>>(); int tokenIndex = 0; while (tokenIndex < tokens.Size) { if (tokens.Get(tokenIndex).Type == EsperEPL2GrammarParser.EXPRESSIONDECL) { var tokenBefore = GetTokenBefore(tokenIndex, tokens); var isCreateExpressionClause = tokenBefore != null && tokenBefore.Type == EsperEPL2GrammarParser.CREATE; var nameAndNameStart = FindScriptName(tokenIndex + 1, tokens); var startIndex = FindStartTokenScript(nameAndNameStart.Second, tokens, EsperEPL2GrammarParser.LBRACK); if (startIndex != -1) { var endIndex = FindEndTokenScript( startIndex + 1, tokens, EsperEPL2GrammarParser.RBRACK, EsperEPL2GrammarParser.GetAfterScriptTokens(), !isCreateExpressionClause); if (endIndex != -1) { var writer = new StringWriter(); for (var j = startIndex + 1; j < endIndex; j++) { writer.Write(tokens.Get(j).Text); } scripts.Add(writer.ToString()); tokenIndexRanges.Add(new UniformPair<int>(startIndex, endIndex)); tokenIndex = endIndex; } } } if (tokens.Get(tokenIndex).Type == EsperEPL2GrammarParser.CLASSDECL) { int startIndex = FindTokenClass(tokenIndex, tokens); if (startIndex != -1) { int endIndex = FindTokenClass(startIndex + 1, tokens); if (endIndex != -1) { StringWriter writer = new StringWriter(); for (int j = startIndex + 1; j < endIndex; j++) { writer.Write(tokens.Get(j).Text); } classes.Add(writer.ToString()); tokenIndexRanges.Add(new UniformPair<int>(startIndex, endIndex)); tokenIndex = endIndex; } } } tokenIndex++; } var rewrittenEPL = RewriteEPL(tokenIndexRanges, tokens); return new ScriptOrClassResult(rewrittenEPL, scripts, classes); }
private static ScriptResult RewriteTokensScript(CommonTokenStream tokens) { IList <String> scripts = new List <String>(); IList <UniformPair <int?> > scriptTokenIndexRanges = new List <UniformPair <int?> >(); for (var i = 0; i < tokens.Size; i++) { if (tokens.Get(i).Type == EsperEPL2GrammarParser.EXPRESSIONDECL) { var tokenBefore = GetTokenBefore(i, tokens); var isCreateExpressionClause = tokenBefore != null && tokenBefore.Type == EsperEPL2GrammarParser.CREATE; var nameAndNameStart = FindScriptName(i + 1, tokens); var startIndex = FindStartTokenScript(nameAndNameStart.Second.Value, tokens, EsperEPL2GrammarParser.LBRACK); if (startIndex != -1) { var endIndex = FindEndTokenScript(startIndex + 1, tokens, EsperEPL2GrammarParser.RBRACK, EsperEPL2GrammarParser.GetAfterScriptTokens(), !isCreateExpressionClause); if (endIndex != -1) { var writer = new StringWriter(); for (var j = startIndex + 1; j < endIndex; j++) { writer.Write(tokens.Get(j).Text); } scripts.Add(writer.ToString()); scriptTokenIndexRanges.Add(new UniformPair <int?>(startIndex, endIndex)); } } } } var rewrittenEPL = RewriteScripts(scriptTokenIndexRanges, tokens); return(new ScriptResult(rewrittenEPL, scripts)); }