1 module gamma.grammar.Alternative;
2 
3 import gamma.grammar.Node;
4 import gamma.grammar.Nonterminal;
5 import gamma.grammar.SymbolNode;
6 import gamma.grammar.Visitor;
7 import gamma.util.Position;
8 
9 public class Alternative
10 {
11     private SymbolNode lhs_;
12 
13     private Node[] rhs_;
14 
15     private Position position_;
16 
17     /**
18      * Creates an unmodifiable alternative.
19      *
20      * @param lhs
21      *            the nonterminal occurrence for the left-hand side
22      * @param rhs
23      *            the list of occurrences of symbols or operators for the right-hand side
24      * @param position
25      *            the position for the alternative
26      *
27      * @precondition the symbol for the left-hand side is a nonterminal
28      */
29     public this(SymbolNode lhs, Node[] rhs, Position position)
30     in (cast(Nonterminal) lhs.symbol())
31     {
32         this.lhs_ = lhs;
33         this.rhs_ = rhs.dup;
34         this.position_ = position;
35     }
36 
37     public void accept(Visitor visitor) {
38         visitor.visit(this);
39     }
40 
41     /**
42      * Returns the identifier occurrence for the left-hand side.
43      */
44     public SymbolNode lhs()
45     {
46         return this.lhs_;
47     }
48 
49     /**
50      * Returns the list of occurrences of symbols or operators for the right-hand side.
51      */
52     public Node[] rhs()
53     {
54         return this.rhs_;
55     }
56 
57     /**
58      * Returns the position for the alternative.
59      */
60     public Position position()
61     {
62         return this.position_;
63     }
64 }