ruby-changes:20591
From: naruse <ko1@a...>
Date: Sat, 23 Jul 2011 19:03:45 +0900 (JST)
Subject: [ruby-changes:20591] naruse:r32639 (trunk): * parse.y (rb_enc_symname_type): :$a!, @a! and so on are not
naruse 2011-07-23 19:03:30 +0900 (Sat, 23 Jul 2011) New Revision: 32639 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32639 Log: * parse.y (rb_enc_symname_type): :$a!, @a! and so on are not valid symbols, so they should be inspected with quotes. Modified files: trunk/ChangeLog trunk/parse.y trunk/test/ruby/test_symbol.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 32638) +++ ChangeLog (revision 32639) @@ -1,3 +1,8 @@ +Sat Jul 23 15:37:04 2011 NARUSE, Yui <naruse@r...> + + * parse.y (rb_enc_symname_type): :$a!, @a! and so on are not + valid symbols, so they should be inspected with quotes. + Sat Jul 23 17:06:25 2011 Tanaka Akira <akr@f...> * io.c (rb_update_max_fd): validate fd. Index: parse.y =================================================================== --- parse.y (revision 32638) +++ parse.y (revision 32639) @@ -9758,10 +9758,12 @@ while (m < e && is_identchar(m, e, enc)) m += rb_enc_mbclen(m, e, enc); switch (*m) { case '!': case '?': + if (type == ID_GLOBAL || type == ID_CLASS || type == ID_INSTANCE) return -1; type = ID_JUNK; ++m; break; case '=': + if (type != ID_CONST && type != ID_LOCAL) return -1; type = ID_ATTRSET; ++m; break; Index: test/ruby/test_symbol.rb =================================================================== --- test/ruby/test_symbol.rb (revision 32638) +++ test/ruby/test_symbol.rb (revision 32639) @@ -75,6 +75,19 @@ assert_inspect_evaled(':$1') end + def test_inspect + valid = %w{$a @a @@a < << <= <=> > >> >= =~ == === * ** + +@ - -@ + | ^ & / % ~ ` [] []= ! != !~ a a? a! a= A A? A! A=} + valid.each do |sym| + assert_equal(':' + sym, sym.intern.inspect) + end + + invalid = %w{$a? $a! $a= @a? @a! @a= @@a? @@a! @@a= =} + invalid.each do |sym| + assert_equal(':"' + sym + '"', sym.intern.inspect) + end + end + def test_to_proc assert_equal %w(1 2 3), (1..3).map(&:to_s) [ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/