summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-02 14:13:20 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-02 14:13:20 +0000
commit856a9afb98b8443a8b32483a97e271560af6de1b (patch)
tree90ff80ad3c87ea3fcab24f81b5b84b6832c3e5ca
parentba95b9787d941aeda329bba6427f7533b89ad2b7 (diff)
eventids2.c: new literals
* ext/ripper/eventids2.c (ripper_init_eventids2): ripper support for new literals, tRATIONAL and tIMAGINARY. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42330 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/ripper/eventids2.c6
-rw-r--r--test/ripper/test_scanner_events.rb25
3 files changed, 36 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index ca31d14..7bb05e2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Aug 2 23:13:18 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@fsij.org>
* bignum.c (big2str_karatsuba): Reduce power_level more than one at
diff --git a/ext/ripper/eventids2.c b/ext/ripper/eventids2.c
index 841a18c..423f9d7 100644
--- a/ext/ripper/eventids2.c
+++ b/ext/ripper/eventids2.c
@@ -19,6 +19,7 @@ static ID ripper_id_embvar;
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;
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)
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)
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 {
{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 {
{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},
diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb
index a96edef..2474588 100644
--- a/test/ripper/test_scanner_events.rb
+++ b/test/ripper/test_scanner_events.rb
@@ -87,6 +87,17 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
[[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::Unit::TestCase
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::Unit::TestCase
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', '')