01: package org.jicengine.expression;
02:
03: import org.jicengine.operation.*;
04:
05: /**
06: * <p> </p>
07: *
08: * <p> </p>
09: *
10: * <p> </p>
11: *
12: * <p> </p>
13: *
14: * @author timo laitinen
15: */
16: public class NegationParser implements Parser {
17: private Parser parser;
18:
19: public NegationParser(Parser subParser) {
20: this .parser = subParser;
21: }
22:
23: /**
24: * @return Parsers may return null in order to signal 'abort' i.e.
25: *
26: * @return Parsers may return null in order to signal 'abort' i.e. if the
27: * syntax of the expression is not understood by the parser
28: * implementation. i.e. NumberParser returns null if the expression is a
29: * string-expression..
30: * @throws SyntaxException
31: * @param expression String
32: */
33: public Operation parse(String expression) throws SyntaxException {
34: if (expression.startsWith("!")) {
35: // looks promising..
36: Operation operation = this .parser.parse(expression
37: .substring(1));
38: if (operation != null) {
39: // looks still ok.
40: return new NegationOperation(operation);
41: } else {
42: return null;
43: }
44: } else {
45: return null;
46: }
47: }
48: }
|