parse.y: flush string content
* parse.y (parser_here_document): flush string content between new line and :string_embexpr. [ruby-core:48703] [Bug #7255] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
68a44cd169
commit
bd0c636211
@ -1,3 +1,8 @@
|
|||||||
|
Thu Dec 6 17:29:03 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* parse.y (parser_here_document): flush string content between new
|
||||||
|
line and :string_embexpr. [ruby-core:48703] [Bug #7255]
|
||||||
|
|
||||||
Thu Dec 6 16:35:21 2012 Eric Hodel <drbrain@segment7.net>
|
Thu Dec 6 16:35:21 2012 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
* test/rake/helper.rb: Load envutil correctly. Removed useless rescue
|
* test/rake/helper.rb: Load envutil correctly. Removed useless rescue
|
||||||
|
32
parse.y
32
parse.y
@ -6107,6 +6107,25 @@ parser_tokadd_string(struct parser_params *parser,
|
|||||||
#define NEW_STRTERM(func, term, paren) \
|
#define NEW_STRTERM(func, term, paren) \
|
||||||
rb_node_newnode(NODE_STRTERM, (func), (term) | ((paren) << (CHAR_BIT * 2)), 0)
|
rb_node_newnode(NODE_STRTERM, (func), (term) | ((paren) << (CHAR_BIT * 2)), 0)
|
||||||
|
|
||||||
|
#ifdef RIPPER
|
||||||
|
static void
|
||||||
|
ripper_flush_string_content(struct parser_params *parser, rb_encoding *enc)
|
||||||
|
{
|
||||||
|
if (!NIL_P(parser->delayed)) {
|
||||||
|
ptrdiff_t len = lex_p - parser->tokp;
|
||||||
|
if (len > 0) {
|
||||||
|
rb_enc_str_buf_cat(parser->delayed, parser->tokp, len, enc);
|
||||||
|
}
|
||||||
|
ripper_dispatch_delayed_token(parser, tSTRING_CONTENT);
|
||||||
|
parser->tokp = lex_p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define flush_string_content(enc) ripper_flush_string_content(parser, (enc))
|
||||||
|
#else
|
||||||
|
#define flush_string_content(enc) ((void)(enc))
|
||||||
|
#endif
|
||||||
|
|
||||||
static int
|
static int
|
||||||
parser_parse_string(struct parser_params *parser, NODE *quote)
|
parser_parse_string(struct parser_params *parser, NODE *quote)
|
||||||
{
|
{
|
||||||
@ -6166,17 +6185,7 @@ parser_parse_string(struct parser_params *parser, NODE *quote)
|
|||||||
|
|
||||||
tokfix();
|
tokfix();
|
||||||
set_yylval_str(STR_NEW3(tok(), toklen(), enc, func));
|
set_yylval_str(STR_NEW3(tok(), toklen(), enc, func));
|
||||||
|
flush_string_content(enc);
|
||||||
#ifdef RIPPER
|
|
||||||
if (!NIL_P(parser->delayed)) {
|
|
||||||
ptrdiff_t len = lex_p - parser->tokp;
|
|
||||||
if (len > 0) {
|
|
||||||
rb_enc_str_buf_cat(parser->delayed, parser->tokp, len, enc);
|
|
||||||
}
|
|
||||||
ripper_dispatch_delayed_token(parser, tSTRING_CONTENT);
|
|
||||||
parser->tokp = lex_p;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return tSTRING_CONTENT;
|
return tSTRING_CONTENT;
|
||||||
}
|
}
|
||||||
@ -6382,6 +6391,7 @@ parser_here_document(struct parser_params *parser, NODE *here)
|
|||||||
}
|
}
|
||||||
if (c != '\n') {
|
if (c != '\n') {
|
||||||
set_yylval_str(STR_NEW3(tok(), toklen(), enc, func));
|
set_yylval_str(STR_NEW3(tok(), toklen(), enc, func));
|
||||||
|
flush_string_content(enc);
|
||||||
return tSTRING_CONTENT;
|
return tSTRING_CONTENT;
|
||||||
}
|
}
|
||||||
tokadd(nextc());
|
tokadd(nextc());
|
||||||
|
@ -676,6 +676,13 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
|
|||||||
scan('tstring_content', "<<""EOS\nhere\ndoc \nEOS \n")
|
scan('tstring_content', "<<""EOS\nhere\ndoc \nEOS \n")
|
||||||
assert_equal ["heredoc\n\tEOS \n"],
|
assert_equal ["heredoc\n\tEOS \n"],
|
||||||
scan('tstring_content', "<<""-EOS\nheredoc\n\tEOS \n")
|
scan('tstring_content', "<<""-EOS\nheredoc\n\tEOS \n")
|
||||||
|
bug7255 = '[ruby-core:48703]'
|
||||||
|
assert_equal ["there\n""heredoc", "\n"],
|
||||||
|
scan('tstring_content', "<<""EOS\n""there\n""heredoc\#{foo}\nEOS"),
|
||||||
|
bug7255
|
||||||
|
assert_equal ["there\n""heredoc", "\n"],
|
||||||
|
scan('tstring_content', "<<""EOS\n""there\n""heredoc\#@foo\nEOS"),
|
||||||
|
bug7255
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_heredoc_end
|
def test_heredoc_end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user