01: package org.jicengine.expression;
02:
03: import org.jicengine.operation.Operation;
04:
05: /**
06: * 'Limited Java Expression'-parser.
07: *
08: * <p>
09: * Copyright (C) 2004 Timo Laitinen
10: * </p>
11: * @author Timo Laitinen
12: * @created 2004-09-20
13: * @since JICE-0.10
14: *
15: */
16:
17: public class LJEParser implements Parser {
18:
19: private static LJEParser instance = new LJEParser();
20:
21: public static LJEParser getInstance() {
22: return instance;
23: }
24:
25: Parser parser;
26:
27: private LJEParser() {
28: // the order of the sub-parsers matters!
29:
30: // these atoms can be part of a FieldValue- or
31: // MethodInvocation-expressions
32: Parser atomParser = new CompositeParser(new Parser[] {
33: new VariableParser(), new ClassParser() });
34:
35: // the negated expression may be any expression.
36: // therefore we give the negationparser a
37: // CompositeParser instance.
38:
39: Parser negationParser = new NegationParser(new CompositeParser(
40: new Parser[] { new BuildParameterParser(),
41: new VariableParser(),
42: // note: no class-parser here
43: new FieldValueParser(atomParser),
44: new InvocationParser(atomParser) }));
45:
46: Parser factoryInvocationParser = new FactoryInvocationParser(
47: new VariableParser());
48:
49: // these parsers define the actual LJE-expressions.
50: parser = new CompositeParser(new Parser[] { negationParser,
51: new BuildParameterParser(), factoryInvocationParser,
52: new VariableParser(),
53: // note: no class-parser here
54: new FieldValueParser(atomParser),
55: new InvocationParser(atomParser) });
56: }
57:
58: public Operation parse(String expression) throws SyntaxException {
59: return this.parser.parse(expression);
60: }
61: }
|