1 /*
2  * Copyright (c) 2012-2018 The ANTLR Project. All rights reserved.
3  * Use of this file is governed by the BSD 3-clause license that
4  * can be found in the LICENSE.txt file in the project root.
5  */
6 
7 module antlr.v4.runtime.tree.TerminalNodeImpl;
8 
9 import antlr.v4.runtime.InterfaceRecognizer;
10 import antlr.v4.runtime.RuleContext : RuleContext;
11 import antlr.v4.runtime.Token;
12 import antlr.v4.runtime.TokenConstantDefinition;
13 import antlr.v4.runtime.atn.StateNames;
14 import antlr.v4.runtime.misc.Interval;
15 import antlr.v4.runtime.tree.ParseTree;
16 import antlr.v4.runtime.tree.TerminalNode;
17 
18 /**
19  * TODO add class description
20  */
21 class TerminalNodeImpl : TerminalNode
22 {
23 
24     public Token symbol;
25 
26     public ParseTree parent;
27 
28     public this(Token symbol)
29     {
30         this.symbol = symbol;
31     }
32 
33     public ParseTree getChild(int i)
34     {
35         return null;
36     }
37 
38     public ParseTree getParent()
39     {
40         return parent;
41     }
42 
43     public void setParent(RuleContext parent)
44     {
45         this.parent = parent;
46     }
47 
48     public Token getSymbol()
49     {
50         return symbol;
51     }
52 
53     public Object getPayload()
54     {
55         return cast(Object)symbol;
56     }
57 
58     public Interval getSourceInterval()
59     {
60         if (symbol is null)
61             return cast(Interval)Interval.INVALID;
62         int tokenIndex = symbol.getTokenIndex();
63         return new Interval(tokenIndex, tokenIndex);
64 
65     }
66 
67     public int getChildCount()
68     {
69         return 0;
70     }
71 
72     public V accept(V, U)(ParseTreeVisitor!U visitor)
73     {
74         return visitor.visitTerminal(this);
75     }
76 
77     public string getText()
78     {
79         return symbol.getText();
80     }
81 
82     public string toStringTree(InterfaceRecognizer parser)
83     {
84         return toString();
85     }
86 
87     /**
88      * @uml
89      * @override
90      */
91     public override string toString()
92     {
93         if (symbol.getType() == TokenConstantDefinition.EOF )
94             return "<EOF>";
95         return symbol.getText();
96     }
97 
98     public string toStringTree()
99     {
100         return toString();
101     }
102 
103 }