|
2 | 2 |
|
3 | 3 | #include "internal/ruby_parser.h"
|
4 | 4 |
|
| 5 | +#include "node.h" |
5 | 6 | #include "rubyparser.h"
|
6 | 7 | #include "internal/error.h"
|
7 | 8 |
|
|
26 | 27 | #include "ruby/ractor.h"
|
27 | 28 | #include "ruby/ruby.h"
|
28 | 29 | #include "ruby/util.h"
|
29 |
| -#include "node.h" |
30 | 30 | #include "internal.h"
|
31 | 31 | #include "vm_core.h"
|
32 | 32 | #include "symbol.h"
|
@@ -522,8 +522,6 @@ static const rb_parser_config_t rb_global_parser_config = {
|
522 | 522 | .ary_unshift = rb_ary_unshift,
|
523 | 523 | .ary_new2 = rb_ary_new2,
|
524 | 524 | .ary_entry = rb_ary_entry,
|
525 |
| - .ary_join = rb_ary_join, |
526 |
| - .ary_reverse = rb_ary_reverse, |
527 | 525 | .ary_clear = rb_ary_clear,
|
528 | 526 | .ary_modify = rb_ary_modify,
|
529 | 527 | .array_len = rb_array_len,
|
@@ -1014,3 +1012,34 @@ rb_node_encoding_val(const NODE *node)
|
1014 | 1012 | {
|
1015 | 1013 | return rb_enc_from_encoding(RNODE_ENCODING(node)->enc);
|
1016 | 1014 | }
|
| 1015 | + |
| 1016 | +VALUE |
| 1017 | +rb_node_const_decl_val(const NODE *node) |
| 1018 | +{ |
| 1019 | + VALUE path; |
| 1020 | + if (RNODE_CDECL(node)->nd_vid) { |
| 1021 | + path = rb_id2str(RNODE_CDECL(node)->nd_vid); |
| 1022 | + } |
| 1023 | + else { |
| 1024 | + NODE *n = RNODE_CDECL(node)->nd_else; |
| 1025 | + path = rb_ary_new(); |
| 1026 | + for (; n && nd_type_p(n, NODE_COLON2); n = RNODE_COLON2(n)->nd_head) { |
| 1027 | + rb_ary_push(path, rb_id2str(RNODE_COLON2(n)->nd_mid)); |
| 1028 | + } |
| 1029 | + if (n && nd_type_p(n, NODE_CONST)) { |
| 1030 | + // Const::Name |
| 1031 | + rb_ary_push(path, rb_id2str(RNODE_CONST(n)->nd_vid)); |
| 1032 | + } |
| 1033 | + else if (n && nd_type_p(n, NODE_COLON3)) { |
| 1034 | + // ::Const::Name |
| 1035 | + rb_ary_push(path, rb_str_new(0, 0)); |
| 1036 | + } |
| 1037 | + else { |
| 1038 | + // expression::Name |
| 1039 | + rb_ary_push(path, rb_str_new_cstr("...")); |
| 1040 | + } |
| 1041 | + path = rb_ary_join(rb_ary_reverse(path), rb_str_new_cstr("::")); |
| 1042 | + path = rb_fstring(path); |
| 1043 | + } |
| 1044 | + return path; |
| 1045 | +} |
0 commit comments