@@ -147,7 +147,7 @@ def next_string_token
147
147
end
148
148
end
149
149
150
- # see if we can read end of string/xstring/regecp markers
150
+ # see if we can read end of string/xstring/regexp markers
151
151
# if scan /#{str_parse[:end]}/
152
152
if scan Regexp . new ( Regexp . escape ( str_parse [ :end ] ) )
153
153
if words && !str_parse [ :done_last_space ] #&& space
@@ -161,7 +161,7 @@ def next_string_token
161
161
if str_parse [ :nesting ] == 0
162
162
@lex_state = :expr_end
163
163
164
- if str_parse [ :regexp ]
164
+ if str_parse [ :type ] == :regexp
165
165
result = scan ( /\w +/ )
166
166
return :tREGEXP_END , result
167
167
end
@@ -180,7 +180,7 @@ def next_string_token
180
180
@lex_state = :expr_end
181
181
return :tSTRING_END , scanner . matched
182
182
183
- elsif str_parse [ :beg ] == '/' || str_parse [ :regexp ]
183
+ elsif str_parse [ :beg ] == '/' || str_parse [ :type ] == :regexp
184
184
result = scan ( /\w +/ )
185
185
@lex_state = :expr_end
186
186
return :tREGEXP_END , result
@@ -250,7 +250,7 @@ def add_heredoc_content(str_buffer, str_parse)
250
250
elsif expand && check ( /#(?=[\$ \@ \{ ])/ )
251
251
break
252
252
elsif scan ( /\\ / )
253
- if str_parse [ :regexp ]
253
+ if str_parse [ :type ] == :regexp
254
254
if scan ( /(.)/ )
255
255
c = "\\ " + scanner . matched
256
256
end
@@ -329,7 +329,7 @@ def add_string_content(str_buffer, str_parse)
329
329
#c = scanner.matched
330
330
331
331
elsif scan ( /\\ / )
332
- if str_parse [ :regexp ]
332
+ if str_parse [ :type ] == :regexp
333
333
if scan ( /(.)/ )
334
334
c = "\\ " + scanner . matched
335
335
end
@@ -696,42 +696,43 @@ def yylex
696
696
@lex_state = after_operator? ( ) ? :expr_arg : :expr_beg
697
697
return :tPIPE , '|'
698
698
699
- elsif scan ( /\% W/ )
700
- start_word = scan ( /./ )
701
- end_word = { '(' => ')' , '[' => ']' , '{' => '}' } [ start_word ] || start_word
702
- self . strterm = { :type => :dword , :beg => 'W' , :end => end_word }
703
- scan ( /\s */ )
704
- return :tWORDS_BEG , scanner . matched
705
-
706
- elsif scan ( /\% w/ ) or scan ( /\% i/ )
707
- start_word = scan ( /./ )
708
- end_word = { '(' => ')' , '[' => ']' , '{' => '}' } [ start_word ] || start_word
709
- self . strterm = { :type => :sword , :beg => 'w' , :end => end_word }
710
- scan ( /\s */ )
711
- return :tAWORDS_BEG , scanner . matched
712
-
713
- elsif scan ( /\% [Qq]/ )
714
- type = scanner . matched . end_with? ( 'Q' ) ? :dquote : :squote
715
- start_word = scan ( /./ )
716
- end_word = { '(' => ')' , '[' => ']' , '{' => '}' } [ start_word ] || start_word
717
- self . strterm = { :type => type , :beg => start_word , :end => end_word , :balance => true , :nesting => 0 }
718
- return :tSTRING_BEG , scanner . matched
719
-
720
- elsif scan ( /\% x/ )
721
- start_word = scan ( /./ )
722
- end_word = { '(' => ')' , '[' => ']' , '{' => '}' } [ start_word ] || start_word
723
- self . strterm = { :type => :xquote , :beg => start_word , :end => end_word , :balance => true , :nesting => 0 }
724
- return :tXSTRING_BEG , scanner . matched
725
-
726
- elsif scan ( /\% r/ )
727
- start_word = scan ( /./ )
728
- end_word = { '(' => ')' , '[' => ']' , '{' => '}' } [ start_word ] || start_word
729
- self . strterm = { :type => :regexp , :beg => start_word , :end => end_word , :regexp => true , :balance => true , :nesting => 0 }
730
- return :tREGEXP_BEG , scanner . matched
699
+ elsif scan ( /\% [QqWwxr]/ )
700
+ str_type = scanner . matched [ 1 ]
701
+ paren = scan ( /./ )
702
+
703
+ term = case paren
704
+ when '(' then ')'
705
+ when '[' then ']'
706
+ when '{' then '}'
707
+ else paren
708
+ end
709
+
710
+ case str_type
711
+ when 'Q'
712
+ self . strterm = { :type => :dquote , :beg => paren , :end => term , :balance => true , :nesting => 0 }
713
+ return :tSTRING_BEG , scanner . matched
714
+ when 'q'
715
+ self . strterm = { :type => :squote , :beg => paren , :end => term , :balance => true , :nesting => 0 }
716
+ return :tSTRING_BEG , scanner . matched
717
+ when 'W'
718
+ self . strterm = { :type => :dword , :beg => 'W' , :end => term }
719
+ scan ( /\s */ )
720
+ return :tWORDS_BEG , scanner . matched
721
+ when 'w' , 'i'
722
+ self . strterm = { :type => :sword , :beg => 'W' , :end => term }
723
+ scan ( /\s */ )
724
+ return :tAWORDS_BEG , scanner . matched
725
+ when 'x'
726
+ self . strterm = { :type => :xquote , :beg => paren , :end => term , :balance => true , :nesting => 0 }
727
+ return :tXSTRING_BEG , scanner . matched
728
+ when 'r'
729
+ self . strterm = { :type => :regexp , :beg => paren , :end => term , :balance => true , :nesting => 0 }
730
+ return :tREGEXP_BEG , scanner . matched
731
+ end
731
732
732
733
elsif scan ( /\/ / )
733
734
if [ :expr_beg , :expr_mid ] . include? @lex_state
734
- self . strterm = { :type => :regexp , :beg => '/' , :end => '/' , :regexp => true }
735
+ self . strterm = { :type => :regexp , :beg => '/' , :end => '/' }
735
736
return :tREGEXP_BEG , scanner . matched
736
737
elsif scan ( /\= / )
737
738
@lex_state = :expr_beg
@@ -740,7 +741,7 @@ def yylex
740
741
@lex_state = :expr_arg
741
742
elsif @lex_state == :expr_cmdarg || @lex_state == :expr_arg
742
743
if !check ( /\s / ) && @space_seen
743
- self . strterm = { :type => :regexp , :beg => '/' , :end => '/' , :regexp => true }
744
+ self . strterm = { :type => :regexp , :beg => '/' , :end => '/' }
744
745
return :tREGEXP_BEG , scanner . matched
745
746
end
746
747
else
0 commit comments