@Override public int parse(List<String> mergedLines, int index) { boolean elseReached = false; int i = index; for (int ii = mergedLines.size(); i < ii; ++i) { String line = mergedLines.get(i); String clearLine; if (line.startsWith("--")) { clearLine = ParserUtils.substr(line, "--".length()); } else { Matcher matcher = ParserUtils.inlineComment.matcher(line); if (matcher.matches()) { clearLine = matcher.group(1).trim(); } else { multiPart.addPart(new LiteralPart(line)); continue; } } if ("end".equalsIgnoreCase(clearLine)) { newCondition(); return i + 1; } if ("else".equalsIgnoreCase(clearLine)) { newCondition(); lastCondExpr = "true"; elseReached = true; continue; } Matcher matcher = elseIfPattern.matcher(clearLine); if (matcher.matches()) { // else if if (elseReached) throw new RuntimeException("syntax error, else if position is illegal"); newCondition(); lastCondExpr = EqlUtils.trimToEmpty(matcher.group(1)); if (EqlUtils.isBlank(lastCondExpr)) throw new RuntimeException("syntax error, no condition in else if"); continue; } PartParser partParser = PartParserFactory.tryParse(clearLine); if (partParser != null) { i = partParser.parse(mergedLines, i + 1) - 1; multiPart.addPart(partParser.createPart()); } } return i; }