@@ -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 keep_script_lines , VALUE error_tolerant );
68- static VALUE rb_ast_parse_file (VALUE path , VALUE keep_script_lines , VALUE error_tolerant );
67+ static VALUE rb_ast_parse_str (VALUE str , VALUE keep_script_lines , VALUE error_tolerant , VALUE keep_tokens );
68+ static VALUE rb_ast_parse_file (VALUE path , VALUE keep_script_lines , VALUE error_tolerant , VALUE keep_tokens );
6969
7070static VALUE
7171ast_parse_new (void )
@@ -85,32 +85,33 @@ ast_parse_done(rb_ast_t *ast)
8585}
8686
8787static VALUE
88- ast_s_parse (rb_execution_context_t * ec , VALUE module , VALUE str , VALUE keep_script_lines , VALUE error_tolerant )
88+ ast_s_parse (rb_execution_context_t * ec , VALUE module , VALUE str , VALUE keep_script_lines , VALUE error_tolerant , VALUE keep_tokens )
8989{
90- return rb_ast_parse_str (str , keep_script_lines , error_tolerant );
90+ return rb_ast_parse_str (str , keep_script_lines , error_tolerant , keep_tokens );
9191}
9292
9393static VALUE
94- rb_ast_parse_str (VALUE str , VALUE keep_script_lines , VALUE error_tolerant )
94+ rb_ast_parse_str (VALUE str , VALUE keep_script_lines , VALUE error_tolerant , VALUE keep_tokens )
9595{
9696 rb_ast_t * ast = 0 ;
9797
9898 StringValue (str );
9999 VALUE vparser = ast_parse_new ();
100100 if (RTEST (keep_script_lines )) rb_parser_keep_script_lines (vparser );
101101 if (RTEST (error_tolerant )) rb_parser_error_tolerant (vparser );
102+ if (RTEST (keep_tokens )) rb_parser_keep_tokens (vparser );
102103 ast = rb_parser_compile_string_path (vparser , Qnil , str , 1 );
103104 return ast_parse_done (ast );
104105}
105106
106107static VALUE
107- ast_s_parse_file (rb_execution_context_t * ec , VALUE module , VALUE path , VALUE keep_script_lines , VALUE error_tolerant )
108+ ast_s_parse_file (rb_execution_context_t * ec , VALUE module , VALUE path , VALUE keep_script_lines , VALUE error_tolerant , VALUE keep_tokens )
108109{
109- return rb_ast_parse_file (path , keep_script_lines , error_tolerant );
110+ return rb_ast_parse_file (path , keep_script_lines , error_tolerant , keep_tokens );
110111}
111112
112113static VALUE
113- rb_ast_parse_file (VALUE path , VALUE keep_script_lines , VALUE error_tolerant )
114+ rb_ast_parse_file (VALUE path , VALUE keep_script_lines , VALUE error_tolerant , VALUE keep_tokens )
114115{
115116 VALUE f ;
116117 rb_ast_t * ast = 0 ;
@@ -122,6 +123,7 @@ rb_ast_parse_file(VALUE path, VALUE keep_script_lines, VALUE error_tolerant)
122123 VALUE vparser = ast_parse_new ();
123124 if (RTEST (keep_script_lines )) rb_parser_keep_script_lines (vparser );
124125 if (RTEST (error_tolerant )) rb_parser_error_tolerant (vparser );
126+ if (RTEST (keep_tokens )) rb_parser_keep_tokens (vparser );
125127 ast = rb_parser_compile_file_path (vparser , Qnil , f , 1 );
126128 rb_io_close (f );
127129 return ast_parse_done (ast );
@@ -141,14 +143,15 @@ lex_array(VALUE array, int index)
141143}
142144
143145static VALUE
144- rb_ast_parse_array (VALUE array , VALUE keep_script_lines , VALUE error_tolerant )
146+ rb_ast_parse_array (VALUE array , VALUE keep_script_lines , VALUE error_tolerant , VALUE keep_tokens )
145147{
146148 rb_ast_t * ast = 0 ;
147149
148150 array = rb_check_array_type (array );
149151 VALUE vparser = ast_parse_new ();
150152 if (RTEST (keep_script_lines )) rb_parser_keep_script_lines (vparser );
151153 if (RTEST (error_tolerant )) rb_parser_error_tolerant (vparser );
154+ if (RTEST (keep_tokens )) rb_parser_keep_tokens (vparser );
152155 ast = rb_parser_compile_generic (vparser , lex_array , Qnil , array , 1 );
153156 return ast_parse_done (ast );
154157}
@@ -208,7 +211,7 @@ node_id_for_backtrace_location(rb_execution_context_t *ec, VALUE module, VALUE l
208211}
209212
210213static VALUE
211- ast_s_of (rb_execution_context_t * ec , VALUE module , VALUE body , VALUE keep_script_lines , VALUE error_tolerant )
214+ ast_s_of (rb_execution_context_t * ec , VALUE module , VALUE body , VALUE keep_script_lines , VALUE error_tolerant , VALUE keep_tokens )
212215{
213216 VALUE node , lines = Qnil ;
214217 const rb_iseq_t * iseq ;
@@ -247,13 +250,13 @@ ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE keep_script
247250 }
248251
249252 if (!NIL_P (lines ) || !NIL_P (lines = script_lines (path ))) {
250- node = rb_ast_parse_array (lines , keep_script_lines , error_tolerant );
253+ node = rb_ast_parse_array (lines , keep_script_lines , error_tolerant , keep_tokens );
251254 }
252255 else if (e_option ) {
253- node = rb_ast_parse_str (rb_e_script , keep_script_lines , error_tolerant );
256+ node = rb_ast_parse_str (rb_e_script , keep_script_lines , error_tolerant , keep_tokens );
254257 }
255258 else {
256- node = rb_ast_parse_file (path , keep_script_lines , error_tolerant );
259+ node = rb_ast_parse_file (path , keep_script_lines , error_tolerant , keep_tokens );
257260 }
258261
259262 return node_find (node , node_id );
@@ -715,6 +718,15 @@ ast_node_last_column(rb_execution_context_t *ec, VALUE self)
715718 return INT2NUM (nd_last_column (data -> node ));
716719}
717720
721+ static VALUE
722+ ast_node_all_tokens (rb_execution_context_t * ec , VALUE self )
723+ {
724+ struct ASTNodeData * data ;
725+ TypedData_Get_Struct (self , struct ASTNodeData , & rb_node_type , data );
726+
727+ return rb_ast_tokens (data -> ast );
728+ }
729+
718730static VALUE
719731ast_node_inspect (rb_execution_context_t * ec , VALUE self )
720732{
0 commit comments