summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--parse.y23
-rw-r--r--test/ripper/test_scanner_events.rb8
3 files changed, 30 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 91a3e58..c552cc4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/parse.y b/parse.y
index 8945b53..c3db298 100644
--- a/parse.y
+++ b/parse.y
@@ -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);
diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb
index 9005e46..7d5bb3c 100644
--- a/test/ripper/test_scanner_events.rb
+++ b/test/ripper/test_scanner_events.rb
@@ -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, "/"]],
@@ -654,6 +659,9 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
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"],
scan('heredoc_end', "<<EOS\nheredoc\nEOS\n")