* parse.y (parser_here_document): should dispatch heredoc_end

scanner event on an empty here document.  fixed Bug#4543.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32412 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2011-07-05 06:28:07 +00:00
parent eb78d224e3
commit 2ac460af94
3 changed files with 30 additions and 6 deletions

View File

@ -1,3 +1,8 @@
Tue Jul 5 15:28:04 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (parser_here_document): should dispatch heredoc_end
scanner event on an empty here document. fixed Bug#4543.
Tue Jul 5 13:49:26 2011 Yusuke Endoh <mame@tsg.ne.jp>
* addr2line.c: fix r32407 to check HAVE_ALLOCA_H.

23
parse.y
View File

@ -6095,6 +6095,21 @@ parser_whole_match_p(struct parser_params *parser,
return strncmp(eos, p, len) == 0;
}
#ifdef RIPPER
static void
ripper_dispatch_heredoc_end(struct parser_params *parser)
{
if (!NIL_P(parser->delayed))
ripper_dispatch_delayed_token(parser, tSTRING_CONTENT);
lex_goto_eol(parser);
ripper_dispatch_ignored_scan_event(parser, tHEREDOC_END);
}
#define dispatch_heredoc_end() ripper_dispatch_heredoc_end(parser)
#else
#define dispatch_heredoc_end() ((void)0)
#endif
static int
parser_here_document(struct parser_params *parser, NODE *here)
{
@ -6131,6 +6146,7 @@ parser_here_document(struct parser_params *parser, NODE *here)
return 0;
}
if (was_bol() && whole_match_p(eos, len, indent)) {
dispatch_heredoc_end();
heredoc_restore(lex_strterm);
return tSTRING_END;
}
@ -6192,12 +6208,7 @@ parser_here_document(struct parser_params *parser, NODE *here)
} while (!whole_match_p(eos, len, indent));
str = STR_NEW3(tok(), toklen(), enc, func);
}
#ifdef RIPPER
if (!NIL_P(parser->delayed))
ripper_dispatch_delayed_token(parser, tSTRING_CONTENT);
lex_goto_eol(parser);
ripper_dispatch_ignored_scan_event(parser, tHEREDOC_END);
#endif
dispatch_heredoc_end();
heredoc_restore(lex_strterm);
lex_strterm = NEW_STRTERM(-1, 0, 0);
set_yylval_str(str);

View File

@ -66,6 +66,11 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
[[2, 0], :on_tstring_content, "heredoc\n"],
[[3, 0], :on_heredoc_end, "EOS"]],
Ripper.lex("<<EOS\nheredoc\nEOS")
assert_equal [[[1, 0], :on_heredoc_beg, "<<EOS"],
[[1, 5], :on_nl, "\n"],
[[2, 0], :on_heredoc_end, "EOS"]],
Ripper.lex("<<EOS\nEOS"),
"bug#4543"
assert_equal [[[1, 0], :on_regexp_beg, "/"],
[[1, 1], :on_tstring_content, "foo\nbar"],
[[2, 3], :on_regexp_end, "/"]],
@ -653,6 +658,9 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
def test_heredoc_end
assert_equal [],
scan('heredoc_end', '')
assert_equal ["EOS"],
scan('heredoc_end', "<<EOS\nEOS"),
"bug#4543"
assert_equal ["EOS"],
scan('heredoc_end', "<<EOS\nheredoc\nEOS")
assert_equal ["EOS\n"],