ruby-changes:30278
From: nobu <ko1@a...>
Date: Fri, 2 Aug 2013 23:13:31 +0900 (JST)
Subject: [ruby-changes:30278] nobu:r42330 (trunk): eventids2.c: new literals
nobu 2013-08-02 23:13:20 +0900 (Fri, 02 Aug 2013) New Revision: 42330 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42330 Log: eventids2.c: new literals * ext/ripper/eventids2.c (ripper_init_eventids2): ripper support for new literals, tRATIONAL and tIMAGINARY. Modified files: trunk/ChangeLog trunk/ext/ripper/eventids2.c trunk/test/ripper/test_scanner_events.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 42329) +++ ChangeLog (revision 42330) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Aug 2 23:13:18 2013 Nobuyoshi Nakada <nobu@r...> + + * ext/ripper/eventids2.c (ripper_init_eventids2): ripper support for + new literals, tRATIONAL and tIMAGINARY. + Fri Aug 2 18:33:28 2013 Tanaka Akira <akr@f...> * bignum.c (big2str_karatsuba): Reduce power_level more than one at Index: ext/ripper/eventids2.c =================================================================== --- ext/ripper/eventids2.c (revision 42329) +++ ext/ripper/eventids2.c (revision 42330) @@ -19,6 +19,7 @@ static ID ripper_id_embvar; https://github.com/ruby/ruby/blob/trunk/ext/ripper/eventids2.c#L19 static ID ripper_id_float; static ID ripper_id_gvar; static ID ripper_id_ident; +static ID ripper_id_imaginary; static ID ripper_id_int; static ID ripper_id_ivar; static ID ripper_id_kw; @@ -41,6 +42,7 @@ static ID ripper_id_qwords_beg; https://github.com/ruby/ruby/blob/trunk/ext/ripper/eventids2.c#L42 static ID ripper_id_qsymbols_beg; static ID ripper_id_symbols_beg; static ID ripper_id_words_sep; +static ID ripper_id_rational; static ID ripper_id_regexp_beg; static ID ripper_id_regexp_end; static ID ripper_id_label; @@ -74,6 +76,7 @@ ripper_init_eventids2(void) https://github.com/ruby/ruby/blob/trunk/ext/ripper/eventids2.c#L76 ripper_id_float = rb_intern_const("on_float"); ripper_id_gvar = rb_intern_const("on_gvar"); ripper_id_ident = rb_intern_const("on_ident"); + ripper_id_imaginary = rb_intern_const("on_imaginary"); ripper_id_int = rb_intern_const("on_int"); ripper_id_ivar = rb_intern_const("on_ivar"); ripper_id_kw = rb_intern_const("on_kw"); @@ -96,6 +99,7 @@ ripper_init_eventids2(void) https://github.com/ruby/ruby/blob/trunk/ext/ripper/eventids2.c#L99 ripper_id_qsymbols_beg = rb_intern_const("on_qsymbols_beg"); ripper_id_symbols_beg = rb_intern_const("on_symbols_beg"); ripper_id_words_sep = rb_intern_const("on_words_sep"); + ripper_id_rational = rb_intern_const("on_rational"); ripper_id_regexp_beg = rb_intern_const("on_regexp_beg"); ripper_id_regexp_end = rb_intern_const("on_regexp_end"); ripper_id_label = rb_intern_const("on_label"); @@ -209,6 +213,7 @@ static const struct token_assoc { https://github.com/ruby/ruby/blob/trunk/ext/ripper/eventids2.c#L213 {tGEQ, &ripper_id_op}, {tGVAR, &ripper_id_gvar}, {tIDENTIFIER, &ripper_id_ident}, + {tIMAGINARY, &ripper_id_imaginary}, {tINTEGER, &ripper_id_int}, {tIVAR, &ripper_id_ivar}, {tLBRACE, &ripper_id_lbrace}, @@ -234,6 +239,7 @@ static const struct token_assoc { https://github.com/ruby/ruby/blob/trunk/ext/ripper/eventids2.c#L239 {tQWORDS_BEG, &ripper_id_qwords_beg}, {tQSYMBOLS_BEG, &ripper_id_qsymbols_beg}, {tSYMBOLS_BEG, &ripper_id_symbols_beg}, + {tRATIONAL, &ripper_id_rational}, {tREGEXP_BEG, &ripper_id_regexp_beg}, {tREGEXP_END, &ripper_id_regexp_end}, {tRPAREN, &ripper_id_rparen}, Index: test/ripper/test_scanner_events.rb =================================================================== --- test/ripper/test_scanner_events.rb (revision 42329) +++ test/ripper/test_scanner_events.rb (revision 42330) @@ -87,6 +87,17 @@ class TestRipper::ScannerEvents < Test:: https://github.com/ruby/ruby/blob/trunk/test/ripper/test_scanner_events.rb#L87 [[1, 1], :on_tstring_content, "\u3042\n\u3044"], [[2, 3], :on_tstring_end, "'"]], Ripper.lex("'\u3042\n\u3044'") + assert_equal [[[1, 0], :on_rational, "1r"], + [[1, 2], :on_nl, "\n"], + [[2, 0], :on_imaginary, "2i"], + [[2, 2], :on_nl, "\n"], + [[3, 0], :on_imaginary, "3ri"], + [[3, 3], :on_nl, "\n"], + [[4, 0], :on_rational, "4.2r"], + [[4, 4], :on_nl, "\n"], + [[5, 0], :on_imaginary, "5.6ri"], + ], + Ripper.lex("1r\n2i\n3ri\n4.2r\n5.6ri") end def test_location @@ -264,6 +275,13 @@ class TestRipper::ScannerEvents < Test:: https://github.com/ruby/ruby/blob/trunk/test/ripper/test_scanner_events.rb#L275 scan('float', 'm(a,b,1.0,c,d)') end + def test_rational + assert_equal [], + scan('rational', '') + assert_equal ['1r', '10r', '10.1r'], + scan('rational', 'm(1r,10r,10.1r)') + end + def test_gvar assert_equal [], scan('gvar', '') @@ -286,6 +304,13 @@ class TestRipper::ScannerEvents < Test:: https://github.com/ruby/ruby/blob/trunk/test/ripper/test_scanner_events.rb#L304 scan('ident', 'm(lvar, @ivar, @@cvar, $gvar)') end + def test_imaginary + assert_equal [], + scan('imaginary', '') + assert_equal ['1i', '10ri', '10.0i', '10.1ri'], + scan('imaginary', 'm(1i,10ri,10.0i,10.1ri)') + end + def test_int assert_equal [], scan('int', '') -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/