class SyntaxTree::Parser::PinVisitor
Ugh… I really do not like this class. Basically, ripper doesn’t provide enough information about where pins are located in the tree. It only gives events for ^ ops and var_ref nodes. You have to piece it together yourself.
Note that there are edge cases here that we straight up do not address, because I honestly think it’s going to be faster to write a new parser than to address them. For
example, this will not work properly:
foo in ^((bar = 0; bar; baz))
If someone actually does something like that, we’ll have to find another way to make this work.
Attributes
Public Class Methods
Source
# File lib/syntax_tree/parser.rb, line 659 def initialize(pins) @pins = pins @stack = [] end
Source
# File lib/syntax_tree/parser.rb, line 681 def self.visit(node, tokens) start_char = node.start_char allocated = [] tokens.reverse_each do |token| char = token.location.start_char break if char <= start_char if token.is_a?(Op) && token.value == "^" allocated.unshift(tokens.delete(token)) end end new(allocated).visit(node) if allocated.any? end
Public Instance Methods
Source
# File lib/syntax_tree/parser.rb, line 664 def visit(node) return if pins.empty? stack << node super stack.pop end
Calls superclass method
Source
# File lib/syntax_tree/parser.rb, line 672 def visit_var_ref(node) if node.start_char > pins.first.start_char node.pin(stack[-2], pins.shift) else super end end
Calls superclass method