diff options
| author | Jemma Issroff <jemmaissroff@gmail.com> | 2023-07-07 12:54:18 -0400 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2023-07-07 17:46:46 +0000 |
| commit | 31f83a6feaeed8c82ed571d17ab33755a75cbb18 (patch) | |
| tree | 9e67e01b5a95a6e352caeb7c3654ba6ae9bc54fb /lib | |
| parent | 61efa9c823263697b1625b411fff33d8dc3cd11d (diff) | |
[ruby/yarp] Add source to ParseResult
https://github.com/ruby/yarp/commit/f3802e03e0
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/yarp.rb | 9 | ||||
| -rw-r--r-- | lib/yarp/lex_compat.rb | 2 |
2 files changed, 8 insertions, 3 deletions
diff --git a/lib/yarp.rb b/lib/yarp.rb index d74ad47db3..3ad5cc4781 100644 --- a/lib/yarp.rb +++ b/lib/yarp.rb @@ -143,13 +143,14 @@ module YARP # the AST, any comments that were encounters, and any errors that were # encountered. class ParseResult - attr_reader :value, :comments, :errors, :warnings + attr_reader :value, :comments, :errors, :warnings, :source - def initialize(value, comments, errors, warnings) + def initialize(value, comments, errors, warnings, source) @value = value @comments = comments @errors = errors @warnings = warnings + @source = source end def deconstruct_keys(keys) @@ -224,6 +225,10 @@ module YARP def self.load(source, serialized) Serialize.load(source, serialized) end + + def self.newlines(source) + YARP.parse(source).source.offsets + end end require_relative "yarp/lex_compat" diff --git a/lib/yarp/lex_compat.rb b/lib/yarp/lex_compat.rb index a455d9c6fa..053b012270 100644 --- a/lib/yarp/lex_compat.rb +++ b/lib/yarp/lex_compat.rb @@ -700,7 +700,7 @@ module YARP raise StandardError, "Lost tokens when performing lex_compat" end - ParseResult.new(tokens, result.comments, result.errors, result.warnings) + ParseResult.new(tokens, result.comments, result.errors, result.warnings, []) end end |
