Skip to content

Commit 7c0cf71

Browse files
kddnewtonmatzbot
authored andcommitted
[ruby/prism] Node#script_lines and supporting infra
ruby/prism@cb4a8ab772
1 parent 398453c commit 7c0cf71

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

lib/prism/parse_result.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ def encoding
2727
source.encoding
2828
end
2929

30+
# Returns the lines of the source code as an array of strings.
31+
def lines
32+
source.lines
33+
end
34+
3035
# Perform a byteslice on the source code using the given byte offset and
3136
# byte length.
3237
def slice(byte_offset, length)
@@ -177,6 +182,11 @@ def inspect
177182
"#<Prism::Location @start_offset=#{@start_offset} @length=#{@length} start_line=#{start_line}>"
178183
end
179184

185+
# Returns all of the lines of the source code associated with this location.
186+
def source_lines
187+
source.lines
188+
end
189+
180190
# The source code that this location represents.
181191
def slice
182192
source.slice(start_offset, length)

prism/templates/lib/prism/node.rb.erb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ module Prism
4040
end
4141
end
4242

43+
# Returns all of the lines of the source code associated with this node.
44+
def source_lines
45+
location.source_lines
46+
end
47+
48+
# An alias for source_lines, used to mimic the API from
49+
# RubyVM::AbstractSyntaxTree to make it easier to migrate.
50+
alias script_lines source_lines
51+
4352
# Slice the location of the node from the source.
4453
def slice
4554
location.slice

0 commit comments

Comments
 (0)