summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-01 21:32:04 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-01 21:32:04 +0000
commit0a190272cdbe182eea4d27407c680370dd8afde8 (patch)
treebe4cb1bc1fa1883fdfa3e0558c672ac4088a40f7
parent1549a6b78daaa4f3efa1d47eb6c9e52b080578b8 (diff)
parse.y: preserve tSTRING_CONTENT results
* parse.y (ripper_flush_string_content): preserve the dispatched results at tSTRING_CONTENT. [ruby-dev:48714] [Bug #10437] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--parse.y9
-rw-r--r--test/ripper/test_sexp.rb3
3 files changed, 13 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 9e497c2..a275a5e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
-Tue Dec 2 06:31:31 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Tue Dec 2 06:32:02 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * parse.y (ripper_flush_string_content): preserve the dispatched
+ results at tSTRING_CONTENT. [ruby-dev:48714] [Bug #10437]
* parse.y (regexp_contents): check in ripper only if the whole
content is a single regexp without interpolation.
diff --git a/parse.y b/parse.y
index a50047e..13a0f48 100644
--- a/parse.y
+++ b/parse.y
@@ -6302,6 +6302,8 @@ static void
ripper_flush_string_content(struct parser_params *parser, rb_encoding *enc)
{
VALUE content = yylval.val;
+ if (!ripper_is_node_yylval(content))
+ content = ripper_new_yylval(0, 0, content);
if (!NIL_P(parser->delayed)) {
ptrdiff_t len = lex_p - parser->tokp;
if (len > 0) {
@@ -6309,11 +6311,12 @@ ripper_flush_string_content(struct parser_params *parser, rb_encoding *enc)
}
ripper_dispatch_delayed_token(parser, tSTRING_CONTENT);
parser->tokp = lex_p;
+ RNODE(content)->nd_rval = yylval.val;
}
- if (!ripper_is_node_yylval(content))
- content = ripper_new_yylval(0, 0, content);
- yylval.val = content;
ripper_dispatch_scan_event(parser, tSTRING_CONTENT);
+ if (yylval.val != content)
+ RNODE(content)->nd_rval = yylval.val;
+ yylval.val = content;
}
#define flush_string_content(enc) ripper_flush_string_content(parser, (enc))
diff --git a/test/ripper/test_sexp.rb b/test/ripper/test_sexp.rb
index adf8c46..2c5bcda 100644
--- a/test/ripper/test_sexp.rb
+++ b/test/ripper/test_sexp.rb
@@ -26,6 +26,9 @@ class TestRipper::Sexp < Test::Unit::TestCase
sexp = Ripper.sexp('/foo/')
assert_equal 'foo', search_sexp(:@tstring_content, search_sexp(:regexp_literal, sexp))[1]
+ sexp = Ripper.sexp("/foo\nbar/")
+ assert_equal "foo\nbar", search_sexp(:@tstring_content, search_sexp(:regexp_literal, sexp))[1]
+
sexp = Ripper.sexp('/(?<n>a(b|\g<n>))/')
assert_equal '(?<n>a(b|\g<n>))', search_sexp(:@tstring_content, search_sexp(:regexp_literal, sexp))[1]
end