Class: PryCoolline::ParenMatch::AST::Root
- Inherits:
-
Struct
- Object
- Struct
- PryCoolline::ParenMatch::AST::Root
- Defined in:
- lib/pry-coolline/paren_match.rb
Overview
The root of the AST tree.
Instance Attribute Summary collapse
-
#elements ⇒ Array<Leaf, DanglingClose, Node>
All the top-level nodes of the tree.
Instance Method Summary collapse
-
#initialize(parser) ⇒ Root
constructor
A new instance of Root.
-
#pair_at(pos) ⇒ Pair
Finds the opening and closing tokens that should be matched at a certain position in the string.
Constructor Details
#initialize(parser) ⇒ Root
Returns a new instance of Root.
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/pry-coolline/paren_match.rb', line 74 def initialize(parser) self.elements = [] while tok = parser.next_token case tok when OpenToken then elements << Node.new(parser, tok) when StrToken then elements << Leaf.new(tok) when CloseToken then elements << DanglingClose.new(tok) end end end |
Instance Attribute Details
#elements ⇒ Array<Leaf, DanglingClose, Node>
All the top-level nodes of the tree.
72 73 74 |
# File 'lib/pry-coolline/paren_match.rb', line 72 def elements @elements end |
Instance Method Details
#pair_at(pos) ⇒ Pair
Finds the opening and closing tokens that should be matched at a certain position in the string.
It is assumed you can be looking for the closing parenthesis when on the opening one, or for the opening one when selecting the character that immediately follows it.
97 98 99 100 101 102 103 104 105 |
# File 'lib/pry-coolline/paren_match.rb', line 97 def pair_at(pos) elements.each do |el| if pair = el.pair_at(pos) return pair end end Pair.new end |