parse.y: symbol literals for alias/undef

* defs/keywords (alias, undef): symbol literals are allowed.
* parse.y (parse_percent): should parse symbol literals for alias
  and undef.  [ruby-dev:47681] [Bug #8851]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-03-16 14:10:27 +00:00
Родитель 5c725ba9fe
Коммит cb65717b45
6 изменённых файлов: 44 добавлений и 11 удалений

Просмотреть файл

@ -1,3 +1,10 @@
Wed Mar 16 23:10:25 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* defs/keywords (alias, undef): symbol literals are allowed.
* parse.y (parse_percent): should parse symbol literals for alias
and undef. [ruby-dev:47681] [Bug #8851]
Wed Mar 16 21:39:39 2016 NARUSE, Yui <naruse@ruby-lang.org>
* enc/trans/JIS: update Unicode's notice. [Bug #11844]

Просмотреть файл

@ -13,7 +13,7 @@ __LINE__, {keyword__LINE__, keyword__LINE__}, EXPR_END
__FILE__, {keyword__FILE__, keyword__FILE__}, EXPR_END
BEGIN, {keyword_BEGIN, keyword_BEGIN}, EXPR_END
END, {keyword_END, keyword_END}, EXPR_END
alias, {keyword_alias, keyword_alias}, EXPR_FNAME
alias, {keyword_alias, keyword_alias}, EXPR_FNAME|EXPR_FITEM
and, {keyword_and, keyword_and}, EXPR_VALUE
begin, {keyword_begin, keyword_begin}, EXPR_BEG
break, {keyword_break, keyword_break}, EXPR_MID
@ -43,7 +43,7 @@ self, {keyword_self, keyword_self}, EXPR_END
super, {keyword_super, keyword_super}, EXPR_ARG
then, {keyword_then, keyword_then}, EXPR_BEG
true, {keyword_true, keyword_true}, EXPR_END
undef, {keyword_undef, keyword_undef}, EXPR_FNAME
undef, {keyword_undef, keyword_undef}, EXPR_FNAME|EXPR_FITEM
unless, {keyword_unless, modifier_unless}, EXPR_VALUE
until, {keyword_until, modifier_until}, EXPR_VALUE
when, {keyword_when, keyword_when}, EXPR_VALUE

Просмотреть файл

@ -13,7 +13,7 @@ __LINE__, {keyword__LINE__, keyword__LINE__}, EXPR_END
__FILE__, {keyword__FILE__, keyword__FILE__}, EXPR_END
BEGIN, {keyword_BEGIN, keyword_BEGIN}, EXPR_END
END, {keyword_END, keyword_END}, EXPR_END
alias, {keyword_alias, keyword_alias}, EXPR_FNAME
alias, {keyword_alias, keyword_alias}, EXPR_FNAME|EXPR_FITEM
and, {keyword_and, keyword_and}, EXPR_VALUE
begin, {keyword_begin, keyword_begin}, EXPR_BEG
break, {keyword_break, keyword_break}, EXPR_MID
@ -43,7 +43,7 @@ self, {keyword_self, keyword_self}, EXPR_END
super, {keyword_super, keyword_super}, EXPR_ARG
then, {keyword_then, keyword_then}, EXPR_BEG
true, {keyword_true, keyword_true}, EXPR_END
undef, {keyword_undef, keyword_undef}, EXPR_FNAME
undef, {keyword_undef, keyword_undef}, EXPR_FNAME|EXPR_FITEM
unless, {keyword_unless, modifier_unless}, EXPR_VALUE
until, {keyword_until, modifier_until}, EXPR_VALUE
when, {keyword_when, keyword_when}, EXPR_VALUE

Просмотреть файл

@ -243,7 +243,7 @@ rb_reserved_word (str, len)
#line 30 "defs/keywords"
{(int)offsetof(struct stringpool_t, stringpool_str27), {keyword_for, keyword_for}, EXPR_VALUE},
#line 46 "defs/keywords"
{(int)offsetof(struct stringpool_t, stringpool_str28), {keyword_undef, keyword_undef}, EXPR_FNAME},
{(int)offsetof(struct stringpool_t, stringpool_str28), {keyword_undef, keyword_undef}, EXPR_FNAME|EXPR_FITEM},
#line 37 "defs/keywords"
{(int)offsetof(struct stringpool_t, stringpool_str29), {keyword_or, keyword_or}, EXPR_VALUE},
#line 32 "defs/keywords"
@ -275,7 +275,7 @@ rb_reserved_word (str, len)
#line 15 "defs/keywords"
{(int)offsetof(struct stringpool_t, stringpool_str43), {keyword_END, keyword_END}, EXPR_END},
#line 16 "defs/keywords"
{(int)offsetof(struct stringpool_t, stringpool_str44), {keyword_alias, keyword_alias}, EXPR_FNAME},
{(int)offsetof(struct stringpool_t, stringpool_str44), {keyword_alias, keyword_alias}, EXPR_FNAME|EXPR_FITEM},
#line 14 "defs/keywords"
{(int)offsetof(struct stringpool_t, stringpool_str45), {keyword_BEGIN, keyword_BEGIN}, EXPR_END},
#line 23 "defs/keywords"

12
parse.y
Просмотреть файл

@ -73,6 +73,7 @@ enum lex_state_bits {
EXPR_CLASS_bit, /* immediate after `class', no here document. */
EXPR_LABEL_bit, /* flag bit, label is allowed. */
EXPR_LABELED_bit, /* flag bit, just after a label. */
EXPR_FITEM_bit, /* symbol literal as FNAME. */
EXPR_MAX_STATE
};
/* examine combinations */
@ -90,6 +91,7 @@ enum lex_state_e {
DEF_EXPR(CLASS),
DEF_EXPR(LABEL),
DEF_EXPR(LABELED),
DEF_EXPR(FITEM),
EXPR_VALUE = EXPR_BEG,
EXPR_BEG_ANY = (EXPR_BEG | EXPR_MID | EXPR_CLASS),
EXPR_ARG_ANY = (EXPR_ARG | EXPR_CMDARG),
@ -1135,7 +1137,7 @@ stmt_or_begin : stmt
%*/
}
stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME);} fitem
stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem
{
/*%%%*/
$$ = NEW_ALIAS($2, $4);
@ -1971,7 +1973,7 @@ undef_list : fitem
$$ = rb_ary_new3(1, $1);
%*/
}
| undef_list ',' {SET_LEX_STATE(EXPR_FNAME);} fitem
| undef_list ',' {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem
{
/*%%%*/
$$ = block_append($1, NEW_UNDEF($4));
@ -7781,7 +7783,7 @@ parse_percent(struct parser_params *parser, const int space_seen, const enum lex
case 's':
lex_strterm = NEW_STRTERM(str_ssym, term, paren);
SET_LEX_STATE(EXPR_FNAME);
SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);
return tSYMBEG;
default:
@ -7794,7 +7796,7 @@ parse_percent(struct parser_params *parser, const int space_seen, const enum lex
SET_LEX_STATE(EXPR_BEG);
return tOP_ASGN;
}
if (IS_SPCARG(c)) {
if (IS_SPCARG(c) || (IS_lex_state(EXPR_FITEM) && c == 's')) {
goto quotation;
}
SET_LEX_STATE(IS_AFTER_OPERATOR() ? EXPR_ARG : EXPR_BEG);
@ -9213,7 +9215,7 @@ id_is_var_gen(struct parser_params *parser, ID id)
static const char lex_state_names[][13] = {
"EXPR_BEG", "EXPR_END", "EXPR_ENDARG", "EXPR_ENDFN", "EXPR_ARG",
"EXPR_CMDARG", "EXPR_MID", "EXPR_FNAME", "EXPR_DOT", "EXPR_CLASS",
"EXPR_LABEL", "EXPR_LABELED",
"EXPR_LABEL", "EXPR_LABELED","EXPR_FITEM",
};
static VALUE

Просмотреть файл

@ -790,6 +790,30 @@ eom
end
end
def test_alias_symbol
bug8851 = '[ruby-dev:47681] [Bug #8851]'
formats = ['%s', ":'%s'", ':"%s"', '%%s(%s)']
all_assertions(bug8851) do |all|
formats.product(formats) do |form1, form2|
all.for(code = "alias #{form1 % 'a'} #{form2 % 'p'}") do
assert_valid_syntax(code)
end
end
end
end
def test_undef_symbol
bug8851 = '[ruby-dev:47681] [Bug #8851]'
formats = ['%s', ":'%s'", ':"%s"', '%%s(%s)']
all_assertions(bug8851) do |all|
formats.product(formats) do |form1, form2|
all.for(code = "undef #{form1 % 'a'}, #{form2 % 'p'}") do
assert_valid_syntax(code)
end
end
end
end
private
def not_label(x) @result = x; @not_label ||= nil end