Skip to content

Commit cad83fa

Browse files
committed
ast.c: Rename "save_script_lines" to "keep_script_lines"
... as per ko1's preference. He is preparing to extend this feature to ISeq for his new debugger. He prefers "keep" to "save" for this wording. This API is internal and not included in any released version, so I change it in advance.
1 parent 4c93c12 commit cad83fa

File tree

6 files changed

+34
-34
lines changed

6 files changed

+34
-34
lines changed

ast.c

+16-16
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ ast_new_internal(rb_ast_t *ast, const NODE *node)
6464
return obj;
6565
}
6666

67-
static VALUE rb_ast_parse_str(VALUE str, VALUE save_script_lines);
68-
static VALUE rb_ast_parse_file(VALUE path, VALUE save_script_lines);
67+
static VALUE rb_ast_parse_str(VALUE str, VALUE keep_script_lines);
68+
static VALUE rb_ast_parse_file(VALUE path, VALUE keep_script_lines);
6969

7070
static VALUE
7171
ast_parse_new(void)
@@ -85,31 +85,31 @@ ast_parse_done(rb_ast_t *ast)
8585
}
8686

8787
static VALUE
88-
ast_s_parse(rb_execution_context_t *ec, VALUE module, VALUE str, VALUE save_script_lines)
88+
ast_s_parse(rb_execution_context_t *ec, VALUE module, VALUE str, VALUE keep_script_lines)
8989
{
90-
return rb_ast_parse_str(str, save_script_lines);
90+
return rb_ast_parse_str(str, keep_script_lines);
9191
}
9292

9393
static VALUE
94-
rb_ast_parse_str(VALUE str, VALUE save_script_lines)
94+
rb_ast_parse_str(VALUE str, VALUE keep_script_lines)
9595
{
9696
rb_ast_t *ast = 0;
9797

9898
StringValue(str);
9999
VALUE vparser = ast_parse_new();
100-
if (RTEST(save_script_lines)) rb_parser_save_script_lines(vparser);
100+
if (RTEST(keep_script_lines)) rb_parser_keep_script_lines(vparser);
101101
ast = rb_parser_compile_string_path(vparser, Qnil, str, 1);
102102
return ast_parse_done(ast);
103103
}
104104

105105
static VALUE
106-
ast_s_parse_file(rb_execution_context_t *ec, VALUE module, VALUE path, VALUE save_script_lines)
106+
ast_s_parse_file(rb_execution_context_t *ec, VALUE module, VALUE path, VALUE keep_script_lines)
107107
{
108-
return rb_ast_parse_file(path, save_script_lines);
108+
return rb_ast_parse_file(path, keep_script_lines);
109109
}
110110

111111
static VALUE
112-
rb_ast_parse_file(VALUE path, VALUE save_script_lines)
112+
rb_ast_parse_file(VALUE path, VALUE keep_script_lines)
113113
{
114114
VALUE f;
115115
rb_ast_t *ast = 0;
@@ -119,7 +119,7 @@ rb_ast_parse_file(VALUE path, VALUE save_script_lines)
119119
f = rb_file_open_str(path, "r");
120120
rb_funcall(f, rb_intern("set_encoding"), 2, rb_enc_from_encoding(enc), rb_str_new_cstr("-"));
121121
VALUE vparser = ast_parse_new();
122-
if (RTEST(save_script_lines)) rb_parser_save_script_lines(vparser);
122+
if (RTEST(keep_script_lines)) rb_parser_keep_script_lines(vparser);
123123
ast = rb_parser_compile_file_path(vparser, Qnil, f, 1);
124124
rb_io_close(f);
125125
return ast_parse_done(ast);
@@ -139,13 +139,13 @@ lex_array(VALUE array, int index)
139139
}
140140

141141
static VALUE
142-
rb_ast_parse_array(VALUE array, VALUE save_script_lines)
142+
rb_ast_parse_array(VALUE array, VALUE keep_script_lines)
143143
{
144144
rb_ast_t *ast = 0;
145145

146146
array = rb_check_array_type(array);
147147
VALUE vparser = ast_parse_new();
148-
if (RTEST(save_script_lines)) rb_parser_save_script_lines(vparser);
148+
if (RTEST(keep_script_lines)) rb_parser_keep_script_lines(vparser);
149149
ast = rb_parser_compile_generic(vparser, lex_array, Qnil, array, 1);
150150
return ast_parse_done(ast);
151151
}
@@ -193,7 +193,7 @@ script_lines(VALUE path)
193193
}
194194

195195
static VALUE
196-
ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE save_script_lines)
196+
ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE keep_script_lines)
197197
{
198198
VALUE path, node, lines;
199199
int node_id;
@@ -221,13 +221,13 @@ ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE save_script
221221
}
222222

223223
if (!NIL_P(lines = script_lines(path))) {
224-
node = rb_ast_parse_array(lines, save_script_lines);
224+
node = rb_ast_parse_array(lines, keep_script_lines);
225225
}
226226
else if (RSTRING_LEN(path) == 2 && memcmp(RSTRING_PTR(path), "-e", 2) == 0) {
227-
node = rb_ast_parse_str(rb_e_script, save_script_lines);
227+
node = rb_ast_parse_str(rb_e_script, keep_script_lines);
228228
}
229229
else {
230-
node = rb_ast_parse_file(path, save_script_lines);
230+
node = rb_ast_parse_file(path, keep_script_lines);
231231
}
232232

