mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parse.y: %-string cannot be a label
* parse.y (parser_yylex): %-string cannot be a label even if terminated by single/double quotes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50409 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7132479960
commit
4d12807e30
2 changed files with 13 additions and 3 deletions
7
parse.y
7
parse.y
|
@ -5686,6 +5686,7 @@ rb_parser_compile_file_path(volatile VALUE vparser, VALUE fname, VALUE file, int
|
||||||
#define STR_FUNC_QWORDS 0x08
|
#define STR_FUNC_QWORDS 0x08
|
||||||
#define STR_FUNC_SYMBOL 0x10
|
#define STR_FUNC_SYMBOL 0x10
|
||||||
#define STR_FUNC_INDENT 0x20
|
#define STR_FUNC_INDENT 0x20
|
||||||
|
#define STR_FUNC_LABEL 0x40
|
||||||
|
|
||||||
enum string_type {
|
enum string_type {
|
||||||
str_squote = (0),
|
str_squote = (0),
|
||||||
|
@ -7858,7 +7859,7 @@ parser_yylex(struct parser_params *parser)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
token = parse_string(lex_strterm);
|
token = parse_string(lex_strterm);
|
||||||
if (token == tSTRING_END && (peek_n('\'', -1) || peek_n('"', -1))) {
|
if ((token == tSTRING_END) && (lex_strterm->nd_func & STR_FUNC_LABEL)) {
|
||||||
if (((IS_lex_state(EXPR_BEG | EXPR_ENDFN) && !COND_P()) || IS_ARG()) &&
|
if (((IS_lex_state(EXPR_BEG | EXPR_ENDFN) && !COND_P()) || IS_ARG()) &&
|
||||||
IS_LABEL_SUFFIX(0)) {
|
IS_LABEL_SUFFIX(0)) {
|
||||||
nextc();
|
nextc();
|
||||||
|
@ -8139,7 +8140,7 @@ parser_yylex(struct parser_params *parser)
|
||||||
return '>';
|
return '>';
|
||||||
|
|
||||||
case '"':
|
case '"':
|
||||||
lex_strterm = NEW_STRTERM(str_dquote, '"', 0);
|
lex_strterm = NEW_STRTERM(str_dquote|STR_FUNC_LABEL, '"', 0);
|
||||||
return tSTRING_BEG;
|
return tSTRING_BEG;
|
||||||
|
|
||||||
case '`':
|
case '`':
|
||||||
|
@ -8158,7 +8159,7 @@ parser_yylex(struct parser_params *parser)
|
||||||
return tXSTRING_BEG;
|
return tXSTRING_BEG;
|
||||||
|
|
||||||
case '\'':
|
case '\'':
|
||||||
lex_strterm = NEW_STRTERM(str_squote, '\'', 0);
|
lex_strterm = NEW_STRTERM(str_squote|STR_FUNC_LABEL, '\'', 0);
|
||||||
return tSTRING_BEG;
|
return tSTRING_BEG;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
|
|
|
@ -295,6 +295,15 @@ WARN
|
||||||
assert_not_label(:foo, 'class Foo < not_label:foo; end', bug6347)
|
assert_not_label(:foo, 'class Foo < not_label:foo; end', bug6347)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_no_label_with_percent
|
||||||
|
assert_syntax_error('{%"a": 1}', /unexpected ':'/)
|
||||||
|
assert_syntax_error("{%'a': 1}", /unexpected ':'/)
|
||||||
|
assert_syntax_error('{%Q"a": 1}', /unexpected ':'/)
|
||||||
|
assert_syntax_error("{%Q'a': 1}", /unexpected ':'/)
|
||||||
|
assert_syntax_error('{%q"a": 1}', /unexpected ':'/)
|
||||||
|
assert_syntax_error("{%q'a': 1}", /unexpected ':'/)
|
||||||
|
end
|
||||||
|
|
||||||
def test_duplicated_arg
|
def test_duplicated_arg
|
||||||
assert_syntax_error("def foo(a, a) end", /duplicated argument name/)
|
assert_syntax_error("def foo(a, a) end", /duplicated argument name/)
|
||||||
assert_nothing_raised { def foo(_, _) end }
|
assert_nothing_raised { def foo(_, _) end }
|
||||||
|
|
Loading…
Reference in a new issue