summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-03-07 14:02:55 +0100
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-03-07 14:02:55 +0100
commit87a905b01dab90acd2e62975ac180e14b41f3eb8 (patch)
tree082bb6881a2d7a2aa14b2547de896afbe0fc5344 /lib
parent9be9f4450983156f4fee31d41c47a613c4376944 (diff)
messagemapper: fix regexp creation for double-optional templates
When a mapping template had a double optional key such as 'something [[double] optional]' the resuting regexp moved the spacing between the (converted) double brackets, requiring extra spacing before the 'optional' keyword. Fix by moving spacing inside all consecutive brackets before converting brackets into their regexp form.
Diffstat (limited to 'lib')
-rw-r--r--lib/rbot/messagemapper.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/rbot/messagemapper.rb b/lib/rbot/messagemapper.rb
index 9501ac59..1162a3a2 100644
--- a/lib/rbot/messagemapper.rb
+++ b/lib/rbot/messagemapper.rb
@@ -514,7 +514,9 @@ class Bot
s = "#{not_needed ? "(?:" : ""}#{whites}(#{sub})#{ not_needed ? ")?" : ""}"
}
# debug "Replaced dyns: #{rx.inspect}"
- rx.gsub!(/((?:\\ )*)\\\[/, "(?:\\1")
+ rx.gsub!(/((?:\\ )*)((?:\\\[)+)/, '\2\1')
+ # debug "Corrected optionals spacing: #{rx.inspect}"
+ rx.gsub!(/\\\[/, "(?:")
rx.gsub!(/\\\]/, ")?")
# debug "Delimited optionals: #{rx.inspect}"
rx.gsub!(/(?:\\ )+/, "\\s+")