233233
return node_find(node, node_id);

ast.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ module RubyVM::AbstractSyntaxTree
2929
#
3030
# RubyVM::AbstractSyntaxTree.parse("x = 1 + 2")
3131
# # => #<RubyVM::AbstractSyntaxTree::Node:SCOPE@1:0-1:9>
32-
def self.parse string, save_script_lines: false
33-
Primitive.ast_s_parse string, save_script_lines
32+
def self.parse string, keep_script_lines: false
33+
Primitive.ast_s_parse string, keep_script_lines
3434
end
3535

3636
# call-seq:
@@ -44,8 +44,8 @@ def self.parse string, save_script_lines: false
4444
#
4545
# RubyVM::AbstractSyntaxTree.parse_file("my-app/app.rb")
4646
# # => #<RubyVM::AbstractSyntaxTree::Node:SCOPE@1:0-31:3>
47-
def self.parse_file pathname, save_script_lines: false
48-
Primitive.ast_s_parse_file pathname, save_script_lines
47+
def self.parse_file pathname, keep_script_lines: false
48+
Primitive.ast_s_parse_file pathname, keep_script_lines
4949
end
5050

5151
# call-seq:
@@ -63,8 +63,8 @@ def self.parse_file pathname, save_script_lines: false
6363
#
6464
# RubyVM::AbstractSyntaxTree.of(method(:hello))
6565
# # => #<RubyVM::AbstractSyntaxTree::Node:SCOPE@1:0-3:3>
66-
def self.of body, save_script_lines: false
67-
Primitive.ast_s_of body, save_script_lines
66+
def self.of body, keep_script_lines: false
67+
Primitive.ast_s_of body, keep_script_lines
6868
end
6969

7070
# RubyVM::AbstractSyntaxTree::Node instances are created by parse methods in

internal/parse.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct rb_iseq_struct; /* in vm_core.h */
1515
/* parse.y */
1616
VALUE rb_parser_set_yydebug(VALUE, VALUE);
1717
void *rb_parser_load_file(VALUE parser, VALUE name);
18-
void rb_parser_save_script_lines(VALUE vparser);
18+
void rb_parser_keep_script_lines(VALUE vparser);
1919

2020
RUBY_SYMBOL_EXPORT_BEGIN
2121
VALUE rb_parser_set_context(VALUE, const struct rb_iseq_struct *, int);

lib/error_highlight/core_ext.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def to_s
1616

1717
loc = locs.first
1818
begin
19-
node = RubyVM::AbstractSyntaxTree.of(loc, save_script_lines: true)
19+
node = RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true)
2020
opts = {}
2121

2222
case self

parse.y

+4-4
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ struct parser_params {
337337
unsigned int do_loop: 1;
338338
unsigned int do_chomp: 1;
339339
unsigned int do_split: 1;
340-
unsigned int save_script_lines: 1;
340+
unsigned int keep_script_lines: 1;
341341

342342
NODE *eval_tree_begin;
343343
NODE *eval_tree;
@@ -6251,7 +6251,7 @@ yycompile0(VALUE arg)
62516251
cov = Qtrue;
62526252
}
62536253
}
6254-
if (p->save_script_lines) {
6254+
if (p->keep_script_lines) {
62556255
if (!p->debug_lines) {
62566256
p->debug_lines = rb_ary_new();
62576257
}
@@ -13197,12 +13197,12 @@ rb_parser_set_context(VALUE vparser, const struct rb_iseq_struct *base, int main
1319713197
}
1319813198

1319913199
void
13200-
rb_parser_save_script_lines(VALUE vparser)
13200+
rb_parser_keep_script_lines(VALUE vparser)
1320113201
{
1320213202
struct parser_params *p;
1320313203

1320413204
TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, p);
13205-
p->save_script_lines = 1;
13205+
p->keep_script_lines = 1;
1320613206
}
1320713207
#endif
1320813208

test/ruby/test_ast.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,8 @@ def test_args
393393
assert_equal(:a, args.children[rest])
394394
end
395395

396-
def test_save_script_lines_for_parse
397-
node = RubyVM::AbstractSyntaxTree.parse(<<~END, save_script_lines: true)
396+
def test_keep_script_lines_for_parse
397+
node = RubyVM::AbstractSyntaxTree.parse(<<~END, keep_script_lines: true)
398398
1.times do
399399
2.times do
400400
end
@@ -432,14 +432,14 @@ def test_save_script_lines_for_parse
432432
assert_equal(expected, node.children.last.children.last.children.last.source)
433433
end
434434

435-
def test_save_script_lines_for_of
435+
def test_keep_script_lines_for_of
436436
proc = Proc.new { 1 + 2 }
437437
method = self.method(__method__)
438438

439-
node_proc = RubyVM::AbstractSyntaxTree.of(proc, save_script_lines: true)
440-
node_method = RubyVM::AbstractSyntaxTree.of(method, save_script_lines: true)
439+
node_proc = RubyVM::AbstractSyntaxTree.of(proc, keep_script_lines: true)
440+
node_method = RubyVM::AbstractSyntaxTree.of(method, keep_script_lines: true)
441441

442442
assert_equal("{ 1 + 2 }", node_proc.source)
443-
assert_equal("def test_save_script_lines_for_of\n", node_method.source.lines.first)
443+
assert_equal("def test_keep_script_lines_for_of\n", node_method.source.lines.first)
444444
end
445445
end

0 commit comments

Comments
 (0)