lib/regextest/back/main.rb in regextest-0.1.6 vs lib/regextest/back/main.rb in regextest-0.1.8
- old
+ new
@@ -278,21 +278,25 @@
if target["repeat_option"].index("reluctant")
result.push Regextest::Back::Element.new({cmd: :CMD_ANC_RELUCTANT_BEGIN, id: target["id"]})
end
# puts "repeat=#{repeat} quit=#{@quit_mode} nest=#{@nest}"
- repeat.times do
+ repeat.times do | current_repeat |
if( elem = generate_candidates(target["value"], param))
result.push elem
else
result = nil
break
end
- # quit to repeat if the first element is begin anchor
elem.flatten! if Array === elem # flatten considering duplicated repeat
- if elem.size > 0 && elem[0].respond_to?(:command) && elem[-1].respond_to?(:command)
+
+ # quit to repeat if the first element is begin anchor
+ if current_repeat >= min_repeat &&
+ elem.size > 0 &&
+ elem[0].respond_to?(:command) &&
+ elem[-1].respond_to?(:command)
break if elem[0].command == :CMD_ANC_LINE_BEGIN && !elem[-1].new_line?
break if elem[0].command == :CMD_ANC_STRING_BEGIN
end
end
@@ -325,14 +329,12 @@
relative_num = work
end
# puts "relative: #{relative_num}, nest=#{@nest}, :#{target}"
result = @parens_hash[target["refer_name"]][:generated][relative_num]
- # Somehow /(^a)\1/ must match with "aa"
- if result.size > 0 &&
- (result[0].command == :CMD_ANC_LINE_BEGIN ||
- result[0].command == :CMD_ANC_STRING_BEGIN)
- result = result[1..-1] # ignore first anchor
+ # Somehow /(^a)\1/ or /(\ba)\1/ must match with "aa"
+ if result.size > 0
+ result = result.select{|elem| elem.command == :CMD_SELECT}
end
else
result = nil
end
result