Class: Ibex::Runtime::CST::Cursor
- Inherits:
-
Object
- Object
- Ibex::Runtime::CST::Cursor
- Defined in:
- lib/ibex/runtime/cst/cursor.rb,
sig/ibex/runtime/cst/cursor.rbs
Overview
Allocation-light cursor over Green elements and absolute offsets. rubocop:disable Naming/PredicateMethod -- cursor movement names follow the public tree-cursor convention.
Instance Attribute Summary collapse
- #green ⇒ green readonly
- #offset ⇒ Integer readonly
Instance Method Summary collapse
- #goto_first_child ⇒ Boolean
- #goto_next_sibling ⇒ Boolean
- #goto_parent ⇒ Boolean
-
#initialize(node) ⇒ Cursor
constructor
A new instance of Cursor.
- #kind ⇒ Integer
Constructor Details
#initialize(node) ⇒ Cursor
Returns a new instance of Cursor.
19 20 21 22 23 |
# File 'lib/ibex/runtime/cst/cursor.rb', line 19 def initialize(node) @green = node.green @offset = node.offset @frames = [] #: Array[frame] end |
Instance Attribute Details
#green ⇒ green (readonly)
15 16 17 |
# File 'lib/ibex/runtime/cst/cursor.rb', line 15 def green @green end |
#offset ⇒ Integer (readonly)
16 17 18 |
# File 'lib/ibex/runtime/cst/cursor.rb', line 16 def offset @offset end |
Instance Method Details
#goto_first_child ⇒ Boolean
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ibex/runtime/cst/cursor.rb', line 26 def goto_first_child green = @green return false unless green.is_a?(GreenNode) return false if green.children.empty? parent = green @frames << [parent, 0, @offset] @green = parent.children.fetch(0) true end |
#goto_next_sibling ⇒ Boolean
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ibex/runtime/cst/cursor.rb', line 38 def goto_next_sibling frame = @frames.last return false unless frame parent, index, parent_offset = frame next_index = index + 1 return false if next_index >= parent.children.length frame[1] = next_index @offset = parent_offset + parent.children.first(next_index).sum(&:full_width) @green = parent.children.fetch(next_index) true end |
#goto_parent ⇒ Boolean
53 54 55 56 57 58 59 60 |
# File 'lib/ibex/runtime/cst/cursor.rb', line 53 def goto_parent frame = @frames.pop return false unless frame @green = frame.fetch(0) @offset = frame.fetch(2) true end |
#kind ⇒ Integer
63 |
# File 'lib/ibex/runtime/cst/cursor.rb', line 63 def kind = @green.kind |