diff options
| -rw-r--r-- | lib/prism/parse_result.rb | 10 | ||||
| -rw-r--r-- | prism/templates/lib/prism/node.rb.erb | 9 |
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/prism/parse_result.rb b/lib/prism/parse_result.rb index e01aa070c2..ff8b1dc8bf 100644 --- a/lib/prism/parse_result.rb +++ b/lib/prism/parse_result.rb @@ -27,6 +27,11 @@ module Prism source.encoding end + # Returns the lines of the source code as an array of strings. + def lines + source.lines + end + # Perform a byteslice on the source code using the given byte offset and # byte length. def slice(byte_offset, length) @@ -177,6 +182,11 @@ module Prism "#<Prism::Location @start_offset=#{@start_offset} @length=#{@length} start_line=#{start_line}>" end + # Returns all of the lines of the source code associated with this location. + def source_lines + source.lines + end + # The source code that this location represents. def slice source.slice(start_offset, length) diff --git a/prism/templates/lib/prism/node.rb.erb b/prism/templates/lib/prism/node.rb.erb index ddbe53e594..6ffbf7b146 100644 --- a/prism/templates/lib/prism/node.rb.erb +++ b/prism/templates/lib/prism/node.rb.erb @@ -40,6 +40,15 @@ module Prism end end + # Returns all of the lines of the source code associated with this node. + def source_lines + location.source_lines + end + + # An alias for source_lines, used to mimic the API from + # RubyVM::AbstractSyntaxTree to make it easier to migrate. + alias script_lines source_lines + # Slice the location of the node from the source. def slice location.slice |
