mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* parse.y (top_compstmt, top_stmts, top_stmt): prohibit BEGIN {} in
non-toplevel scope. [ruby-core:21657] * test/ruby/test_beginendblock.rb (test_begininclass): add a test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26347 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f00951bb25
commit
6b438bee04
3 changed files with 83 additions and 20 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Tue Jan 19 01:42:36 2010 Yusuke Endoh <mame@tsg.ne.jp>
|
||||||
|
|
||||||
|
* parse.y (top_compstmt, top_stmts, top_stmt): prohibit BEGIN {} in
|
||||||
|
non-toplevel scope. [ruby-core:21657]
|
||||||
|
|
||||||
|
* test/ruby/test_beginendblock.rb (test_begininclass): add a test for
|
||||||
|
above.
|
||||||
|
|
||||||
Mon Jan 18 17:16:03 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Mon Jan 18 17:16:03 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* lib/webrick/httpservlet/filehandler.rb (make_partial_content):
|
* lib/webrick/httpservlet/filehandler.rb (make_partial_content):
|
||||||
|
|
89
parse.y
89
parse.y
|
@ -686,6 +686,7 @@ static void token_info_pop(struct parser_params*, const char *token);
|
||||||
%type <node> string_contents xstring_contents string_content
|
%type <node> string_contents xstring_contents string_content
|
||||||
%type <node> words qwords word_list qword_list word
|
%type <node> words qwords word_list qword_list word
|
||||||
%type <node> literal numeric dsym cpath
|
%type <node> literal numeric dsym cpath
|
||||||
|
%type <node> top_compstmt top_stmts top_stmt
|
||||||
%type <node> bodystmt compstmt stmts stmt expr arg primary command command_call method_call
|
%type <node> bodystmt compstmt stmts stmt expr arg primary command command_call method_call
|
||||||
%type <node> expr_value arg_value primary_value
|
%type <node> expr_value arg_value primary_value
|
||||||
%type <node> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
|
%type <node> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
|
||||||
|
@ -788,7 +789,7 @@ program : {
|
||||||
local_push(0);
|
local_push(0);
|
||||||
%*/
|
%*/
|
||||||
}
|
}
|
||||||
compstmt
|
top_compstmt
|
||||||
{
|
{
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
if ($2 && !$<num>1) {
|
if ($2 && !$<num>1) {
|
||||||
|
@ -811,6 +812,73 @@ program : {
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
top_compstmt : top_stmts opt_terms
|
||||||
|
{
|
||||||
|
/*%%%*/
|
||||||
|
void_stmts($1);
|
||||||
|
fixup_nodes(&deferred_nodes);
|
||||||
|
/*%
|
||||||
|
%*/
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
top_stmts : none
|
||||||
|
{
|
||||||
|
/*%%%*/
|
||||||
|
$$ = NEW_BEGIN(0);
|
||||||
|
/*%
|
||||||
|
$$ = dispatch2(stmts_add, dispatch0(stmts_new),
|
||||||
|
dispatch0(void_stmt));
|
||||||
|
%*/
|
||||||
|
}
|
||||||
|
| top_stmt
|
||||||
|
{
|
||||||
|
/*%%%*/
|
||||||
|
$$ = newline_node($1);
|
||||||
|
/*%
|
||||||
|
$$ = dispatch2(stmts_add, dispatch0(stmts_new), $1);
|
||||||
|
%*/
|
||||||
|
}
|
||||||
|
| top_stmts terms top_stmt
|
||||||
|
{
|
||||||
|
/*%%%*/
|
||||||
|
$$ = block_append($1, newline_node($3));
|
||||||
|
/*%
|
||||||
|
$$ = dispatch2(stmts_add, $1, $3);
|
||||||
|
%*/
|
||||||
|
}
|
||||||
|
| error top_stmt
|
||||||
|
{
|
||||||
|
$$ = remove_begin($2);
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
top_stmt : stmt
|
||||||
|
| keyword_BEGIN
|
||||||
|
{
|
||||||
|
if (in_def || in_single) {
|
||||||
|
yyerror("BEGIN in method");
|
||||||
|
}
|
||||||
|
/*%%%*/
|
||||||
|
/* local_push(0); */
|
||||||
|
/*%
|
||||||
|
%*/
|
||||||
|
}
|
||||||
|
'{' top_compstmt '}'
|
||||||
|
{
|
||||||
|
/*%%%*/
|
||||||
|
ruby_eval_tree_begin = block_append(ruby_eval_tree_begin,
|
||||||
|
$4);
|
||||||
|
/* NEW_PREEXE($4)); */
|
||||||
|
/* local_pop(); */
|
||||||
|
$$ = NEW_BEGIN(0);
|
||||||
|
/*%
|
||||||
|
$$ = dispatch1(BEGIN, $4);
|
||||||
|
%*/
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
bodystmt : compstmt
|
bodystmt : compstmt
|
||||||
opt_rescue
|
opt_rescue
|
||||||
opt_else
|
opt_else
|
||||||
|
@ -984,25 +1052,6 @@ stmt : keyword_alias fitem {lex_state = EXPR_FNAME;} fitem
|
||||||
$$ = dispatch2(rescue_mod, $3, $1);
|
$$ = dispatch2(rescue_mod, $3, $1);
|
||||||
%*/
|
%*/
|
||||||
}
|
}
|
||||||
| keyword_BEGIN
|
|
||||||
{
|
|
||||||
if (in_def || in_single) {
|
|
||||||
yyerror("BEGIN in method");
|
|
||||||
}
|
|
||||||
/* local_push(0); */
|
|
||||||
}
|
|
||||||
'{' compstmt '}'
|
|
||||||
{
|
|
||||||
/*%%%*/
|
|
||||||
ruby_eval_tree_begin = block_append(ruby_eval_tree_begin,
|
|
||||||
$4);
|
|
||||||
/* NEW_PREEXE($4)); */
|
|
||||||
$$ = NEW_BEGIN(0);
|
|
||||||
/*%
|
|
||||||
$$ = dispatch1(BEGIN, $4);
|
|
||||||
%*/
|
|
||||||
/* local_pop(); */
|
|
||||||
}
|
|
||||||
| keyword_END '{' compstmt '}'
|
| keyword_END '{' compstmt '}'
|
||||||
{
|
{
|
||||||
if (in_def || in_single) {
|
if (in_def || in_single) {
|
||||||
|
|
|
@ -41,6 +41,12 @@ class TestBeginEndBlock < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_begininclass
|
||||||
|
assert_raise(SyntaxError) do
|
||||||
|
eval("class TestBeginEndBlock; BEGIN {}; end")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_endblockwarn
|
def test_endblockwarn
|
||||||
ruby = EnvUtil.rubybin
|
ruby = EnvUtil.rubybin
|
||||||
# Use Tempfile to create temporary file path.
|
# Use Tempfile to create temporary file path.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue