ruby-changes:26178
From: nobu <ko1@a...>
Date: Thu, 6 Dec 2012 17:29:29 +0900 (JST)
Subject: [ruby-changes:26178] nobu:r38235 (trunk): parse.y: flush string content
nobu 2012-12-06 17:29:16 +0900 (Thu, 06 Dec 2012) New Revision: 38235 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38235 Log: parse.y: flush string content * parse.y (parser_here_document): flush string content between new line and :string_embexpr. [ruby-core:48703] [Bug #7255] Modified files: trunk/ChangeLog trunk/parse.y trunk/test/ripper/test_scanner_events.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 38234) +++ ChangeLog (revision 38235) @@ -1,3 +1,8 @@ +Thu Dec 6 17:29:03 2012 Nobuyoshi Nakada <nobu@r...> + + * 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@s...> * test/rake/helper.rb: Load envutil correctly. Removed useless rescue Index: parse.y =================================================================== --- parse.y (revision 38234) +++ parse.y (revision 38235) @@ -6107,6 +6107,25 @@ #define NEW_STRTERM(func, term, paren) \ 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 parser_parse_string(struct parser_params *parser, NODE *quote) { @@ -6166,18 +6185,8 @@ tokfix(); 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; } @@ -6382,6 +6391,7 @@ } if (c != '\n') { set_yylval_str(STR_NEW3(tok(), toklen(), enc, func)); + flush_string_content(enc); return tSTRING_CONTENT; } tokadd(nextc()); Index: test/ripper/test_scanner_events.rb =================================================================== --- test/ripper/test_scanner_events.rb (revision 38234) +++ test/ripper/test_scanner_events.rb (revision 38235) @@ -676,6 +676,13 @@ scan('tstring_content', "<<""EOS\nhere\ndoc \nEOS \n") assert_equal ["heredoc\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 def test_heredoc_end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/