aboutsummaryrefslogtreecommitdiffstats
path: root/prism/prism.c
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2023-11-29 11:46:33 +0100
committergit <svn-admin@ruby-lang.org>2023-11-29 13:56:19 +0000
commit2af82e23165180f20ca2af374aedb7a45dedcc20 (patch)
tree1bd829f6f15140c645496167a208d38736ac8d81 /prism/prism.c
parent2653404840952d25bbdd7deaf599fbfb1f5287f0 (diff)
downloadruby-2af82e23165180f20ca2af374aedb7a45dedcc20.tar.gz
[ruby/prism] Convert start line to signed integers
Ruby allows for 0 or negative line start, this is often used with `eval` calls to get a correct offset when prefixing a snippet. e.g. ```ruby caller = caller_locations(1, 1).first class_eval <<~RUBY, caller.path, caller.line - 2 # frozen_string_literal: true def some_method #{caller_provided_code_snippet} end RUBY ``` https://github.com/ruby/prism/commit/0d14ed1452
Diffstat (limited to 'prism/prism.c')
-rw-r--r--prism/prism.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/prism/prism.c b/prism/prism.c
index aee9fc7b88..1a4d31c268 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -17067,9 +17067,7 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm
parser->filepath_string = options->filepath;
// line option
- if (options->line > 0) {
- parser->start_line = options->line;
- }
+ parser->start_line = options->line;
// encoding option
size_t encoding_length = pm_string_length(&options->encoding);
@@ -17238,7 +17236,7 @@ pm_serialize(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
PRISM_EXPORTED_FUNCTION void
pm_serialize_parse(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) {
pm_options_t options = { 0 };
- if (data != NULL) pm_options_read(&options, data);
+ pm_options_read(&options, data);
pm_parser_t parser;
pm_parser_init(&parser, source, size, &options);
@@ -17260,7 +17258,7 @@ pm_serialize_parse(pm_buffer_t *buffer, const uint8_t *source, size_t size, cons
PRISM_EXPORTED_FUNCTION void
pm_serialize_parse_comments(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) {
pm_options_t options = { 0 };
- if (data != NULL) pm_options_read(&options, data);
+ pm_options_read(&options, data);
pm_parser_t parser;
pm_parser_init(&parser, source, size, &options);
@@ -17268,7 +17266,7 @@ pm_serialize_parse_comments(pm_buffer_t *buffer, const uint8_t *source, size_t s
pm_node_t *node = pm_parse(&parser);
pm_serialize_header(buffer);
pm_serialize_encoding(&parser.encoding, buffer);
- pm_buffer_append_varuint(buffer, parser.start_line);
+ pm_buffer_append_varsint(buffer, parser.start_line);
pm_serialize_comment_list(&parser, &parser.comment_list, buffer);
pm_node_destroy(&parser, node);