Project

General

Profile

Bug #14027

Updated by mjago (Martyn Jago) over 6 years ago

Where you have two or more embedded expressions on the same line within a squiggly heredoc 
 seperated by whitespace, Ripper considers that whitespace as ignored space despite it not being at the 
 beginning of a line. Below is a diff of lexer output between identical heredoc and squiggly heredoc to highlight: 

 ~~~ diff 
  [[[1, 0], :on_ignored_nl, "\n", EXPR_BEG], 
 -[[[1, - [[2, 0], :on_heredoc_beg, "<<-E", EXPR_BEG], 
 +[[[1, + [[2, 0], :on_heredoc_beg, "<<~E", EXPR_BEG], 
   [[1, [[2, 4], :on_nl, "\n", EXPR_BEG], 
   [[2, [[3, 0], :on_embexpr_beg, "\#{", EXPR_BEG], 
   [[2, [[3, 2], :on_int, "1", "3", EXPR_END|EXPR_ENDARG], 
   [[2, [[3, 3], :on_embexpr_end, "}", EXPR_END], 
 - [[2, [[3, 4], :on_tstring_content, " ", EXPR_BEG], 
 + [[2, [[3, 4], :on_ignored_sp, " ", EXPR_BEG], 
   [[2, [[3, 5], :on_embexpr_beg, "\#{", EXPR_BEG], 
   [[2, [[3, 7], :on_sp, " ", EXPR_BEG], 
   [[3, 8], :on_int, "2", "4", EXPR_END|EXPR_ENDARG], 
   [[2, 8], [[3, 9], :on_sp, " ", EXPR_END|EXPR_ENDARG], 
   [[3, 10], :on_embexpr_end, "}", EXPR_END], 
   [[2, 9], [[3, 11], :on_tstring_content, "\n", EXPR_BEG], 
   [[3, [[4, 0], :on_heredoc_end, "E", EXPR_BEG]] 
 ~~~ 

 Also the sexp shows the whitespace as an empty string: 

 ~~~ diff 
 
  [:program, 
   [[:string_literal, 
     [:string_content, 
      [:string_embexpr, [[:@int, "1", [2, 2]]]], 
 -      [:@tstring_content, "     ", [2, 4]], 
 +      [:@tstring_content, "", [2, 5]], 7]], 
      [:string_embexpr, [[:@int, "2", [2, 7]]]], 9]]]], 
      [:@tstring_content, "\n", [2, 9]]]]]] 11]]]]]] 
 ~~~ 
 This can be seen on head, 2.4.2, and 2.3.5 

 Scripts used: 
 ``` 
 ruby -rripper -rpp -e '%{<<-E\n\#{1} \#{2}\nE}' 
 ruby -rripper -rpp -e '%{<<~E\n\#{1} \#{2}\nE}' 
 ``` 

Back