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); } }
public static ScelExpr parse(String expr) { return new ScelParser(expr).expr(); }
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 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);
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 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 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 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 + "'"); } }
protected void applyFieldFilterIn(WhereBuilder.Expr expr, String alias, FieldMapping fm, List<ScelNode> values) { expr.append(alias).append('.').append(fm.getFieldName()).append(' ').append("in").append(" ?"); final Class<?> type = ((FieldMapping) fm).getJavaType(); Object[] args = new Object[values.size()]; for (int i = 0; i < args.length; i++) { ScelNode value = values.get(i); if (ScelToken.NULL == value.token()) { args[i] = null; } else { args[i] = Converts.convert(value.literal(), type); } } expr.arg(args); }
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); }
@Override public String toString() { StringBuilder s = new StringBuilder(); for (int i = 0; i < nodes.length; i++) { ScelNode node = nodes[i]; if (i > 0) { s.append(' '); } if (node.isQuoted()) { s.append('\''); } s.append(node.literal()); if (node.isQuoted()) { s.append('\''); } } return s.toString(); }
private void scanInValue() { List<ScelNode> values = new ArrayList<>(); String literal = scanInValues(values).trim(); nodes.add(new ScelNode(ScelToken.VALUE, literal, values)); }
public ScelNameValue findNameValue(String name) { return findNameValue(name, false); }
private static final void op(ScelToken token) { OPS.put(token.name(), token); }
public ScelNameValue findNameValue(String name, boolean ignoreCase) { for (int i = 0; i < nodes.length; i++) { ScelNode node = nodes[i]; if (node instanceof ScelName) { ScelName nameNode = (ScelName) node; if (Strings.equals(nameNode.literal, name, ignoreCase)) { ScelNode opNode = nodes[++i]; ScelNode valNode = nodes[++i]; return new ScelNameValue(nameNode, opNode.token, valNode); } } } return null; }
public boolean test(Map o) { if (null == expression) { expression = toExpression(); } return Boolean.TRUE.equals(expression.getValue(o)); }
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; }