Module: Hashira::Analysis::Syntax
- Defined in:
- lib/hashira/analysis/syntax.rb
Class Method Summary collapse
- .anchor(stack, segments, roots) ⇒ Object
- .cbase?(node) ⇒ Boolean
- .direct(type_node) ⇒ Object
- .hoist(stack, segments, roots) ⇒ Object
- .label(node) ⇒ Object
- .segments(node) ⇒ Object
Class Method Details
.anchor(stack, segments, roots) ⇒ Object
26 27 28 29 30 |
# File 'lib/hashira/analysis/syntax.rb', line 26 def anchor(stack, segments, roots) return (stack.last || []) + segments if segments.length < 2 || !roots base = stack.reverse_each.find { roots.include?(it + segments.first(1)) } base ? base + segments : hoist(stack, segments, roots) end |
.cbase?(node) ⇒ Boolean
20 21 22 23 24 |
# File 'lib/hashira/analysis/syntax.rb', line 20 def cbase?(node) return false unless node.is_a?(Prism::ConstantPathNode) parent = node.parent !parent || cbase?(parent) end |
.direct(type_node) ⇒ Object
36 37 38 39 |
# File 'lib/hashira/analysis/syntax.rb', line 36 def direct(type_node) body = type_node.body (body.is_a?(Prism::StatementsNode) ? body.body : [body]).grep(Prism::DefNode) end |
.hoist(stack, segments, roots) ⇒ Object
32 33 34 |
# File 'lib/hashira/analysis/syntax.rb', line 32 def hoist(stack, segments, roots) roots.include?(segments.first(1)) ? segments : (stack.last || []) + segments end |
.label(node) ⇒ Object
18 |
# File 'lib/hashira/analysis/syntax.rb', line 18 def label(node) = [node.name.to_s] |
.segments(node) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/hashira/analysis/syntax.rb', line 10 def segments(node) case node when Prism::ConstantReadNode then [node.name.to_s] when Prism::ConstantPathNode then segments(node.parent) + label(node) else [] end end |