Changeset 564

Show
Ignore:
Timestamp:
07/12/08 00:49:49 (5 months ago)
Author:
athomas
Message:

Allow custom Context classes to be used with the Parser.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cly/trunk/cly/parser.py

    r562 r564  
    276276        :grammar: Grammar to parse with. 
    277277        :data: User data to attach to Context. 
     278        :context_factory: A callable used to create new :class:`Context` 
     279                          objects. 
    278280    """ 
    279     def __init__(self, grammar, data=None): 
     281    def __init__(self, grammar, data=None, context_factory=None): 
    280282        """Construct a new Parser.""" 
    281283        self.grammar = grammar 
    282284        self.data = data 
    283285        self.labels = self._collect_labels() 
     286        self.context_factory = context_factory 
    284287 
    285288    def _set_grammar(self, grammar): 
     
    321324        if data is None: 
    322325            data = self.data 
    323         context = Context(self, command, data) 
     326        context = self.context_factory(self, command, data) 
    324327 
    325328        def parse(node, match):