1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html40/loose.dtd">
<html>
<head>
<title>Module: utils</title>
</head>
<body bgcolor="#ffffff">
<p><i><a href="../../../index.html">Table of Contents</a></i></p>
<table border="0" cellpadding="5" cellspacing="0" width="100%">
<tr>
<th rowspan="2"
valign="top"
align="left"
width="10%"
bgcolor="#88bbee"><font color="#000000">Module: utils</font>
</th>
<th bgcolor="#88bbee"
width="90%"
align="right"><font color="#000000">../HappyDoc-r2_1/happydoclib/parseinfo/utils.py</font>
</th>
</tr>
<tr>
<td>
<p>Utility functions for parseinfo package.</p>
<table border="0" cellpadding="5" cellspacing="0" width="100%">
<tr>
<th bgcolor="#99ccff"
rowspan="2"
valign="top"
align="left"
width="20%"
>
<font color="#000000">
<a name="Imported modules">Imported modules</a>
</font>
</th>
<th bgcolor="#99ccff"
valign="top"
align="left"
width="80%"
>
<font color="#000000"> </font>
</th>
</tr>
<tr>
<td>
<b>import</b> <a href="http://www.python.org/doc/current/lib/module-pprint.html">pprint</a><br>
<b>import</b> <a href="http://www.python.org/doc/current/lib/module-symbol.html">symbol</a><br>
<b>import</b> <a href="http://www.python.org/doc/current/lib/module-token.html">token</a><br>
<b>import</b> <a href="http://www.python.org/doc/current/lib/module-types.html">types</a><br>
</td></tr>
<tr>
<th bgcolor="#99ccff"
rowspan="2"
valign="top"
align="left"
width="20%"
>
<font color="#000000">
<a name="Functions">Functions</a>
</font>
</th>
<th bgcolor="#99ccff"
valign="top"
align="left"
width="80%"
>
<font color="#000000"> </font>
</th>
</tr>
<tr>
<td>
<a href="#drill">drill</a><br>
<a href="#findNode">findNode</a><br>
<a href="#joinCodeSnippets">joinCodeSnippets</a><br>
<a href="#lenientMatch">lenientMatch</a><br>
<a href="#match">match</a><br>
<a href="#parseTreeToString">parseTreeToString</a><br>
<tr>
<th bgcolor="#99ccff"
rowspan="2"
valign="top"
align="left"
width="20%"
>
<font color="#000000">
<a name="drill"></a>
</font>
</th>
<th bgcolor="#99ccff"
valign="top"
align="left"
width="80%"
>
<font color="#000000">drill </font>
</th>
</tr>
<tr>
<td>
<font color="#000088"><pre>
drill ( tree, depth )
</pre></font>
<p>Return the section of the parse <code>tree</code> that is <code>depth</code> nodes deep.</p>
<tr>
<th bgcolor="#99ccff"
rowspan="2"
valign="top"
align="left"
width="20%"
>
<font color="#000000">
<a name="findNode"></a>
</font>
</th>
<th bgcolor="#99ccff"
valign="top"
align="left"
width="80%"
>
<font color="#000000">findNode </font>
</th>
</tr>
<tr>
<td>
<font color="#000088"><pre>
findNode (
tree,
node,
response=None,
)
</pre></font>
<p>Return a sequence of subtrees starting with node value of <code>node</code>.</p>
<tr>
<th bgcolor="#99ccff"
rowspan="2"
valign="top"
align="left"
width="20%"
>
<font color="#000000">
<a name="joinCodeSnippets"></a>
</font>
</th>
<th bgcolor="#99ccff"
valign="top"
align="left"
width="80%"
>
<font color="#000000">joinCodeSnippets </font>
</th>
</tr>
<tr>
<td>
<font color="#000088"><pre>
joinCodeSnippets (
first,
second,
separator,
)
</pre></font>
<h3>Join two code snippets into one string.</h3>
<p> Use some general code content rules to try to make the
resulting snippet look nice.</p>
<tr>
<th bgcolor="#99ccff"
rowspan="2"
valign="top"
align="left"
width="20%"
>
<font color="#000000">
<a name="lenientMatch"></a>
</font>
</th>
<th bgcolor="#99ccff"
valign="top"
align="left"
width="80%"
>
<font color="#000000">lenientMatch </font>
</th>
</tr>
<tr>
<td>
<font color="#000088"><pre>
lenientMatch (
pattern,
data,
vars=None,
dbg=0,
)
</pre></font>
<h3>Match `data' to `pattern', with variable extraction.</h3>
<dl>
<dt> pattern</dt>
<dd>Pattern to match against, possibly containing variables.</dd>
<dt> data</dt>
<dd>Data to be checked and against which variables are extracted.</dd>
<dt> vars</dt>
<dd>Dictionary of variables which have already been found. If not
provided, an empty dictionary is created.</dd>
</dl>
<p> The `pattern' value may contain variables of the form ['varname'] which
are allowed to match anything. The value that is matched is returned as
part of a dictionary which maps <code>varname</code> to the matched value. <code>varname</code>
is not required to be a string object, but using strings makes patterns
and the code which uses them more readable.</p>
<p> This function is based on the match() function, but is more lenient.
The pattern does not have to completely describe the tree. Instead,
it can be the <code>top</code> portion of the tree. Everything must match down
to the leaves of the pattern. At that point, the matching stops. If
a match was found at all, the return values indicate a match.</p>
<p> This function returns two values: a boolean indicating whether a match
was found and a dictionary mapping variable names to their associated
values.</p>
<tr>
<th bgcolor="#99ccff"
rowspan="2"
valign="top"
align="left"
width="20%"
>
<font color="#000000">
<a name="match"></a>
</font>
</th>
<th bgcolor="#99ccff"
valign="top"
align="left"
width="80%"
>
<font color="#000000">match </font>
</th>
</tr>
<tr>
<td>
<font color="#000088"><pre>
match (
pattern,
data,
vars=None,
dbg=0,
)
</pre></font>
<h3>Match `data' to `pattern', with variable extraction.</h3>
<dl>
<dt> pattern</dt>
<dd>Pattern to match against, possibly containing variables.</dd>
<dt> data</dt>
<dd>Data to be checked and against which variables are extracted.</dd>
<dt> vars</dt>
<dd>Dictionary of variables which have already been found. If not
provided, an empty dictionary is created.</dd>
</dl>
<p> The `pattern' value may contain variables of the form ['varname'] which
are allowed to match anything. The value that is matched is returned as
part of a dictionary which maps <code>varname</code> to the matched value. <code>varname</code>
is not required to be a string object, but using strings makes patterns
and the code which uses them more readable.</p>
<p> This function returns two values: a boolean indicating whether a match
was found and a dictionary mapping variable names to their associated
values.</p>
<tr>
<th bgcolor="#99ccff"
rowspan="2"
valign="top"
align="left"
width="20%"
>
<font color="#000000">
<a name="parseTreeToString"></a>
</font>
</th>
<th bgcolor="#99ccff"
valign="top"
align="left"
width="80%"
>
<font color="#000000">parseTreeToString </font>
</th>
</tr>
<tr>
<td>
<font color="#000088"><pre>
parseTreeToString ( tree, separator=' ' )
</pre></font>
<h3>Convert a parse tree to a string which would have parsed in that way.</h3>
<p> Given a parse tree, walk it to determine the original string
which would have been parsed to produce that tree.</p>
</td></tr>
</td></tr>
</table>
</td>
</tr>
</table>
<hr>
<p><i><a href="../../../index.html">Table of Contents</a></i></p>
<font size="-2"><i>This document was automatically generated
on Sat Aug 24 16:57:40 2002 by
<a href="http://happydoc.sourceforge.net">HappyDoc</a> version
2.1</i></font>
</body>
</html>
|