Changeset 488

Show
Ignore:
Timestamp:
12/25/07 22:59:57 (1 year ago)
Author:
athomas
Message:

cly: Add equivalent XML grammars to the tutorial.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cly/trunk/doc/tutorial.rst

    r484 r488  
    1515commands ``cat`` and ``quit``. ``cat`` will have full tab completion of files 
    1616and directories. 
     17 
     18Finally, following each example using `cly.builder` will be the equivalent 
     19XML grammar. Simply replace: 
     20 
     21.. code-block:: python 
     22    
     23    grammar = Grammar(...) 
     24     
     25with: 
     26 
     27.. code-block:: python 
     28    
     29   grammar = Grammar.from_xml(xml, **locals()) 
    1730 
    1831Step One - Fundamentals 
     
    7083 
    7184    interact(grammar) 
     85 
     86Here's the equivalent XML grammar: 
     87 
     88.. code-block:: xml 
     89 
     90    <?xml version="1.0"?> 
     91    <grammar> 
     92      <node name="quit" help="Quit"> 
     93        <action callback="do_quit" help="Quit"/> 
     94      </node> 
     95    </grammar> 
    7296 
    7397**Note:** The apparent redundancy of having two *Quit* nodes is explained 
     
    119143    interact(grammar) 
    120144 
     145Here's the equivalent grammar as XML: 
     146 
     147.. code-block:: xml 
     148 
     149    <?xml version="1.0"?> 
     150    <grammar> 
     151      <node name="quit" help="Quit"> 
     152        <action callback="do_quit" help="Quit"/> 
     153      </node> 
     154      <node name="cat" help="Concatenate files"> 
     155        <variable name="file" help="File to concatenate" pattern="\S+"> 
     156          <action callback="do_cat" help="Concatenate files"/> 
     157        </variable> 
     158      </node> 
     159    </grammar> 
     160 
    121161Step Five - Recursion 
    122162--------------------- 
     
    160200parent node, whose absolute path is ``/cat/files``. 
    161201 
     202The equivalent XML grammar: 
     203 
     204.. code-block:: xml 
     205 
     206    <?xml version="1.0"?> 
     207    <grammar> 
     208      <node name="quit" help="Quit"> 
     209        <action callback="do_quit" help="Quit"/> 
     210      </node> 
     211      <node name="cat" help="Concatenate files"> 
     212        <variable name="file" help="File to concatenate" pattern="\S+" traversals="0"> 
     213          <action callback="do_cat" help="Concatenate files"/> 
     214          <alias target=".."/> 
     215        </variable> 
     216      </node> 
     217    </grammar> 
     218 
    162219Step Six - Completion 
    163220--------------------- 
     
    200257returns the IP as a tuple of integers. 
    201258 
     259And here is the XML grammar: 
     260 
     261.. code-block:: xml 
     262 
     263    <?xml version="1.0"?> 
     264    <grammar> 
     265      <node name="quit" help="Quit"> 
     266        <action callback="do_quit" help="Quit"/> 
     267      </node> 
     268      <node name="cat" help="Concatenate files"> 
     269        <file name="files" help="File to concatenate" traversals="0"> 
     270          <action callback="do_cat" help="Concatenate files"/> 
     271          <alias target=".."/> 
     272        </variable> 
     273      </node> 
     274    </grammar> 
     275 
    202276Conclusion 
    203277----------