Modified:
branches/groups/src/esmre.py
Log:
Refactor: simplify hint collection methods in RootState.
self.to_append is always a single character or an empty string, so the test
in
bank_current_hint_with_last_byte was unnecesary and forget_current_hint is
badly named and becomes equivalent to
bank_current_hint_and_forget_last_byte.
Modified: branches/groups/src/esmre.py
==============================================================================
--- branches/groups/src/esmre.py (original)
+++ branches/groups/src/esmre.py Wed Oct 1 08:52:44 2008
@@ -87,21 +87,13 @@
self.update_hints(ch)
return self.next_state(ch)
- def forget_current_hint(self):
- self.to_append = ""
- self.hints.append("")
-
def bank_current_hint_with_last_byte(self):
- if self.to_append:
- self.hints[-1] += self.to_append
+ self.hints[-1] += self.to_append
self.to_append = ""
self.hints.append("")
def bank_current_hint_and_forget_last_byte(self):
- if self.to_append:
- self.hints[-1] += self.to_append[:-1]
-
self.to_append = ""
self.hints.append("")
@@ -115,15 +107,12 @@
self.to_append = ch
def update_hints(self, ch):
- if ch in "?*":
- self.forget_current_hint()
+ if ch in "?*{":
+ self.bank_current_hint_and_forget_last_byte()
elif ch in "+.^$([\\":
self.bank_current_hint_with_last_byte()
- elif ch == "{":
- self.bank_current_hint_and_forget_last_byte()
-
elif ch == "|":
self.forget_all_hints()