[esmre commit] r49 - in branches/groups: src test

1 view
Skip to first unread message

codesite...@google.com

unread,
Oct 1, 2008, 3:20:38 PM10/1/08
to esmre-c...@googlegroups.com
Author: wharris
Date: Wed Oct 1 12:20:23 2008
New Revision: 49

Modified:
branches/groups/src/esmre.py
branches/groups/test/test_esmre.py

Log:
Get hints from named groups.


Modified: branches/groups/src/esmre.py
==============================================================================
--- branches/groups/src/esmre.py (original)
+++ branches/groups/src/esmre.py Wed Oct 1 12:20:23 2008
@@ -161,7 +161,40 @@
return self


-class StartOfExtensionGroupState(InGroupState):
+class StartOfExtensionGroupState(object):
+ def __init__(self, parent_state):
+ self.parent_state = parent_state
+
+ def process_byte(self, ch):
+ if ch == "P":
+ return MaybeStartOfNamedGroupState(self.parent_state)
+ else:
+ return IgnoredGroupState(self.parent_state).process_byte(ch)
+
+
+class MaybeStartOfNamedGroupState(object):
+ def __init__(self, parent_state):
+ self.parent_state = parent_state
+
+ def process_byte(self, ch):
+ if ch == "<":
+ return InNamedGroupNameState(self.parent_state)
+ else:
+ return IgnoredGroupState(self.parent_state)
+
+
+class InNamedGroupNameState(object):
+ def __init__(self, parent_state):
+ self.parent_state = parent_state
+
+ def process_byte(self, ch):
+ if ch == ">":
+ return InGroupState(self.parent_state)
+ else:
+ return self
+
+
+class IgnoredGroupState(InGroupState):
def update_hints(self, ch):
pass


Modified: branches/groups/test/test_esmre.py
==============================================================================
--- branches/groups/test/test_esmre.py (original)
+++ branches/groups/test/test_esmre.py Wed Oct 1 12:20:23 2008
@@ -114,6 +114,9 @@
# non-grouping paren
r"(?:foo)",

+ # previous named group
+ r"(?P=foo)",
+
# comment
r"(?#foo)",

@@ -133,6 +136,11 @@
r"(?(1)foo|bar)"]:

self.checkHints([], regex)
+
+ def testGetsHintsFromNamedGroup(self):
+ self.checkHints(
+ ["/"], r"(?P<date>[0-3][0-9]/[0-1][0-9]/[1-2][0-9]{3})")
+

class ShortlistTests(unittest.TestCase):
def checkShortlist(self, expected_shortlist, hints):

Reply all
Reply to author
Forward
0 new messages