public Object evaluate(ExpressionEvaluator ee, Expression e) { if (checkOperator(e)) { final int count = 1; if (checkOperandCount(e, count)) { return ee.evaluate(e.getOperand(0)); } else throw new BadOperandCountException(e, count, count); } else throw new BadOperatorException(e, "group"); }
void pushOperand(Token t) { assert t.isLiteral(); pushOperand(new Expression(Operator.LITERAL, t)); }
private void parseExpression() { parsePrimary(); Token t = state.next(); while (t != Token.EOS) { if (t.isBinaryOp()) { state.consume(); state.pushOperator(Operator.fromToken(t, OperatorContext.BINARY)); parsePrimary(); } else break; t = state.next(); } while (state.topOperator() != Operator.SENTINEL) state.popOperator(); }
public Object evaluate(ExpressionEvaluator ee, Expression e) { if (checkOperator(e)) { final int count = 1; if (checkOperandCount(e, count)) { Object o0 = e.getOperand(0); if (!(o0 instanceof Token)) throw new IncompatibleOperandException(e, o0, Token.class); else return evaluate(ee.getState(), e.getOperator(), o0); } else throw new BadOperandCountException(e, count, count); } else throw new BadOperatorException(e, "literal"); }
Condition parse(CharBuffer cb) { if (cb.hasRemaining()) { state.setInput(cb, skipWhitespace); state.operators().push(Operator.SENTINEL); parseExpression(); state.expect(Token.EOS); return new Condition(state.topOperand()); } else throw new ParserException("empty condition"); }
public void merge(QName name, String value) { merge(new StyleSpecification(name, value)); }
protected void out(ReportType type, Message message) { out(type, message.toText(bundle, isHidingLocation(), isHidingPath())); }
public static EvaluatorState makeEvaluatorState(Map<String,Object> mediaParams, Map<String,Object> boundParams, Set<String> supportFeatures) { EvaluatorState state = new EvaluatorBindingState(); if (mediaParams == null) mediaParams = new java.util.HashMap<String,Object>(); state.setBinding("media", new MediaFunction(mediaParams)); if (boundParams == null) boundParams = new java.util.HashMap<String,Object>(); state.setBinding("parameter", new ParameterFunction(boundParams)); if (supportFeatures == null) supportFeatures = new java.util.HashSet<String>(); state.setBinding("supports", new SupportsFunction(supportFeatures)); return state; }
public static MediaQuery valueOf(String query) throws ParserException { // [TBD] implement me return new MediaQuery(new Query()); }
public void logDebug(Message message) { if (isDebuggingEnabled()) { out(ReportType.Debug, message); } }
private boolean checkOperator(Expression e) { Operator operator = e.getOperator(); if (operator == Operator.LITERAL) return true; else return false; }
public boolean preVisit(Object content, Object parent) throws Exception { if (order != Order.Post) return visit(content, parent, Order.Pre); else return true; } public boolean postVisit(Object content, Object parent) throws Exception {
public boolean logWarning(Message message) { if (!disableWarnings) { if (!hideWarnings) out(ReportType.Warning, message); ++resourceWarnings; } return treatWarningAsError; }
public int comparePrecedence(Operator other) { if (getPrecedence() < other.getPrecedence()) return -1; else if (getPrecedence() > other.getPrecedence()) return 1; else return 0; }
private boolean checkOperator(Expression e) { Operator operator = e.getOperator(); if (operator == Operator.MINUS) return true; else if (operator == Operator.PLUS) return true; else return false; }
public boolean postVisit(Object content, Object parent) throws Exception { if (order != Order.Pre) return visit(content, parent, Order.Post); else return true; } public abstract boolean visit(Object content, Object parent, Order order) throws Exception;