git @ Cat's Eye Technologies Eightebed / 2889f8f
Incorporate latest version of rooibos. Cat's Eye Technologies 12 years ago
1 changed file(s) with 12 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
11
22 """
33 Rooibos, a parser combinator module for Python.
4
5 Written by Chris Pressey of Cat's Eye Technologies.
6 This work is hereby placed in the public domain.
47 """
58
69 import re
9396 has_match = True
9497 while has_match:
9598 has_match = False
96
9799 has_ignore = True
100
98101 while has_ignore:
99102 has_ignore = False
100103 for pattern in self.ignoring:
110113 self.text = self.text[result.end():]
111114 has_match = True
112115 break
116
113117 if has_match:
114118 if meta is not None:
115119 yield meta, result.group()
174178 yield x
175179
176180 def __repr__(self):
177 return "PredicateSet(%s)" % repr(self._set)
181 return "PredicateSet(%r)" % self._set
178182
179183
180184 ### Productions ###
435439 """Container for a set of named productions.
436440
437441 >>> g = Grammar()
438 >>> g['Expr'] = Sequence(Terminal('('),Asteration(Terminal('*')),
439 ... Terminal(')'))
442 >>> g['Expr'] = Sequence(
443 ... Terminal('('),Asteration(Terminal('*')),Terminal(')'))
440444 >>> g.parse('Expr', Stream(['(','*','*',')']))
441445 ['(', ['*', '*'], ')']
442 >>> g['Expr'] = Sequence(Terminal('('),Asteration(NonTerminal('Expr')),
443 ... Terminal(')'))
446 >>> g['Expr'] = Sequence(
447 ... Terminal('('),Asteration(NonTerminal('Expr')),Terminal(')'))
444448 >>> g.parse('Expr', Stream(['(',')']))
445449 ['(', [], ')']
446450 >>> s = Stream(['(','(',')',')'])
466470 elif self.parent:
467471 return self.parent[key]
468472 else:
469 raise KeyError("No production '%s' in grammar, "
470 "and no parent grammar" % key)
473 raise KeyError("No production '%s' in grammar, and "
474 "no parent grammar" % key)
471475
472476 def __setitem__(self, key, value):
473477 self.productions[key] = value