KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jicengine > expression > LJEParser


1 package org.jicengine.expression;
2
3 import org.jicengine.operation.Operation;
4
5 /**
6  * 'Limited Java Expression'-parser.
7  *
8  * <p>
9  * 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     {
23         return instance;
24     }
25
26     Parser parser;
27
28     private LJEParser() {
29         // the order of the sub-parsers matters!
30

31         // these atoms can be part of a FieldValue- or
32
// MethodInvocation-expressions
33
Parser atomParser = new CompositeParser(new Parser[]{
34             new VariableParser(),
35             new ClassParser()
36         });
37
38         // the negated expression may be any expression.
39
// therefore we give the negationparser a
40
// CompositeParser instance.
41

42         Parser negationParser = new NegationParser(
43             new CompositeParser(new Parser[]{
44                 new BuildParameterParser(),
45                 new VariableParser(),
46                 // note: no class-parser here
47
new FieldValueParser(atomParser),
48                 new InvocationParser(atomParser)
49             }));
50
51         Parser factoryInvocationParser = new FactoryInvocationParser(new VariableParser());
52
53         // these parsers define the actual LJE-expressions.
54
parser = new CompositeParser(new Parser[]{
55             negationParser,
56             new BuildParameterParser(),
57             factoryInvocationParser,
58             new VariableParser(),
59             // note: no class-parser here
60
new FieldValueParser(atomParser),
61             new InvocationParser(atomParser)
62         });
63     }
64
65     public Operation parse(String JavaDoc expression) throws SyntaxException
66     {
67         return this.parser.parse(expression);
68     }
69 }
70
Popular Tags