Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
More locations for the parser translation
  • Loading branch information
kddnewton committed Feb 7, 2023
commit c13bfda6d167908437f0518d0dfe1cfe14d439c5
5 changes: 3 additions & 2 deletions lib/syntax_tree/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11527,8 +11527,9 @@ def ===(other)
#
# To be clear, this method should just not exist. It's not good. It's a
# place of shame. But it's necessary for now, so I'm keeping it.
def pin(parent)
replace = PinnedVarRef.new(value: value, location: location)
def pin(parent, pin)
replace =
PinnedVarRef.new(value: value, location: pin.location.to(location))

parent
.deconstruct_keys([])
Expand Down
33 changes: 24 additions & 9 deletions lib/syntax_tree/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,7 @@ def visit(node)
end

def visit_var_ref(node)
pins.shift
node.pin(stack[-2])
node.pin(stack[-2], pins.shift)
end

def self.visit(node, tokens)
Expand Down Expand Up @@ -1683,6 +1682,22 @@ def on_float(value)
# VarField right
# ) -> FndPtn
def on_fndptn(constant, left, values, right)
# The left and right of a find pattern are always going to be splats, so
# we're going to consume the * operators and use their location
# information to extend the location of the splats.
right, left =
[right, left].map do |node|
operator = consume_operator(:*)
location =
if node.value
operator.location.to(node.location)
else
operator.location
end

node.copy(location: location)
end

# The opening of this find pattern is either going to be a left bracket, a
# right left parenthesis, or the left splat. We're going to use this to
# determine how to find the closing of the pattern, as well as determining
Expand Down Expand Up @@ -1791,7 +1806,7 @@ def on_heredoc_beg(value)
line: lineno,
char: char_pos,
column: current_column,
size: value.size + 1
size: value.size
)

# Here we're going to artificially create an extra node type so that if
Expand Down Expand Up @@ -1826,7 +1841,7 @@ def on_heredoc_end(value)
line: lineno,
char: char_pos,
column: current_column,
size: value.size + 1
size: value.size
)

heredoc_end = HeredocEnd.new(value: value.chomp, location: location)
Expand All @@ -1841,9 +1856,9 @@ def on_heredoc_end(value)
start_line: heredoc.location.start_line,
start_char: heredoc.location.start_char,
start_column: heredoc.location.start_column,
end_line: lineno,
end_char: char_pos,
end_column: current_column
end_line: location.end_line,
end_char: location.end_char,
end_column: location.end_column
)
)
end
Expand Down Expand Up @@ -2357,14 +2372,14 @@ def on_method_add_arg(call, arguments)

# :call-seq:
# on_method_add_block: (
# (Break | Call | Command | CommandCall) call,
# (Break | Call | Command | CommandCall, Next) call,
# Block block
# ) -> Break | MethodAddBlock
def on_method_add_block(call, block)
location = call.location.to(block.location)

case call
when Break
when Break, Next
parts = call.arguments.parts

node = parts.pop
Expand Down
Loading