Changeset 496

Show
Ignore:
Timestamp:
01/02/08 06:01:56 (1 year ago)
Author:
athomas
Message:

Clarify user_context docs with another example.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cly/trunk/doc/developers-guide.rst

    r492 r496  
    499499parameter. 
    500500 
     501.. code-block:: python 
     502  from cly import * 
     503 
     504  def echo(context): 
     505    print context 
     506 
     507  grammar = Grammar(one=Node(Action(with_user_context=True, callback=echo))) 
     508 
     509  my_context = 'hi' 
     510  parser = Parser(grammar) 
     511  parser.execute('one', user_context=my_context) 
     512 
     513Will print:: 
     514 
     515  hi 
     516 
     517 
    501518One way of applying this is by binding all callbacks to methods on a 
    502519single *class*, then passing an instance of that class as the context: