ruby-changes:38399
From: nobu <ko1@a...>
Date: Wed, 13 May 2015 11:13:52 +0900 (JST)
Subject: [ruby-changes:38399] nobu:r50480 (trunk): parse.y: refine message for gvar w/o identitirs
nobu 2015-05-13 11:13:43 +0900 (Wed, 13 May 2015) New Revision: 50480 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50480 Log: parse.y: refine message for gvar w/o identitirs * parse.y (parse_gvar): separate message for gvar without non-space characters from message for invalid identitirs. Modified files: trunk/ChangeLog trunk/parse.y trunk/test/ripper/test_parser_events.rb trunk/test/ruby/test_parse.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 50479) +++ ChangeLog (revision 50480) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed May 13 11:13:40 2015 Nobuyoshi Nakada <nobu@r...> + + * parse.y (parse_gvar): separate message for gvar without + non-space characters from message for invalid identitirs. + Tue May 12 22:18:27 2015 Masaki Matsushita <glass.saga@g...> * enum.c (enum_to_a): fix incompatibility introduced in r50457. Index: parse.y =================================================================== --- parse.y (revision 50479) +++ parse.y (revision 50480) @@ -7675,8 +7675,13 @@ parse_gvar(struct parser_params *parser, https://github.com/ruby/ruby/blob/trunk/parse.y#L7675 default: if (!parser_is_identchar()) { - pushback(c); - compile_error(PARSER_ARG "`$%c' is not allowed as a global variable name", c); + if (c == -1 || ISSPACE(c)) { + compile_error(PARSER_ARG "`$' without identifiers is not allowed as a global variable name"); + } + else { + pushback(c); + compile_error(PARSER_ARG "`$%c' is not allowed as a global variable name", c); + } return 0; } case '0': Index: test/ruby/test_parse.rb =================================================================== --- test/ruby/test_parse.rb (revision 50479) +++ test/ruby/test_parse.rb (revision 50480) @@ -375,6 +375,25 @@ class TestParse < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L375 assert_nothing_raised { eval(':""') } end + def assert_disallowed_variable(type, noname, *invalid) + assert_syntax_error(noname, "`#{noname}' without identifiers is not allowed as #{type} variable name") + invalid.each do |name| + assert_syntax_error(name, "`#{name}' is not allowed as #{type} variable name") + end + end + + def test_disallowed_instance_variable + assert_disallowed_variable("an instance", *%w[@ @1 @.]) + end + + def test_disallowed_class_variable + assert_disallowed_variable("a class", *%w[@@ @@1 @@.]) + end + + def test_disallowed_gloal_variable + assert_disallowed_variable("a global", *%w[$ $%]) + end + def test_arg2 o = Object.new Index: test/ripper/test_parser_events.rb =================================================================== --- test/ripper/test_parser_events.rb (revision 50479) +++ test/ripper/test_parser_events.rb (revision 50480) @@ -1219,14 +1219,17 @@ class TestRipper::ParserEvents < Test::U https://github.com/ruby/ruby/blob/trunk/test/ripper/test_parser_events.rb#L1219 def test_invalid_instance_variable_name assert_equal("`@1' is not allowed as an instance variable name", compile_error('@1')) assert_equal("`@%' is not allowed as an instance variable name", compile_error('@%')) + assert_equal("`@' without identifiers is not allowed as an instance variable name", compile_error('@')) end def test_invalid_class_variable_name assert_equal("`@@1' is not allowed as a class variable name", compile_error('@@1')) assert_equal("`@@%' is not allowed as a class variable name", compile_error('@@%')) + assert_equal("`@@' without identifiers is not allowed as a class variable name", compile_error('@@')) end def test_invalid_global_variable_name assert_equal("`$%' is not allowed as a global variable name", compile_error('$%')) + assert_equal("`$' without identifiers is not allowed as a global variable name", compile_error('$')) end end if ripper_test -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/