summaryrefslogtreecommitdiff
path: root/ast.c
diff options
context:
space:
mode:
authorydah <[email protected]>2024-09-30 13:48:31 +0900
committerYudai Takada <[email protected]>2025-01-03 21:26:21 +0900
commit4b02a7b794b6c565eae0ed3c8dfedc1b8daf4e49 ()
tree938870797ef39b7562fe85d1958187042ad3a3cf /ast.c
parentb33c1e4bb2943779b9e7a8034cb6763ef9c25e67 (diff)
Change `rb_ast_compile` to a function that simply creates a parser and sets options
Notes: Merged: https://.com/ruby/ruby/pull/11717
-rw-r--r--ast.c26
1 files changed, 16 insertions, 10 deletions
@@ -116,16 +116,13 @@ ast_parse_done(VALUE ast_value)
}
static VALUE
-rb_ast_compile(VALUE keep_script_lines, VALUE error_tolerant, VALUE keep_tokens, VALUE source, VALUE compile_func(VALUE, VALUE, VALUE, int))
{
VALUE vparser = ast_parse_new();
- VALUE ast_value = Qnil;
-
if (RTEST(keep_script_lines)) rb_parser_set_script_lines(vparser);
if (RTEST(error_tolerant)) rb_parser_error_tolerant(vparser);
if (RTEST(keep_tokens)) rb_parser_keep_tokens(vparser);
- ast_value = compile_func(vparser, Qnil, source, 1);
- return ast_parse_done(ast_value);
}
static VALUE
@@ -137,8 +134,11 @@ ast_s_parse(rb_execution_context_t *ec, VALUE module, VALUE str, VALUE keep_scri
static VALUE
rb_ast_parse_str(VALUE str, VALUE keep_script_lines, VALUE error_tolerant, VALUE keep_tokens)
{
StringValue(str);
- return rb_ast_compile(keep_script_lines, error_tolerant, keep_tokens, str, rb_parser_compile_string_path);
}
static VALUE
@@ -150,21 +150,27 @@ ast_s_parse_file(rb_execution_context_t *ec, VALUE module, VALUE path, VALUE kee
static VALUE
rb_ast_parse_file(VALUE path, VALUE keep_script_lines, VALUE error_tolerant, VALUE keep_tokens)
{
VALUE ast_value = Qnil;
- VALUE f = rb_file_open_str(path, "r");
rb_encoding *enc = rb_utf8_encoding();
rb_funcall(f, rb_intern("set_encoding"), 2, rb_enc_from_encoding(enc), rb_str_new_cstr("-"));
- ast_value = rb_ast_compile(keep_script_lines, error_tolerant, keep_tokens, f, rb_parser_compile_file_path);
rb_io_close(f);
- return ast_value;
}
static VALUE
rb_ast_parse_array(VALUE array, VALUE keep_script_lines, VALUE error_tolerant, VALUE keep_tokens)
{
array = rb_check_array_type(array);
- return rb_ast_compile(keep_script_lines, error_tolerant, keep_tokens, array, rb_parser_compile_array);
}
static VALUE node_children(VALUE, const NODE*);