diff --git a/bootstraptest/test_class.rb b/bootstraptest/test_class.rb index b7fe0a1..a290fb4 100644 --- a/bootstraptest/test_class.rb +++ b/bootstraptest/test_class.rb @@ -109,7 +109,7 @@ assert_equal '1', %q( C = 1 # [yarv-dev:782] assert_equal '1', %q( C = 1 # [yarv-dev:800] begin module C; end; rescue TypeError; 1 end ) -# colon2, colon3 +# colon2, colon2_head assert_equal '1', %q( class A; end; A::C = 1; A::C ) assert_equal '1', %q( A = 7; begin A::C = 7; rescue TypeError; 1 end ) assert_equal '1', %q( begin 7::C = 7; rescue TypeError; 1 end ) diff --git a/compile.c b/compile.c index 8df7acf..08b4e21 100644 --- a/compile.c +++ b/compile.c @@ -2669,8 +2669,8 @@ compile_colon2(rb_iseq_t *iseq, NODE * node, debugi("compile_colon2 - colon", node->nd_vid); ADD_INSN1(body, nd_line(node), getconstant, ID2SYM(node->nd_vid)); break; - case NODE_COLON3: - debugi("compile_colon2 - colon3", node->nd_mid); + case NODE_COLON2_HEAD: + debugi("compile_colon2 - colon2_head", node->nd_mid); ADD_INSN(body, nd_line(node), pop); ADD_INSN1(body, nd_line(node), putobject, rb_cObject); ADD_INSN1(body, nd_line(node), getconstant, ID2SYM(node->nd_mid)); @@ -2690,7 +2690,7 @@ compile_colon2(rb_iseq_t *iseq, NODE * node, static VALUE compile_cpath(LINK_ANCHOR *ret, rb_iseq_t *iseq, NODE *cpath) { - if (nd_type(cpath) == NODE_COLON3) { + if (nd_type(cpath) == NODE_COLON2_HEAD) { /* toplevel class ::Foo */ ADD_INSN1(ret, nd_line(cpath), putobject, rb_cObject); return Qfalse; @@ -2802,7 +2802,7 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *ret, ID2SYM(node->nd_mid), needstr); } return 1; - case NODE_COLON3: + case NODE_COLON2_HEAD: ADD_INSN1(ret, nd_line(node), putobject, rb_cObject); ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_CONST), ID2SYM(node->nd_mid), needstr); @@ -4134,7 +4134,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) ID mid; switch (nd_type(node->nd_head)) { - case NODE_COLON3: + case NODE_COLON2_HEAD: ADD_INSN1(ret, line, putobject, rb_cObject); break; case NODE_COLON2: @@ -5020,11 +5020,11 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) } break; } - case NODE_COLON3:{ + case NODE_COLON2_HEAD:{ LABEL *lend = NEW_LABEL(line); int ic_index = iseq->is_size++; - debugi("colon3#nd_mid", node->nd_mid); + debugi("colon2_head#nd_mid", node->nd_mid); /* add cache insn */ if (iseq->compile_data->option->inline_const_cache) { diff --git a/ext/objspace/objspace.c b/ext/objspace/objspace.c index 88ebfca..c725d9e 100644 --- a/ext/objspace/objspace.c +++ b/ext/objspace/objspace.c @@ -387,7 +387,7 @@ count_nodes(int argc, VALUE *argv, VALUE os) COUNT_NODE(NODE_MODULE); COUNT_NODE(NODE_SCLASS); COUNT_NODE(NODE_COLON2); - COUNT_NODE(NODE_COLON3); + COUNT_NODE(NODE_COLON2_HEAD); COUNT_NODE(NODE_CREF); COUNT_NODE(NODE_DOT2); COUNT_NODE(NODE_DOT3); diff --git a/ext/ripper/eventids2.c b/ext/ripper/eventids2.c index abbe584..0928ab0 100644 --- a/ext/ripper/eventids2.c +++ b/ext/ripper/eventids2.c @@ -212,7 +212,7 @@ static const struct token_assoc { {tCHAR, O(CHAR)}, {tCMP, O(op)}, {tCOLON2, O(op)}, - {tCOLON3, O(op)}, + {tCOLON2_HEAD, O(op)}, {tCONSTANT, O(const)}, {tCVAR, O(cvar)}, {tDOT2, O(op)}, diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index 7189307..e818fe2 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -547,7 +547,7 @@ class RubyLex |op, io| if @lex_state == EXPR_BEG or @lex_state == EXPR_ARG && @space_seen @lex_state = EXPR_BEG - Token(TkCOLON3) + Token(TkCOLON2_HEAD) else @lex_state = EXPR_DOT Token(TkCOLON2) diff --git a/lib/irb/ruby-token.rb b/lib/irb/ruby-token.rb index a80d81c..c3cd919 100644 --- a/lib/irb/ruby-token.rb +++ b/lib/irb/ruby-token.rb @@ -185,7 +185,7 @@ module RubyToken [:TkLSHFT, TkOp, "<<"], [:TkRSHFT, TkOp, ">>"], [:TkCOLON2, TkOp], - [:TkCOLON3, TkOp], + [:TkCOLON2_HEAD,TkOp], [:TkASSOC, TkOp, "=>"], [:TkQUESTION, TkOp, "?"], #? [:TkCOLON, TkOp, ":"], #: diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb index ce1083e..769fbf2 100644 --- a/lib/rdoc/parser/ruby.rb +++ b/lib/rdoc/parser/ruby.rb @@ -333,7 +333,7 @@ class RDoc::Parser::Ruby < RDoc::Parser # class ::A -> A is in the top level case name_t - when TkCOLON2, TkCOLON3 then # bug + when TkCOLON2, TkCOLON2_HEAD then # bug name_t = get_tk container = @top_level given_name << '::' @@ -404,7 +404,7 @@ class RDoc::Parser::Ruby < RDoc::Parser skip_tkspace false tk = get_tk - while TkCOLON2 === tk or TkCOLON3 === tk or TkCONSTANT === tk do + while TkCOLON2 === tk or TkCOLON2_HEAD === tk or TkCONSTANT === tk do res += tk.name tk = get_tk end @@ -933,7 +933,7 @@ class RDoc::Parser::Ruby < RDoc::Parser unget_tk tk break end - when TkCOLON2, TkCOLON3 then + when TkCOLON2, TkCOLON2_HEAD then rhs_name << '::' when nil then break diff --git a/lib/rdoc/ruby_lex.rb b/lib/rdoc/ruby_lex.rb index 91b90ab..ce9fbb2 100644 --- a/lib/rdoc/ruby_lex.rb +++ b/lib/rdoc/ruby_lex.rb @@ -633,7 +633,7 @@ class RDoc::RubyLex # p @lex_state.id2name, @space_seen if @lex_state == :EXPR_BEG or @lex_state == :EXPR_ARG && @space_seen @lex_state = :EXPR_BEG - Token(TkCOLON3) + Token(TkCOLON2_HEAD) else @lex_state = :EXPR_DOT Token(TkCOLON2) diff --git a/lib/rdoc/ruby_token.rb b/lib/rdoc/ruby_token.rb index f091e1a..3cab9bf 100644 --- a/lib/rdoc/ruby_token.rb +++ b/lib/rdoc/ruby_token.rb @@ -363,7 +363,7 @@ module RDoc::RubyToken [:TkLSHFT, TkOp, "<<"], [:TkRSHFT, TkOp, ">>"], [:TkCOLON2, TkOp, '::'], - [:TkCOLON3, TkOp, '::'], + [:TkCOLON2_HEAD,TkOp, '::'], #[:OPASGN, TkOp], # +=, -= etc. # [:TkASSOC, TkOp, "=>"], [:TkQUESTION, TkOp, "?"], #? diff --git a/node.c b/node.c index 32518d3..d080e6e 100644 --- a/node.c +++ b/node.c @@ -707,7 +707,7 @@ dump_node(VALUE buf, VALUE indent, int comment, NODE *node) F_NODE(nd_head, "receiver"); break; - case NODE_COLON3: + case NODE_COLON2_HEAD: ANN("top-level constant reference"); ANN("format: ::[nd_mid]"); ANN("example: ::Object"); @@ -1002,7 +1002,7 @@ rb_gc_mark_node(NODE *obj) case NODE_IASGN: case NODE_IASGN2: case NODE_CVASGN: - case NODE_COLON3: + case NODE_COLON2_HEAD: case NODE_OPT_N: case NODE_EVSTR: case NODE_UNDEF: diff --git a/node.h b/node.h index e376e57..c94bc05 100644 --- a/node.h +++ b/node.h @@ -190,8 +190,8 @@ enum node_type { #define NODE_SCLASS NODE_SCLASS NODE_COLON2, #define NODE_COLON2 NODE_COLON2 - NODE_COLON3, -#define NODE_COLON3 NODE_COLON3 + NODE_COLON2_HEAD, +#define NODE_COLON2_HEAD NODE_COLON2_HEAD NODE_CREF, #define NODE_CREF NODE_CREF NODE_DOT2, @@ -448,7 +448,7 @@ typedef struct RNode { #define NEW_SCLASS(r,b) NEW_NODE(NODE_SCLASS,r,NEW_SCOPE(0,b),0) #define NEW_MODULE(n,b) NEW_NODE(NODE_MODULE,n,NEW_SCOPE(0,b),0) #define NEW_COLON2(c,i) NEW_NODE(NODE_COLON2,c,i,0) -#define NEW_COLON3(i) NEW_NODE(NODE_COLON3,0,i,0) +#define NEW_COLON2_HEAD(i) NEW_NODE(NODE_COLON2_HEAD,0,i,0) #define NEW_CREF(a) NEW_NODE(NODE_CREF,a,0,0) #define NEW_DOT2(b,e) NEW_NODE(NODE_DOT2,b,e,0) #define NEW_DOT3(b,e) NEW_NODE(NODE_DOT3,b,e,0) diff --git a/parse.y b/parse.y index 18c08db..49b9d45 100644 --- a/parse.y +++ b/parse.y @@ -816,7 +816,7 @@ static void token_info_pop(struct parser_params*, const char *token); %token tLSHFT RUBY_TOKEN(LSHFT) "<<" %token tRSHFT RUBY_TOKEN(RSHFT) ">>" %token tCOLON2 "::" -%token tCOLON3 ":: at EXPR_BEG" +%token tCOLON2_HEAD ":: at EXPR_BEG" %token tOP_ASGN /* +=, -= etc. */ %token tASSOC "=>" %token tLPAREN "(" @@ -1697,12 +1697,12 @@ mlhs_node : user_variable } %*/ } - | tCOLON3 tCONSTANT + | tCOLON2_HEAD tCONSTANT { /*%%%*/ if (in_def || in_single) yyerror("dynamic constant assignment"); - $$ = NEW_CDECL(0, 0, NEW_COLON3($2)); + $$ = NEW_CDECL(0, 0, NEW_COLON2_HEAD($2)); /*% $$ = dispatch1(top_const_field, $2); if (in_def || in_single) { @@ -1788,12 +1788,12 @@ lhs : user_variable } %*/ } - | tCOLON3 tCONSTANT + | tCOLON2_HEAD tCONSTANT { /*%%%*/ if (in_def || in_single) yyerror("dynamic constant assignment"); - $$ = NEW_CDECL(0, 0, NEW_COLON3($2)); + $$ = NEW_CDECL(0, 0, NEW_COLON2_HEAD($2)); /*% $$ = dispatch1(top_const_field, $2); if (in_def || in_single) { @@ -1826,10 +1826,10 @@ cname : tIDENTIFIER | tCONSTANT ; -cpath : tCOLON3 cname +cpath : tCOLON2_HEAD cname { /*%%%*/ - $$ = NEW_COLON3($2); + $$ = NEW_COLON2_HEAD($2); /*% $$ = dispatch1(top_const_ref, $2); %*/ @@ -2035,10 +2035,10 @@ arg : lhs '=' arg $$ = dispatch3(opassign, $$, $4, $5); %*/ } - | tCOLON3 tCONSTANT tOP_ASGN arg + | tCOLON2_HEAD tCONSTANT tOP_ASGN arg { /*%%%*/ - $$ = NEW_COLON3($2); + $$ = NEW_COLON2_HEAD($2); $$ = new_const_op_assign($$, $3, $4); /*% $$ = dispatch1(top_const_field, $2); @@ -2671,10 +2671,10 @@ primary : literal $$ = dispatch2(const_path_ref, $1, $3); %*/ } - | tCOLON3 tCONSTANT + | tCOLON2_HEAD tCONSTANT { /*%%%*/ - $$ = NEW_COLON3($2); + $$ = NEW_COLON2_HEAD($2); /*% $$ = dispatch1(top_const_ref, $2); %*/ @@ -8189,7 +8189,7 @@ parser_yylex(struct parser_params *parser) if (c == ':') { if (IS_BEG() || IS_lex_state(EXPR_CLASS) || IS_SPCARG(-1)) { lex_state = EXPR_BEG; - return tCOLON3; + return tCOLON2_HEAD; } lex_state = EXPR_DOT; return tCOLON2; @@ -9174,7 +9174,7 @@ void_expr_gen(struct parser_params *parser, NODE *node) useless = "a literal"; break; case NODE_COLON2: - case NODE_COLON3: + case NODE_COLON2_HEAD: useless = "::"; break; case NODE_DOT2: diff --git a/template/id.h.tmpl b/template/id.h.tmpl index 92dbc47..0ac0469 100644 --- a/template/id.h.tmpl +++ b/template/id.h.tmpl @@ -18,7 +18,7 @@ op_id_offset = 128 token_op_ids = %w[ tDOT2 tDOT3 tUPLUS tUMINUS tPOW tDSTAR tCMP tLSHFT tRSHFT tLEQ tGEQ tEQ tEQQ tNEQ tMATCH tNMATCH tAREF tASET - tCOLON2 tCOLON3 tANDOP tOROP + tCOLON2 tCOLON2_HEAD tANDOP tOROP ] defs = File.join(File.dirname(File.dirname(erb.filename)), "defs/id.def") diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb index 8750433..5fd8030 100644 --- a/test/rdoc/test_rdoc_parser_ruby.rb +++ b/test/rdoc/test_rdoc_parser_ruby.rb @@ -869,7 +869,7 @@ end assert_empty foo.comment end - def test_parse_class_colon3 + def test_parse_class_colon2_head code = <<-CODE class A class ::B @@ -884,7 +884,7 @@ end assert_equal %w[A B], @store.all_classes.map { |c| c.full_name }.sort end - def test_parse_class_colon3_self_reference + def test_parse_class_colon2_head_self_reference code = <<-CODE class A::B class ::A