mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parse.y: show invalid global variable line
* parse.y (parse_gvar): show the source line erred by invalid global variable, and indicate the variable including the wrong punctuation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67251 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ccc933d4a6
commit
9c077bbed9
2 changed files with 9 additions and 3 deletions
4
parse.y
4
parse.y
|
@ -7480,9 +7480,11 @@ parse_numvar(struct parser_params *p)
|
||||||
static enum yytokentype
|
static enum yytokentype
|
||||||
parse_gvar(struct parser_params *p, const enum lex_state_e last_state)
|
parse_gvar(struct parser_params *p, const enum lex_state_e last_state)
|
||||||
{
|
{
|
||||||
|
const char *ptr = p->lex.pcur;
|
||||||
register int c;
|
register int c;
|
||||||
|
|
||||||
SET_LEX_STATE(EXPR_END);
|
SET_LEX_STATE(EXPR_END);
|
||||||
|
p->lex.ptok = ptr - 1; /* from '$' */
|
||||||
newtok(p);
|
newtok(p);
|
||||||
c = nextc(p);
|
c = nextc(p);
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
@ -7560,6 +7562,7 @@ parse_gvar(struct parser_params *p, const enum lex_state_e last_state)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (!parser_is_identchar(p)) {
|
if (!parser_is_identchar(p)) {
|
||||||
|
YYLTYPE loc = RUBY_INIT_YYLLOC();
|
||||||
if (c == -1 || ISSPACE(c)) {
|
if (c == -1 || ISSPACE(c)) {
|
||||||
compile_error(p, "`$' without identifiers is not allowed as a global variable name");
|
compile_error(p, "`$' without identifiers is not allowed as a global variable name");
|
||||||
}
|
}
|
||||||
|
@ -7567,6 +7570,7 @@ parse_gvar(struct parser_params *p, const enum lex_state_e last_state)
|
||||||
pushback(p, c);
|
pushback(p, c);
|
||||||
compile_error(p, "`$%c' is not allowed as a global variable name", c);
|
compile_error(p, "`$%c' is not allowed as a global variable name", c);
|
||||||
}
|
}
|
||||||
|
parser_show_error_line(p, &loc);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case '0':
|
case '0':
|
||||||
|
|
|
@ -377,9 +377,9 @@ class TestParse < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_disallowed_variable(type, noname, *invalid)
|
def assert_disallowed_variable(type, noname, *invalid)
|
||||||
assert_syntax_error(noname, "`#{noname}' without identifiers is not allowed as #{type} variable name")
|
assert_syntax_error("a = #{noname}", "`#{noname}' without identifiers is not allowed as #{type} variable name")
|
||||||
invalid.each do |name|
|
invalid.each do |name|
|
||||||
assert_syntax_error(name, "`#{name}' is not allowed as #{type} variable name")
|
assert_syntax_error("a = #{name}", "`#{name}' is not allowed as #{type} variable name")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -712,7 +712,9 @@ x = __ENCODING__
|
||||||
$test_parse_foobarbazqux = nil
|
$test_parse_foobarbazqux = nil
|
||||||
assert_equal(nil, $&)
|
assert_equal(nil, $&)
|
||||||
assert_equal(nil, eval('alias $& $preserve_last_match'))
|
assert_equal(nil, eval('alias $& $preserve_last_match'))
|
||||||
assert_raise(SyntaxError) { eval('$#') }
|
assert_raise_with_message(SyntaxError, /as a global variable name\na = \$\#\n \^~$/) do
|
||||||
|
eval('a = $#')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_invalid_instance_variable
|
def test_invalid_instance_variable
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue