Changeset 572
- Timestamp:
- 07/14/08 02:29:32 (2 months ago)
- Files:
-
- cly/trunk/cly/builder.py (modified) (3 diffs)
- cly/trunk/cly/exceptions.py (modified) (1 diff)
- cly/trunk/cly/parser.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cly/trunk/cly/builder.py
r571 r572 38 38 __docformat__ = 'restructuredtext en' 39 39 40 41 40 class Node(object): 42 41 """The base class for all grammar nodes. … … 121 120 traversals = 1 122 121 label = None 122 context = None 123 123 124 124 def __init__(self, *anonymous, **kwargs): … … 1125 1125 return eval(attr, locals) 1126 1126 except Exception, e: 1127 e.args = e.args + ('while parsing "%s"' % attr,) 1128 raise 1127 raise EvaluationError(error=e, expression=repr(attr)) 1129 1128 return attr_evaluator 1130 1129 cly/trunk/cly/exceptions.py
r481 r572 79 79 80 80 81 class EvaluationError(Error): 82 """An error ocurred while evaluating a Python expression.""" 83 message = '$error occurred while parsing $expression' 84 85 81 86 if __name__ == '__main__': 82 87 import doctest cly/trunk/cly/parser.py
r567 r572 330 330 context = self.context_factory(self, command, data) 331 331 332 def parse(node, match): 333 context.trail.append((node, match)) 334 if match is not None: 335 node.advance(context) 336 node.selected(context, match) 337 338 for subnode in node.next(context): 339 if subnode.valid(context): 340 submatch = subnode.match(context) 341 if submatch is not None: 342 return parse(subnode, submatch) 343 else: 344 return 345 raise InvalidToken(context) 346 347 parse(self.grammar, None) 348 return context 332 # Set context on all nodes in the grammar 333 for node in self.grammar.walk(): 334 node.context = self 335 336 try: 337 def parse(node, match): 338 context.trail.append((node, match)) 339 if match is not None: 340 node.advance(context) 341 node.selected(context, match) 342 343 for subnode in node.next(context): 344 if subnode.valid(context): 345 submatch = subnode.match(context) 346 if submatch is not None: 347 return parse(subnode, submatch) 348 else: 349 return 350 raise InvalidToken(context) 351 352 parse(self.grammar, None) 353 return context 354 finally: 355 # Unset context on grammar 356 for node in self.grammar.walk(): 357 node.context = None 349 358 350 359 def merge(self, where, grammar):
