summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJemma Issroff <jemmaissroff@gmail.com>2023-07-07 12:54:18 -0400
committergit <svn-admin@ruby-lang.org>2023-07-07 17:46:46 +0000
commit31f83a6feaeed8c82ed571d17ab33755a75cbb18 (patch)
tree9e67e01b5a95a6e352caeb7c3654ba6ae9bc54fb
parent61efa9c823263697b1625b411fff33d8dc3cd11d (diff)
[ruby/yarp] Add source to ParseResult
https://github.com/ruby/yarp/commit/f3802e03e0
-rw-r--r--lib/yarp.rb9
-rw-r--r--lib/yarp/lex_compat.rb2
-rw-r--r--yarp/extension.c10
3 files changed, 14 insertions, 7 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
diff --git a/yarp/extension.c b/yarp/extension.c
index f0d22c7f8c..034be79e4d 100644
--- a/yarp/extension.c
+++ b/yarp/extension.c
@@ -391,10 +391,11 @@ lex_input(input_t *input, const char *filepath) {
lex_data.tokens,
parser_comments(&parser, source),
parser_errors(&parser, lex_data.encoding, source),
- parser_warnings(&parser, lex_data.encoding, source)
+ parser_warnings(&parser, lex_data.encoding, source),
+ source
};
- VALUE result = rb_class_new_instance(4, result_argv, rb_cYARPParseResult);
+ VALUE result = rb_class_new_instance(5, result_argv, rb_cYARPParseResult);
yp_node_destroy(&parser, node);
yp_parser_free(&parser);
@@ -446,10 +447,11 @@ parse_input(input_t *input, const char *filepath) {
yp_ast_new(&parser, node, encoding),
parser_comments(&parser, source),
parser_errors(&parser, encoding, source),
- parser_warnings(&parser, encoding, source)
+ parser_warnings(&parser, encoding, source),
+ source
};
- VALUE result = rb_class_new_instance(4, result_argv, rb_cYARPParseResult);
+ VALUE result = rb_class_new_instance(5, result_argv, rb_cYARPParseResult);
yp_node_destroy(&parser, node);
yp_parser_free(&parser);