public static ScelExpr parse(String expr) { return new ScelParser(expr).expr(); }
private String nextLiteral() { skipWhitespaces(); int start = pos; for (; ; ) { nextChar(); if (isWhitespace() || ch == ')' || eof()) { break; } // if(!isIdentifierChar(ch)) { // error("Illegal identifier char '" + ch + "'"); // } } String s = substring(start, pos); if (s.isEmpty()) { error("Unexpected eof"); } return s; }
private String scanInValues(List<ScelNode> values) { int start = pos; skipWhitespaces(); if (ch == '(') { nextChar(); scanInValues(values, true); return substring(start, pos); } else { scanInValues(values, false); return substring(start, pos); } }
nextChar(); if (eof()) { break; if (isWhitespace()) { nextChar(); continue; parens++; nodes.add(LPAREN); nextChar(); break; error("Illegal char ')'"); nextChar(); break; scanAndOr(); andOr = false; break; if (scanName()) { if (scanOperator()) { scanValue(); error("Unclosed expression, ')' required");
private boolean scanOperator() { skipWhitespaces(); if (eof()) { error("Expected operator, but eof"); nextChar(); return true; String op = nextLiteral(); error("Invalid operator '" + op + "'"); String s = nextLiteral(); if (!s.equalsIgnoreCase("null")) { error("Expected 'null' but '" + s + "'"); String s = nextLiteral(); if (s.equalsIgnoreCase("not")) { nodes.add(new ScelNode(ScelToken.IS_NOT, op + " " + s)); s = nextLiteral(); if (!s.equalsIgnoreCase("null")) { error("Expected 'null' but '" + s + "'"); error("Unexpected literal '" + s + "' after IS"); scanInValue(); return false; } else {
private void scanInValues(List<ScelNode> values, boolean close) { for (; ; ) { skipWhitespaces(); if (ch == ',') { nextChar(); continue; } if(ch == ')') { if(close) { nextChar(); } break; } if (values.size() > 0 && (eof() || isWhitespace())) { break; } values.add(scanInValueNode(close)); } }
private void scanAndOr() { if (ch == ',') { nodes.add(AND); nextChar(); return; } String s = nextLiteral(); if (s.equalsIgnoreCase("and")) { nodes.add(new ScelNode(ScelToken.AND, s)); } else if (s.equalsIgnoreCase("or")) { nodes.add(new ScelNode(ScelToken.OR, s)); } else { error("Expect 'AND' or 'OR' operator but was '" + s + "'"); } }
private void scanValue() { ScelNode node = scanValueOnly(); if (!node.isNull()) { ScelToken last = nodes.get(nodes.size() - 1).token; if (last == ScelToken.IS_NOT || last == ScelToken.IS) { error("Invalid value of operation '" + last + "', it must be null"); } } nodes.add(node); }
private boolean scanName() { String alias = null; String name = scanIdentifier(true); if (name.equalsIgnoreCase("not")) { nodes.add(new ScelNode(ScelToken.NOT, name)); return false; } if (ch == '.') { nextChar(); alias = name; name = scanIdentifier(false); } nodes.add(new ScelName(alias, name)); return true; }
private String scanIdentifier(boolean dot) { skipWhitespaces(); int start = pos; for (; ; ) { nextChar(); if (dot && ch == '.') { break; } if (ch == ':' || isWhitespace() || eof()) { break; } if (!isIdentifierChar(ch)) { error("Illegal identifier char '" + ch + "'"); } } String s = substring(start, pos); if (s.isEmpty()) { error("Unexpected eof"); } return s; }
private ScelNode scanValueOnly() { skipWhitespaces(); nextChar(); if (charAt(pos + 1) == quotedChar) { nextChar(); continue; nextChar(); break; error("Invalid character [" + quoted + "], should use [" + quotedChar + quotedChar + "] instead"); if (ch == '(' && charAt(pos + 1) == ')') { nextChar(); nextChar(); end = pos; break; if (eof()) { error("Unclosed string value"); } else if (isWhitespace() || eof() || ch == '(' || ch == ')') { end = pos; break; String value = Strings.replace(substring(start, end), "''", "'"); if (!Strings.equals(ScelToken.NULL.name(), value.toUpperCase())) { return new ScelNode(ScelToken.VALUE, value, quoted);