Incorporate latest version of rooibos.
Cat's Eye Technologies
12 years ago
1 | 1 | |
2 | 2 | """ |
3 | 3 | 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. | |
4 | 7 | """ |
5 | 8 | |
6 | 9 | import re |
93 | 96 | has_match = True |
94 | 97 | while has_match: |
95 | 98 | has_match = False |
96 | ||
97 | 99 | has_ignore = True |
100 | ||
98 | 101 | while has_ignore: |
99 | 102 | has_ignore = False |
100 | 103 | for pattern in self.ignoring: |
110 | 113 | self.text = self.text[result.end():] |
111 | 114 | has_match = True |
112 | 115 | break |
116 | ||
113 | 117 | if has_match: |
114 | 118 | if meta is not None: |
115 | 119 | yield meta, result.group() |
174 | 178 | yield x |
175 | 179 | |
176 | 180 | def __repr__(self): |
177 | return "PredicateSet(%s)" % repr(self._set) | |
181 | return "PredicateSet(%r)" % self._set | |
178 | 182 | |
179 | 183 | |
180 | 184 | ### Productions ### |
435 | 439 | """Container for a set of named productions. |
436 | 440 | |
437 | 441 | >>> g = Grammar() |
438 | >>> g['Expr'] = Sequence(Terminal('('),Asteration(Terminal('*')), | |
439 | ... Terminal(')')) | |
442 | >>> g['Expr'] = Sequence( | |
443 | ... Terminal('('),Asteration(Terminal('*')),Terminal(')')) | |
440 | 444 | >>> g.parse('Expr', Stream(['(','*','*',')'])) |
441 | 445 | ['(', ['*', '*'], ')'] |
442 | >>> g['Expr'] = Sequence(Terminal('('),Asteration(NonTerminal('Expr')), | |
443 | ... Terminal(')')) | |
446 | >>> g['Expr'] = Sequence( | |
447 | ... Terminal('('),Asteration(NonTerminal('Expr')),Terminal(')')) | |
444 | 448 | >>> g.parse('Expr', Stream(['(',')'])) |
445 | 449 | ['(', [], ')'] |
446 | 450 | >>> s = Stream(['(','(',')',')']) |
466 | 470 | elif self.parent: |
467 | 471 | return self.parent[key] |
468 | 472 | 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) | |
471 | 475 | |
472 | 476 | def __setitem__(self, key, value): |
473 | 477 | self.productions[key] = value |