Class: Dendroid::Parsing::TerminalNode
- Defined in:
- lib/dendroid/parsing/terminal_node.rb
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 ⇒ Object
Constructor Details
#initialize(sym, tok, rank) ⇒ TerminalNode
Returns a new instance of TerminalNode.
14 15 16 17 18 |
# File 'lib/dendroid/parsing/terminal_node.rb', line 14 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.
9 10 11 |
# File 'lib/dendroid/parsing/terminal_node.rb', line 9 def symbol @symbol end |
#token ⇒ Dendroid::Lexical::Token (readonly)
Returns Matching input token object.
12 13 14 |
# File 'lib/dendroid/parsing/terminal_node.rb', line 12 def token @token end |
Instance Method Details
#accept(aVisitor) ⇒ Object
Part of the ‘visitee’ role in Visitor design pattern.
22 23 24 |
# File 'lib/dendroid/parsing/terminal_node.rb', line 22 def accept(aVisitor) aVisitor.visit_terminal(self) end |
#to_s ⇒ Object
26 27 28 29 |
# File 'lib/dendroid/parsing/terminal_node.rb', line 26 def to_s display_val = token.is_a?(Dendroid::Lexical::Literal) ? ": #{token.value}" : '' "#{symbol.name}#{display_val} #{super}" end |