Line splitRemainder(int trimmedIndex) { String after = _trimmed.substring(trimmedIndex); return new Line(after, after, _lineNumber, _endOfLine); }
/** * Ensure that there are no tabs. */ private void rejectTabs() { for (Line line : _lines) { if (line.containsTab()) { throw new IllegalArgumentException("Tab character not permitted: " + line); } } }
while (lineIterator.hasNext()) { Line line = lineIterator.next(); if (line.isComment()) { lineIterator.remove(); continue; if (line.indent() <= indent) { lineIterator.previous(); return; String trimmed = line.lineTrimmed(); if (trimmed.startsWith("@NAME")) { Matcher nameMatcher = NAME_PATTERN.matcher(trimmed); parseContainerSection(nameFragment, lineIterator, line.indent()); if (nameFragment.getFragments().size() == 0) { throw new IllegalArgumentException("@NAME found with no subsequent indented lines: " + line); parseContainerSection(whereFragment, lineIterator, line.indent()); if (whereFragment.getFragments().size() == 0) { throw new IllegalArgumentException("@PAGING found with no subsequent indented lines: " + line); parseContainerSection(whereFragment, lineIterator, line.indent()); if (whereFragment.getFragments().size() == 0) { throw new IllegalArgumentException("@WHERE found with no subsequent indented lines: " + line); parseContainerSection(andFragment, lineIterator, line.indent()); if (andFragment.getFragments().size() == 0) { throw new IllegalArgumentException("@AND found with no subsequent indented lines: " + line);
Line[] split = line.split(line.lineTrimmed().indexOf(tagName)); parseLine(container, split[0]); String trimmed = split[1].lineTrimmed(); remainderIndex = end + endTag.length(); TextSqlFragment contentTextFragment = new TextSqlFragment(content, line.endOfLine()); Matcher matcher = OPERATOR_VARIABLE_PATTERN.matcher(content); if (matcher.matches() == false) { operatorFragment.addFragment(contentTextFragment); Line subLine = split[1].splitRemainder(remainderIndex); parseLine(container, subLine);
String trimmed = line.lineTrimmed(); if (trimmed.length() == 0) { return; TextSqlFragment textFragment = new TextSqlFragment(trimmed, line.endOfLine()); container.addFragment(textFragment); TextSqlFragment textFragment = new TextSqlFragment(trimmed, line.endOfLine()); container.addFragment(textFragment);
Line[] split = line.split(line.lineTrimmed().indexOf("@OFFSETFETCH")); parseLine(container, split[0]); String trimmed = split[1].lineTrimmed(); container.addFragment(pagingFragment); Line subLine = split[1].splitRemainder(remainderIndex); parseLine(container, subLine);
Line[] split = line.split(line.lineTrimmed().indexOf("@FETCH")); parseLine(container, split[0]); String trimmed = split[1].lineTrimmed(); container.addFragment(pagingFragment); Line subLine = split[1].splitRemainder(remainderIndex); parseLine(container, subLine);
/** * Parse VALUE tag. * <p> * This tag can appear anywhere in a line. * The text before is treated as simple text. * The text after is parsed. * * @param container the container to add to, not null * @param line the line to parse, not null */ private void parseValueTag(ContainerSqlFragment container, Line line) { Line[] split = line.split(line.lineTrimmed().indexOf("@VALUE")); parseLine(container, split[0]); Line lineStartingAtTag = split[1]; Matcher matcher = VALUE_PATTERN.matcher(lineStartingAtTag.lineTrimmed()); if (matcher.matches() == false) { throw new IllegalArgumentException("@VALUE found with invalid format: " + line); } String followingSpaces = matcher.group(2); Line subLine = lineStartingAtTag.splitRemainder(matcher.start(3)); boolean followWithSpace = (followingSpaces != null && followingSpaces.length() > 0) || subLine.lineTrimmed().isEmpty(); ValueSqlFragment valueFragment = new ValueSqlFragment(matcher.group(1), followWithSpace); container.addFragment(valueFragment); parseLine(container, subLine); }
/** * Parse INCLUDE tag. * <p> * This tag can appear anywhere in a line. * It substitutes the entire content of the named section in at this point. * The text before is treated as simple text. * The text after is parsed. * * @param container the container to add to, not null * @param line the line to parse, not null */ private void parseIncludeTag(ContainerSqlFragment container, Line line) { Line[] split = line.split(line.lineTrimmed().indexOf("@INCLUDE")); parseLine(container, split[0]); String trimmed = split[1].lineTrimmed(); Matcher matcher = INCLUDE_PATTERN.matcher(trimmed); if (matcher.matches() == false) { throw new IllegalArgumentException("@INCLUDE found with invalid format: " + line); } IncludeSqlFragment includeFragment = new IncludeSqlFragment(matcher.group(1)); container.addFragment(includeFragment); Line subLine = split[1].splitRemainder(matcher.start(2)); parseLine(container, subLine); }
@Override public String toString() { return "Line " + lineNumber(); } }
/** * Creates the parser. * * @param lines the lines, not null */ ElSqlParser(List<String> lines) { for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); _lines.add(new Line(line, i + 1)); } }