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 import std.conv;
18 import std.variant;
19 
20 /**
21  * TODO add class description
22  */
23 class TerminalNodeImpl : TerminalNode
24 {
25 
26     public Token symbol;
27 
28     public ParseTree parent;
29 
30     public this(Token symbol)
31     {
32         this.symbol = symbol;
33     }
34 
35     public ParseTree getChild(int i)
36     {
37         return null;
38     }
39 
40     public ParseTree getParent()
41     {
42         return parent;
43     }
44 
45     public void setParent(RuleContext parent)
46     {
47         this.parent = parent;
48     }
49 
50     public Token getSymbol()
51     {
52         return symbol;
53     }
54 
55     public Object getPayload()
56     {
57         return cast(Object)symbol;
58     }
59 
60     public Interval getSourceInterval()
61     {
62         if (symbol is null)
63             return cast(Interval)Interval.INVALID;
64         int tokenIndex = symbol.getTokenIndex();
65         return new Interval(tokenIndex, tokenIndex);
66 
67     }
68 
69     public int getChildCount()
70     {
71         return 0;
72     }
73 
74     public V accept(V, U)(ParseTreeVisitor!U visitor)
75     {
76         return visitor.visitTerminal(this);
77     }
78 
79     public Variant getText()
80     {
81         return symbol.getText();
82     }
83 
84     public string toStringTree(InterfaceRecognizer parser)
85     {
86         return toString();
87     }
88 
89     /**
90      * @uml
91      * @override
92      */
93     public override string toString()
94     {
95         if (symbol.getType() == TokenConstantDefinition.EOF )
96             return "<EOF>";
97         return to!string(symbol.getText);
98     }
99 
100     public string toStringTree()
101     {
102         return toString();
103     }
104 
105 }