aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2016-10-15 01:31:51 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2016-10-15 01:31:51 +0000
commit26c20f9517709f1aed44d35f6a2a349c5e5726cf (patch)
tree670baa3dbad31a759039712b92104f19f9a53485 /src/main
parent332ec655a597ba3c14f407b9b491752548f370ab (diff)
downloadjackcess-26c20f9517709f1aed44d35f6a2a349c5e5726cf.tar.gz
jackcess-26c20f9517709f1aed44d35f6a2a349c5e5726cf.zip
add debug to strings to start enabling some testing
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/exprs@1048 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/util/Expressionator.java125
1 files changed, 114 insertions, 11 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/util/Expressionator.java b/src/main/java/com/healthmarketscience/jackcess/util/Expressionator.java
index ce54b98..38d8ae6 100644
--- a/src/main/java/com/healthmarketscience/jackcess/util/Expressionator.java
+++ b/src/main/java/com/healthmarketscience/jackcess/util/Expressionator.java
@@ -133,21 +133,33 @@ public class Expressionator
@Override protected Object eval(RowContext ctx) {
return ctx.getThisColumnValue();
}
+ @Override protected void toExprString(StringBuilder sb, boolean isDebug) {
+ sb.append("<THIS_COL>");
+ }
};
private static final Expr NULL_VALUE = new Expr() {
@Override protected Object eval(RowContext ctx) {
return null;
}
+ @Override protected void toExprString(StringBuilder sb, boolean isDebug) {
+ sb.append("Null");
+ }
};
private static final Expr TRUE_VALUE = new Expr() {
@Override protected Object eval(RowContext ctx) {
return Boolean.TRUE;
}
+ @Override protected void toExprString(StringBuilder sb, boolean isDebug) {
+ sb.append("True");
+ }
};
private static final Expr FALSE_VALUE = new Expr() {
@Override protected Object eval(RowContext ctx) {
return Boolean.FALSE;
}
+ @Override protected void toExprString(StringBuilder sb, boolean isDebug) {
+ sb.append("False");
+ }
};
private Expressionator()
@@ -183,11 +195,7 @@ public class Expressionator
return null;
}
- TokBuf buf = new TokBuf(exprType, tokens);
- parseExpression(buf, false);
-
- // FIXME
- return null;
+ return parseExpression(new TokBuf(exprType, tokens), false);
}
private static List<Token> trimSpaces(List<Token> tokens) {
@@ -777,7 +785,7 @@ public class Expressionator
}
public void setPendingExpr(Expr expr) {
- if(_pendingExpr == null) {
+ if(_pendingExpr != null) {
throw new IllegalArgumentException(
"Found multiple expressions with no operator " + this);
}
@@ -830,8 +838,8 @@ public class Expressionator
}
private static boolean isHigherPrecendence(String op1, String op2) {
- int prec1 = PRECENDENCE.get(op1);
- int prec2 = PRECENDENCE.get(op2);
+ int prec1 = PRECENDENCE.get(op1.toLowerCase());
+ int prec2 = PRECENDENCE.get(op2.toLowerCase());
// higher preceendence ops have lower numbers
return (prec1 < prec2);
@@ -869,7 +877,32 @@ public class Expressionator
return val.equals(ctx.getThisColumnValue());
}
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ toString(sb, false);
+ return sb.toString();
+ }
+
+ public String toDebugString() {
+ StringBuilder sb = new StringBuilder();
+ toString(sb, true);
+ return sb.toString();
+ }
+
+ protected void toString(StringBuilder sb, boolean isDebug) {
+ if(isDebug) {
+ sb.append("<").append(getClass().getSimpleName()).append(">{");
+ }
+ toExprString(sb, isDebug);
+ if(isDebug) {
+ sb.append("}");
+ }
+ }
+
protected abstract Object eval(RowContext ctx);
+
+ protected abstract void toExprString(StringBuilder sb, boolean isDebug);
}
public interface RowContext
@@ -892,6 +925,19 @@ public class Expressionator
public Object eval(RowContext ctx) {
return _value;
}
+
+ @Override
+ protected void toExprString(StringBuilder sb, boolean isDebug) {
+ // FIXME, stronger typing?
+ if(_value instanceof String) {
+ sb.append("\"").append(_value).append("\"");
+ } else if(_value instanceof Date) {
+ // FIXME Date,Time,DateTime formatting?
+ sb.append("#").append(_value).append("#");
+ } else {
+ sb.append(_value);
+ }
+ }
}
private static final class EObjValue extends Expr
@@ -911,6 +957,17 @@ public class Expressionator
public Object eval(RowContext ctx) {
return ctx.getRowValue(_collectionName, _objName, _fieldName);
}
+
+ @Override
+ protected void toExprString(StringBuilder sb, boolean isDebug) {
+ if(_collectionName != null) {
+ sb.append("[").append(_collectionName).append("].");
+ }
+ if(_objName != null) {
+ sb.append("[").append(_objName).append("].");
+ }
+ sb.append("[").append(_fieldName).append("]");
+ }
}
private static abstract class EOp
@@ -935,6 +992,13 @@ public class Expressionator
protected Object eval(RowContext ctx) {
return _expr.eval(ctx);
}
+
+ @Override
+ protected void toExprString(StringBuilder sb, boolean isDebug) {
+ sb.append("(");
+ _expr.toString(sb, isDebug);
+ sb.append(")");
+ }
}
private static class EFunc extends Expr
@@ -953,6 +1017,22 @@ public class Expressionator
return false;
}
+
+ @Override
+ protected void toExprString(StringBuilder sb, boolean isDebug) {
+ sb.append(_name).append("(");
+
+ if(!_params.isEmpty()) {
+ Iterator<Expr> iter = _params.iterator();
+ iter.next().toString(sb, isDebug);
+ while(iter.hasNext()) {
+ sb.append(",");
+ iter.next().toString(sb, isDebug);
+ }
+ }
+
+ sb.append(")");
+ }
}
private static abstract class EBaseBinaryOp extends Expr
@@ -1002,6 +1082,8 @@ public class Expressionator
// as all other precedence has been resolved in previous parsing
// rounds.
if((leftOp._right == this) && isHigherPrecendence(leftOp._op, _op)) {
+
+ // FIXME, need to move up if precedecne is the same!
// doh, "this" is lower precedence, restore the original order of
// things
@@ -1013,6 +1095,13 @@ public class Expressionator
return outerExpr;
}
+
+ @Override
+ protected void toExprString(StringBuilder sb, boolean isDebug) {
+ _left.toString(sb, isDebug);
+ sb.append(" ").append(_op).append(" ");
+ _right.toString(sb, isDebug);
+ }
}
private static class EBinaryOp extends EBaseBinaryOp
@@ -1033,11 +1122,11 @@ public class Expressionator
private static class EUnaryOp extends Expr
{
private final String _op;
- private final Expr _val;
+ private final Expr _expr;
- private EUnaryOp(String op, Expr val) {
+ private EUnaryOp(String op, Expr expr) {
_op = op;
- _val = val;
+ _expr = expr;
}
@Override
@@ -1046,6 +1135,12 @@ public class Expressionator
return null;
}
+
+ @Override
+ protected void toExprString(StringBuilder sb, boolean isDebug) {
+ sb.append(" ").append(_op).append(" ");
+ _expr.toString(sb, isDebug);
+ }
}
private static class ECompOp extends EBaseBinaryOp
@@ -1085,6 +1180,14 @@ public class Expressionator
_op = op;
_expr = expr;
}
+
+ @Override
+ protected void toExprString(StringBuilder sb, boolean isDebug) {
+ // FIXME
+ throw new UnsupportedOperationException("FIXME");
+ // _expr.toString(sb, isDebug);
+ // sb.append(" ").append(_op);
+ }
}
private static class ENullOp extends ESpecOp