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
|
<HTML>
<title>pyparsing Examples</title>
<body>
<h1>pyparsing Examples</h1>
<p>
This directory contains a number of Python scripts that can get you started in learning to use pyparsing.
<ul>
<li><a href="greeting.py">greeting.py</a><br>
Parse "Hello, World!".
</li>
<p>
<li><a href="greetingInKorean.py">greetingInKorean.py</a> <i>~ submission by June Kim</i><br>
Unicode example to parse "Hello, World!" in Korean.
</li>
<p>
<li><a href="greetingInGreek.py">greetingInGreek.py</a> <i>~ submission by ???</i><br>
Unicode example to parse "Hello, World!" in Greek.
</li>
<p>
<li><a href="holaMundo.py">holaMundo.py</a> <i>~ submission by Marco Alfonso</i><br>
"Hello, World!" example translated to Spanish, from Marco Alfonso's blog.
</li>
<p>
<li><a href="chemicalFormulas.py">chemicalFormulas.py</a><br>
Simple example to demonstrate the use of ParseResults returned from parseString().
Parses a chemical formula (such as "H2O" or "C6H5OH"), and walks the returned list of tokens to calculate the molecular weight.
</li>
<p>
<li><a href="wordsToNum.py">wordsToNum.py</a><br>
A sample program that reads a number in words (such as "fifteen hundred and sixty four"), and returns the actual number (1564).
Also demonstrates some processing of ParseExceptions, including marking where the parse failure was found.
</li>
<p>
<li><a href="pythonGrammarparser.py">pythonGrammarparser.py</a> <i>~ suggested by JH Stovall</i><br>
A sample program that parses the EBNF used in the Python source code to define the Python grammar. From this parser,
one can generate Python grammar documentation tools, such as railroad track diagrams. Also demonstrates use of
Dict class.
</li>
<p>
<li><a href="commasep.py">commasep.py</a><br>
Demonstration of the use of the commaSeparatedList helper. Shows examples of
proper handling of commas within quotes, trimming of whitespace around delimited entries, and handling of consecutive commas (null arguments). Includes comparison with simple string.split(',').
</li>
<p>
<li><a href="dictExample.py">dictExample.py</a><br>
A demonstration of using the Dict class, to parse a table of ASCII tabulated data.
</li>
<p>
<li><a href="dictExample2.py">dictExample2.py</a> <i>~ submission by Mike Kelly</i><br>
An extended version of dictExample.py, in which Mike Kelly also parses the column headers, and generates a transposed version of the original table!
</li>
<p>
<li><a href="scanExamples.py">scanExamples.py</a><br>
Some examples of using scanString and transformString, as alternative parsing methods to parseString, to do macro substitution, and selection and/or removal of matching strings within a source file.
</li>
<p>
<li><a href="urlExtractor.py">urlExtractor.py</a><br>
Another example using scanString, this time to extract all HREF references found on Yahoo!'s home page, and return them as a dictionary.
</li>
<p>
<li><a href="makeHTMLTagExample.py">makeHTMLTagExample.py</a><br>
A sample program showing sample definitions and applications of HTML tag expressions
created using makeHTMLTags helper function. Very useful for scraping data from HTML pages.
</li>
<p>
<li><a href="urlExtractorNew.py">urlExtractorNew.py</a><br>
Another updated version of urlExtractor.py, using the new makeHTMLTags() method.
</li>
<p>
<li><a href="fourFn.py">fourFn.py</a><br>
A simple algebraic expression parser, that performs +,-,*,/, and ^ arithmetic operations. (With suggestions and bug-fixes graciously offered by Andrea Griffini.)
</li>
<p>
<li><a href="SimpleCalc.py">SimpleCalc.py</a> <i>~ submission by Steven Siew</i><br>
An interactive version of fourFn.py, with support for variables.
</li>
<p>
<li><a href="LAParser.py">LAParser.py</a> <i>~ submission by Mike Ellis</i><br>
An interactive Linear Algebra Parser, an extension of SimpleCalc.py. Supports linear algebra (LA) notation for vectors, matrices, and scalars,
including matrix operations such as inversion and determinants. Converts LA expressions to C code - uses a separate C library for runtime
evaluation of results.
</li>
<p>
<li><a href="configParse.py">configParse.py</a><br>
A simple alternative to Python's ConfigParse module, demonstrating the use of the Dict class to return nested dictionary access to configuration values.
</li>
<p>
<li><a href="getNTPservers.py">getNTPservers.py</a><br>
Yet another scanString example, to read/extract the list of NTP servers from NIST's web site.
</li>
<p>
<li><a href="getNTPserversNew.py">getNTPserversNew.py</a><br>
An updated version of getNTPservers.py, using the new makeHTMLTags() method.
</li>
<p>
<li><a href="httpServerLogParser.py">httpServerLogParser.py</a><br>
Parser for Apache server log files.
</li>
<p>
<li><a href="idlParse.py">idlParse.py</a><br>
Parser for CORBA IDL files.
</li>
<p>
<li><a href="mozillaCalendarParser.py">mozillaCalendarParser.py</a>
<i>~ submission by Petri Savolainen</i><br>
Parser for Mozilla calendar (*.ics) files.
</li>
<p>
<li><a href="pgn.py">pgn.py</a> <i>~ submission by Alberto Santini</i><br>
Parser for PGN (Portable Game Notation) files, the standard form for documenting the moves in chess games.
</li>
<p>
<li><a href="simpleSQL.py">simpleSQL.py</a><br>
A simple parser that will extract table and column names from SQL SELECT statements..
</li>
<p>
<li><a href="dfmparse.py">dfmparse.py</a> <i>~ submission by Dan Griffith</i><br>
Parser for Delphi forms.
</li>
<p>
<li><a href="ebnf.py">ebnf.py / ebnftest.py</a> <i>~ submission by Seo Sanghyeon</i><br>
An EBNF-compiler that reads EBNF and generates a pyparsing grammar! Including a test that compiles... EBNF itself!
</li>
<p>
<li><a href="searchparser.py">searchparser.py</a> <i>~ submission by Steven Mooij and Rudolph Froger</i><br>
An expression parser that parses search strings, with special keyword and expression operations using (), not, and, or, and quoted strings.
</li>
<p>
<li><a href="sparser.py">sparser.py</a> <i>~ submission by Tim Cera</i><br>
A configurable parser module that can be configured with a list of tuples, giving a high-level definition for parsing common sets
of water table data files. Tim had to contend with several different styles of data file formats, each with slight variations of its own.
Tim created a configurable parser (or "SPECIFIED parser" - hence the name "sparser"), that simply works from a config variable listing
the field names and data types, and implicitly, their order in the source data file.
<p>
See <a href="mayport_florida_8720220_data_def.txt">mayport_florida_8720220_data_def.txt</a> for an
example configuration file.
</li>
<p>
<li><a href="romanNumerals.py">romanNumerals.py</a><br>
A Roman numeral generator and parser example, showing the power of parse actions
to compile Roman numerals into their integer values.
</li>
<p>
<li><a href="removeLineBreaks.py">removeLineBreaks.py</a><br>
A string transformer that converts text files with hard line-breaks into one with line breaks
only between paragraphs. Useful when converting downloads from
<a href="http://www.gutenberg.org">Project Gutenberg</a> to import to word processing apps
that can reformat paragraphs once hard line-breaks are removed, or for loading into your Palm Pilot for portable perusal.
<p>
See <a href="Successful Methods of Public Speaking.txt">Successful Methods of Public Speaking.txt</a> and
<a href="Successful Methods of Public Speaking(2).txt">Successful Methods of Public Speaking(2).txt</a> for a sample
before and after (text file courtesy of Project Gutenberg).
</li>
<p>
<li><a href="listAllMatches.py">listAllMatches.py</a><br>
An example program showing the utility of the listAllMatches option when specifying results naming.
</li>
<p>
<li><a href="linenoExample.py">linenoExample.py</a><br>
An example program showing how to use the string location to extract line and column numbers, or the
source line of text.
</li>
<p>
<li><a href="parseListString.py">parseListString.py</a><br>
An example program showing a progression of steps, how to parse a string representation of a Python
list back into a true list.
</li>
<p>
<li><a href="parsePythonValue.py">parsePythonValue.py</a><br>
An extension of parseListString.py to parse tuples and dicts, including nested values,
returning a Python value of the original type.
</li>
<p>
<li><a href="indentedGrammarExample.py">indentedGrammarExample.py</a><br>
An example program showing how to parse a grammar using indentation for grouping,
such as is done in Python.
</li>
<p>
<li><a href="simpleArith.py">simpleArith.py</a><br>
An example program showing how to use the new operatorPrecedence helper method to define a 6-function
(+, -, *, /, ^, and !) arithmetic expression parser, with unary plus and minus signs.
</li>
<p>
<li><a href="simpleBool.py">simpleBool.py</a><br>
An example program showing how to use the new operatorPrecedence helper method to define a
boolean expression parser, with parse actions associated with each operator to "compile" the expression
into a data structure that will evaluate the expression's boolean value.
</li>
<p>
<li><a href="simpleWiki.py">simpleWiki.py</a><br>
An example program showing how to use transformString to implement a simple Wiki markup parser.
</li>
<p>
<li><a href="sql2dot.py">sql2dot.py</a><i>~ submission by EnErGy [CSDX]</i><br>
A nice graphing program that generates schema diagrams from SQL table definition statements.
</li>
<p>
<li><a href="htmlStripper.py">htmlStripper.py</a><br>
An example implementation of a common application, removing HTML markup tags from an HTML page,
leaving just the text content.
</li>
<p>
<li><a href="macroExpansion.py">macroExpansion.py</a><br>
An example implementation of a simple preprocessor, that will read embedded macro definitions
and replace macro references with the defined substitution string.
</li>
<p>
<li><a href="sexpParser.py">sexpParser.py</a><br>
A parser that uses a recursive grammar to parse S-expressions.
</li>
<p>
<li><a href="nested.py">nested.py</a><br>
An example using nestedExpr, a helper method to simplify definitions of expressions of nested lists.
</li>
<p>
<li><a href="withAttribute.py">withAttribute.py</a><br>
An example using withAttribute, a helper method to define parse actions to validate matched HTML tags
using additional attributes. Especially helpful for matching common tags such as <DIV> and <TD>.
</li>
<p>
<li><a href="stackish.py">stackish.py</a><br>
A parser for the data representation format, Stackish.
</li>
<p>
<li><a href="builtin_parse_action_demo.py">builtin_parse_action_demo.py</a><br>
<b>New in version 1.5.7</b><br>
Demonstration of using builtins (min, max, sum, len, etc.) as parse actions.
</li>
<p>
<li><a href="antlr_grammar.py">antlr_grammar.py</a><i>~ submission by Luca DellOlio</i><br>
<b>New in version 1.5.7</b><br>
Pyparsing example parsing ANTLR .a files and generating a working pyparsing parser.
</li>
<p>
<li><a href="shapes.py">shapes.py</a><br>
<b>New in version 1.5.7</b><br>
Parse actions example simple shape definition syntax, and returning the matched tokens as
domain objects instead of just strings.
</li>
<p>
<li><a href="datetimeParseActions.py">datetimeParseActions.py</a><br>
<b>New in version 1.5.7</b><br>
Parse actions example showing a parse action returning a datetime object instead of
string tokens, and doing validation of the tokens, raising a ParseException if the
given YYYY/MM/DD string does not represent a valid date.
</li>
<p>
<li><a href="position.py">position.py</a><br>
<b>New in version 1.5.7</b><br>
Demonstration of a couple of different ways to capture the location a particular
expression was found within the overall input string.
</li>
<p>
</ul>
</body></html>
|