Class: Dendroid::Parsing::TerminalNode
- Defined in:
- lib/dendroid/parsing/terminal_node.rb
Overview
A parse tree/forest node that is related to one input token.
Instance Attribute Summary collapse
-
#symbol ⇒ Dendroid::Syntax::Terminal
readonly
Terminal symbol of matching token.
-
#token ⇒ Dendroid::Lexical::Token
readonly
Matching input token object.
Attributes inherited from ParseNode
Instance Method Summary collapse
-
#accept(aVisitor) ⇒ Object
Part of the ‘visitee’ role in Visitor design pattern.
-
#initialize(sym, tok, rank) ⇒ TerminalNode
constructor
A new instance of TerminalNode.
-
#to_s ⇒ String
Render a String representation of itself.
Constructor Details
#initialize(sym, tok, rank) ⇒ TerminalNode
Returns a new instance of TerminalNode.
15 16 17 18 19 |
# File 'lib/dendroid/parsing/terminal_node.rb', line 15 def initialize(sym, tok, rank) super(rank, rank + 1) @symbol = sym @token = tok end |
Instance Attribute Details
#symbol ⇒ Dendroid::Syntax::Terminal (readonly)
Returns Terminal symbol of matching token.
10 11 12 |
# File 'lib/dendroid/parsing/terminal_node.rb', line 10 def symbol @symbol end |
#token ⇒ Dendroid::Lexical::Token (readonly)
Returns Matching input token object.
13 14 15 |
# File 'lib/dendroid/parsing/terminal_node.rb', line 13 def token @token end |
Instance Method Details
#accept(aVisitor) ⇒ Object
Part of the ‘visitee’ role in Visitor design pattern.
23 24 25 |
# File 'lib/dendroid/parsing/terminal_node.rb', line 23 def accept(aVisitor) aVisitor.visit_terminal(self) end |
#to_s ⇒ String
Render a String representation of itself
29 30 31 32 |
# File 'lib/dendroid/parsing/terminal_node.rb', line 29 def to_s display_val = token.literal? ? ": #{token.value}" : '' "#{symbol.name}#{display_val} #{range_to_s}" end |