Changeset 488
- Timestamp:
- 12/25/07 22:59:57 (1 year ago)
- Files:
-
- cly/trunk/doc/tutorial.rst (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cly/trunk/doc/tutorial.rst
r484 r488 15 15 commands ``cat`` and ``quit``. ``cat`` will have full tab completion of files 16 16 and directories. 17 18 Finally, following each example using `cly.builder` will be the equivalent 19 XML grammar. Simply replace: 20 21 .. code-block:: python 22 23 grammar = Grammar(...) 24 25 with: 26 27 .. code-block:: python 28 29 grammar = Grammar.from_xml(xml, **locals()) 17 30 18 31 Step One - Fundamentals … … 70 83 71 84 interact(grammar) 85 86 Here'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> 72 96 73 97 **Note:** The apparent redundancy of having two *Quit* nodes is explained … … 119 143 interact(grammar) 120 144 145 Here'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 121 161 Step Five - Recursion 122 162 --------------------- … … 160 200 parent node, whose absolute path is ``/cat/files``. 161 201 202 The 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 162 219 Step Six - Completion 163 220 --------------------- … … 200 257 returns the IP as a tuple of integers. 201 258 259 And 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 202 276 Conclusion 203 277 ----------
