Permalink
Browse files

have parser deal with bracket nesting correctly. doh.

  • Loading branch information...
1 parent 154783c commit 0f713a8b8e5ab9f6cc369395d38f9b126a36f8f4 @dbasden committed Sep 7, 2011
Showing with 14 additions and 5 deletions.
  1. +14 −5 digraphtools/predicate.py
View
@@ -153,11 +153,12 @@ def parse(self, tokens):
l,part,r = partition_list(tokens, '(')
if part != None:
if ')' in l: raise ParseSyntaxError('unmatched ) near',tokens)
- r.reverse()
- r,part,inner = partition_list(r,')')
- if part == None: raise ParseSyntaxError('unmatched ( near',tokens)
- r.reverse()
- inner.reverse()
+ r.insert(0,'(')
+ rindex = self._match_bracket(r, 0)
+ if rindex is None: raise ParseSyntaxError('unmatched ( near',tokens)
+ assert r[rindex] == ')'
+ inner = r[1:rindex]
+ r = r[rindex+1:]
inner = self.brackets(self.parse(inner))
return self.parse(l+[inner]+r)
@@ -325,6 +326,14 @@ def predicate_factory_sample():
assert allof2('-abc-')
assert not_anyof2('12345')
+ pred = pf.predicate_from_string('( a | b | c ) & ( c | e | d )')
+ assert not pred('b')
+ assert pred('c')
+ assert pred('cd')
+ assert pred('acd')
+ assert not pred('ab')
+ assert not pred('a')
+
parser_internal_test()
defer_sample()
predicate_sample()

0 comments on commit 0f713a8

Please sign in to comment.