parsimonius 0.11.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2012 Erik Rose
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,653 @@
1
+ Metadata-Version: 2.5
2
+ Name: parsimonius
3
+ Version: 0.11.0
4
+ Summary: (Soon to be) the fastest pure-Python PEG parser I could muster
5
+ Project-URL: Homepage, https://github.com/erikrose/parsimonius
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Keywords: grammar,language,packrat,parse,parser,parsing,peg
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Natural Language :: English
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
22
+ Classifier: Topic :: Software Development :: Libraries
23
+ Classifier: Topic :: Text Processing :: General
24
+ Requires-Python: <3.15,>=3.10
25
+ Requires-Dist: aiogram>=3.27.0
26
+ Requires-Dist: aiohttp>=3.13.5
27
+ Requires-Dist: regex>=2022.3.15
28
+ Provides-Extra: testing
29
+ Requires-Dist: pytest; extra == 'testing'
30
+ Description-Content-Type: text/x-rst
31
+
32
+ ============
33
+ Parsimonius
34
+ ============
35
+
36
+ Parsimonius aims to be the fastest arbitrary-lookahead parser written in pure
37
+ Python—and the most usable. It's based on parsing expression grammars (PEGs),
38
+ which means you feed it a simplified sort of EBNF notation. Parsimonius was
39
+ designed to undergird a MediaWiki parser that wouldn't take 5 seconds or a GB
40
+ of RAM to do one page, but it's applicable to all sorts of languages.
41
+
42
+ :Code: https://github.com/erikrose/parsimonius/
43
+ :Issues: https://github.com/erikrose/parsimonius/issues
44
+ :License: MIT License (MIT)
45
+ :Package: https://pypi.org/project/parsimonius/
46
+
47
+
48
+ Goals
49
+ =====
50
+
51
+ * Speed
52
+ * Frugal RAM use
53
+ * Minimalistic, understandable, idiomatic Python code
54
+ * Readable grammars
55
+ * Extensible grammars
56
+ * Complete test coverage
57
+ * Separation of concerns. Some Python parsing kits mix recognition with
58
+ instructions about how to turn the resulting tree into some kind of other
59
+ representation. This is limiting when you want to do several different things
60
+ with a tree: for example, render wiki markup to HTML *or* to text.
61
+ * Good error reporting. I want the parser to work *with* me as I develop a
62
+ grammar.
63
+
64
+
65
+ Install
66
+ =======
67
+
68
+ To install Parsimonius, run::
69
+
70
+ $ pip install parsimonius
71
+
72
+
73
+ Example Usage
74
+ =============
75
+
76
+ Here's how to build a simple grammar:
77
+
78
+ .. code:: python
79
+
80
+ >>> from parsimonius.grammar import Grammar
81
+ >>> grammar = Grammar(
82
+ ... """
83
+ ... bold_text = bold_open text bold_close
84
+ ... text = ~"[A-Z 0-9]*"i
85
+ ... bold_open = "(("
86
+ ... bold_close = "))"
87
+ ... """)
88
+
89
+ You can have forward references and even right recursion; it's all taken care
90
+ of by the grammar compiler. The first rule is taken to be the default start
91
+ symbol, but you can override that.
92
+
93
+ Next, let's parse something and get an abstract syntax tree:
94
+
95
+ .. code:: python
96
+
97
+ >>> print(grammar.parse('((bold stuff))'))
98
+ <Node called "bold_text" matching "((bold stuff))">
99
+ <Node called "bold_open" matching "((">
100
+ <RegexNode called "text" matching "bold stuff">
101
+ <Node called "bold_close" matching "))">
102
+
103
+ You'd typically then use a ``nodes.NodeVisitor`` subclass (see below) to walk
104
+ the tree and do something useful with it.
105
+
106
+ Another example would be to implement a parser for ``.ini``-files. Consider the following:
107
+
108
+ .. code:: python
109
+
110
+ grammar = Grammar(
111
+ r"""
112
+ expr = (entry / emptyline)*
113
+ entry = section pair*
114
+
115
+ section = lpar word rpar ws
116
+ pair = key equal value ws?
117
+
118
+ key = word+
119
+ value = (word / quoted)+
120
+ word = ~r"[-\w]+"
121
+ quoted = ~'"[^\"]+"'
122
+ equal = ws? "=" ws?
123
+ lpar = "["
124
+ rpar = "]"
125
+ ws = ~r"\s*"
126
+ emptyline = ws+
127
+ """
128
+ )
129
+
130
+
131
+ We could now implement a subclass of ``NodeVisitor`` like so:
132
+
133
+ .. code:: python
134
+
135
+ class IniVisitor(NodeVisitor):
136
+ def visit_expr(self, node, visited_children):
137
+ """ Returns the overall output. """
138
+ output = {}
139
+ for child in visited_children:
140
+ output.update(child[0])
141
+ return output
142
+
143
+ def visit_entry(self, node, visited_children):
144
+ """ Makes a dict of the section (as key) and the key/value pairs. """
145
+ key, values = visited_children
146
+ return {key: dict(values)}
147
+
148
+ def visit_section(self, node, visited_children):
149
+ """ Gets the section name. """
150
+ _, section, *_ = visited_children
151
+ return section.text
152
+
153
+ def visit_pair(self, node, visited_children):
154
+ """ Gets each key/value pair, returns a tuple. """
155
+ key, _, value, *_ = node.children
156
+ return key.text, value.text
157
+
158
+ def generic_visit(self, node, visited_children):
159
+ """ The generic visit method. """
160
+ return visited_children or node
161
+
162
+ And call it like that:
163
+
164
+ .. code:: python
165
+
166
+ from parsimonius.grammar import Grammar
167
+ from parsimonius.nodes import NodeVisitor
168
+
169
+ data = """[section]
170
+ somekey = somevalue
171
+ someotherkey=someothervalue
172
+
173
+ [anothersection]
174
+ key123 = "what the heck?"
175
+ key456="yet another one here"
176
+
177
+ """
178
+
179
+ tree = grammar.parse(data)
180
+
181
+ iv = IniVisitor()
182
+ output = iv.visit(tree)
183
+ print(output)
184
+
185
+ This would yield
186
+
187
+ .. code:: python
188
+
189
+ {'section': {'somekey': 'somevalue', 'someotherkey': 'someothervalue'}, 'anothersection': {'key123': '"what the heck?"', 'key456': '"yet another one here"'}}
190
+
191
+ Status
192
+ ======
193
+
194
+ * Everything that exists works. Test coverage is good.
195
+ * I don't plan on making any backward-incompatible changes to the rule syntax
196
+ in the future, so you can write grammars with confidence.
197
+ * It may be slow and use a lot of RAM; I haven't measured either yet. However,
198
+ I have yet to begin optimizing in earnest.
199
+ * Error reporting is now in place. ``repr`` methods of expressions, grammars,
200
+ and nodes are clear and helpful as well. The ``Grammar`` ones are
201
+ even round-trippable!
202
+ * The grammar extensibility story is underdeveloped at the moment. You should
203
+ be able to extend a grammar by simply concatenating more rules onto the
204
+ existing ones; later rules of the same name should override previous ones.
205
+ However, this is untested and may not be the final story.
206
+ * Sphinx docs are coming, but the docstrings are quite useful now.
207
+ * Note that there may be API changes until we get to 1.0, so be sure to pin to
208
+ the version you're using.
209
+
210
+ Coming Soon
211
+ -----------
212
+
213
+ * Optimizations to make Parsimonius worthy of its name
214
+ * Tighter RAM use
215
+ * Better-thought-out grammar extensibility story
216
+ * Amazing grammar debugging
217
+
218
+
219
+ A Little About PEG Parsers
220
+ ==========================
221
+
222
+ PEG parsers don't draw a distinction between lexing and parsing; everything is
223
+ done at once. As a result, there is no lookahead limit, as there is with, for
224
+ instance, Yacc. And, due to both of these properties, PEG grammars are easier
225
+ to write: they're basically just a more practical dialect of EBNF. With
226
+ caching, they take O(grammar size * text length) memory (though I plan to do
227
+ better), but they run in O(text length) time.
228
+
229
+ More Technically
230
+ ----------------
231
+
232
+ PEGs can describe a superset of *LL(k)* languages, any deterministic *LR(k)*
233
+ language, and many others—including some that aren't context-free
234
+ (http://www.brynosaurus.com/pub/lang/peg.pdf). They can also deal with what
235
+ would be ambiguous languages if described in canonical EBNF. They do this by
236
+ trading the ``|`` alternation operator for the ``/`` operator, which works the
237
+ same except that it makes priority explicit: ``a / b / c`` first tries matching
238
+ ``a``. If that fails, it tries ``b``, and, failing that, moves on to ``c``.
239
+ Thus, ambiguity is resolved by always yielding the first successful recognition.
240
+
241
+
242
+ Writing Grammars
243
+ ================
244
+
245
+ Grammars are defined by a series of rules. The syntax should be familiar to
246
+ anyone who uses regexes or reads programming language manuals. An example will
247
+ serve best:
248
+
249
+ .. code:: python
250
+
251
+ my_grammar = Grammar(r"""
252
+ styled_text = bold_text / italic_text
253
+ bold_text = "((" text "))"
254
+ italic_text = "''" text "''"
255
+ text = ~"[A-Z 0-9]*"i
256
+ """)
257
+
258
+ You can wrap a rule across multiple lines if you like; the syntax is very
259
+ forgiving.
260
+
261
+ If you want to save your grammar into a separate file, you should name it using
262
+ ``.ppeg`` extension.
263
+
264
+
265
+ Syntax Reference
266
+ ----------------
267
+
268
+ ==================== ========================================================
269
+ ``"some literal"`` Used to quote literals. Backslash escaping and Python
270
+ conventions for "raw" and Unicode strings help support
271
+ fiddly characters.
272
+
273
+ ``b"some literal"`` A bytes literal. Using bytes literals and regular
274
+ expressions allows your grammar to parse binary files.
275
+ Note that all literals and regular expressions must be
276
+ of the same type within a grammar. In grammars that
277
+ process bytestrings, you should make the grammar string
278
+ an ``r"""string"""`` so that byte literals like ``\xff``
279
+ work correctly.
280
+
281
+ [space] Sequences are made out of space- or tab-delimited
282
+ things. ``a b c`` matches spots where those 3
283
+ terms appear in that order.
284
+
285
+ ``a / b / c`` Alternatives. The first to succeed of ``a / b / c``
286
+ wins.
287
+
288
+ ``thing?`` An optional expression. This is greedy, always consuming
289
+ ``thing`` if it exists.
290
+
291
+ ``&thing`` A lookahead assertion. Ensures ``thing`` matches at the
292
+ current position but does not consume it.
293
+
294
+ ``!thing`` A negative lookahead assertion. Matches if ``thing``
295
+ isn't found here. Doesn't consume any text.
296
+
297
+ ``things*`` Zero or more things. This is greedy, always consuming as
298
+ many repetitions as it can.
299
+
300
+ ``things+`` One or more things. This is greedy, always consuming as
301
+ many repetitions as it can.
302
+
303
+ ``~r"regex"ilmsuxa`` Regexes have ``~`` in front and are quoted like
304
+ literals. Any flags_ (``asilmx``) follow the end quotes
305
+ as single chars. Regexes are good for representing
306
+ character classes (``[a-z0-9]``) and optimizing for
307
+ speed. The downside is that they won't be able to take
308
+ advantage of our fancy debugging, once we get that
309
+ working. Ultimately, I'd like to deprecate explicit
310
+ regexes and instead have Parsimonius dynamically build
311
+ them out of simpler primitives. Parsimonius uses the
312
+ regex_ library instead of the built-in re module.
313
+
314
+ ``~br"regex"`` A bytes regex; required if your grammar parses
315
+ bytestrings.
316
+
317
+ ``(things)`` Parentheses are used for grouping, like in every other
318
+ language.
319
+
320
+ ``thing{n}`` Exactly ``n`` repetitions of ``thing``.
321
+
322
+ ``thing{n,m}`` Between ``n`` and ``m`` repititions (inclusive.)
323
+
324
+ ``thing{,m}`` At most ``m`` repetitions of ``thing``.
325
+
326
+ ``thing{n,}`` At least ``n`` repetitions of ``thing``.
327
+
328
+ ==================== ========================================================
329
+
330
+ .. _flags: https://docs.python.org/3/howto/regex.html#compilation
331
+ .. _regex: https://github.com/mrabarnett/mrab-regex
332
+
333
+ Optimizing Grammars
334
+ ===================
335
+
336
+ Don't Repeat Expressions
337
+ ------------------------
338
+
339
+ If you need a ``~"[a-z0-9]"i`` at two points in your grammar, don't type it
340
+ twice. Make it a rule of its own, and reference it from wherever you need it.
341
+ You'll get the most out of the caching this way, since cache lookups are by
342
+ expression object identity (for speed).
343
+
344
+ Even if you have an expression that's very simple, not repeating it will
345
+ save RAM, as there can, at worst, be a cached int for every char in the text
346
+ you're parsing. In the future, we may identify repeated subexpressions
347
+ automatically and factor them up while building the grammar.
348
+
349
+ How much should you shove into one regex, versus how much should you break them
350
+ up to not repeat yourself? That's a fine balance and worthy of benchmarking.
351
+ More stuff jammed into a regex will execute faster, because it doesn't have to
352
+ run any Python between pieces, but a broken-up one will give better cache
353
+ performance if the individual pieces are re-used elsewhere. If the pieces of a
354
+ regex aren't used anywhere else, by all means keep the whole thing together.
355
+
356
+
357
+ Quantifiers
358
+ -----------
359
+
360
+ Bring your ``?`` and ``*`` quantifiers up to the highest level you
361
+ can. Otherwise, lower-level patterns could succeed but be empty and put a bunch
362
+ of useless nodes in your tree that didn't really match anything.
363
+
364
+
365
+ Processing Parse Trees
366
+ ======================
367
+
368
+ A parse tree has a node for each expression matched, even if it matched a
369
+ zero-length string, like ``"thing"?`` might.
370
+
371
+ The ``NodeVisitor`` class provides an inversion-of-control framework for
372
+ walking a tree and returning a new construct (tree, string, or whatever) based
373
+ on it. For now, have a look at its docstrings for more detail. There's also a
374
+ good example in ``grammar.RuleVisitor``. Notice how we take advantage of nodes'
375
+ iterability by using tuple unpacks in the formal parameter lists:
376
+
377
+ .. code:: python
378
+
379
+ def visit_or_term(self, or_term, (slash, _, term)):
380
+ ...
381
+
382
+ For reference, here is the production the above unpacks::
383
+
384
+ or_term = "/" _ term
385
+
386
+ When something goes wrong in your visitor, you get a nice error like this::
387
+
388
+ [normal traceback here...]
389
+ VisitationException: 'Node' object has no attribute 'foo'
390
+
391
+ Parse tree:
392
+ <Node called "rules" matching "number = ~"[0-9]+""> <-- *** We were here. ***
393
+ <Node matching "number = ~"[0-9]+"">
394
+ <Node called "rule" matching "number = ~"[0-9]+"">
395
+ <Node matching "">
396
+ <Node called "label" matching "number">
397
+ <Node matching " ">
398
+ <Node called "_" matching " ">
399
+ <Node matching "=">
400
+ <Node matching " ">
401
+ <Node called "_" matching " ">
402
+ <Node called "rhs" matching "~"[0-9]+"">
403
+ <Node called "term" matching "~"[0-9]+"">
404
+ <Node called "atom" matching "~"[0-9]+"">
405
+ <Node called "regex" matching "~"[0-9]+"">
406
+ <Node matching "~">
407
+ <Node called "literal" matching ""[0-9]+"">
408
+ <Node matching "">
409
+ <Node matching "">
410
+ <Node called "eol" matching "
411
+ ">
412
+ <Node matching "">
413
+
414
+ The parse tree is tacked onto the exception, and the node whose visitor method
415
+ raised the error is pointed out.
416
+
417
+ Why No Streaming Tree Processing?
418
+ ---------------------------------
419
+
420
+ Some have asked why we don't process the tree as we go, SAX-style. There are
421
+ two main reasons:
422
+
423
+ 1. It wouldn't work. With a PEG parser, no parsing decision is final until the
424
+ whole text is parsed. If we had to change a decision, we'd have to backtrack
425
+ and redo the SAX-style interpretation as well, which would involve
426
+ reconstituting part of the AST and quite possibly scuttling whatever you
427
+ were doing with the streaming output. (Note that some bursty SAX-style
428
+ processing may be possible in the future if we use cuts.)
429
+
430
+ 2. It interferes with the ability to derive multiple representations from the
431
+ AST: for example, turning wiki markup into first HTML and then text.
432
+
433
+
434
+ Future Directions
435
+ =================
436
+
437
+ Rule Syntax Changes
438
+ -------------------
439
+
440
+ * Maybe support left-recursive rules like PyMeta, if anybody cares.
441
+ * Ultimately, I'd like to get rid of explicit regexes and break them into more
442
+ atomic things like character classes. Then we can dynamically compile bits
443
+ of the grammar into regexes as necessary to boost speed.
444
+
445
+ Optimizations
446
+ -------------
447
+
448
+ * Make RAM use almost constant by automatically inserting "cuts", as described
449
+ in
450
+ http://ialab.cs.tsukuba.ac.jp/~mizusima/publications/paste513-mizushima.pdf.
451
+ This would also improve error reporting, as we wouldn't backtrack out of
452
+ everything informative before finally failing.
453
+ * Find all the distinct subexpressions, and unify duplicates for a better cache
454
+ hit ratio.
455
+ * Think about having the user (optionally) provide some representative input
456
+ along with a grammar. We can then profile against it, see which expressions
457
+ are worth caching, and annotate the grammar. Perhaps there will even be
458
+ positions at which a given expression is more worth caching. Or we could keep
459
+ a count of how many times each cache entry has been used and evict the most
460
+ useless ones as RAM use grows.
461
+ * We could possibly compile the grammar into VM instructions, like in "A
462
+ parsing machine for PEGs" by Medeiros.
463
+ * If the recursion gets too deep in practice, use trampolining to dodge it.
464
+
465
+ Niceties
466
+ --------
467
+
468
+ * Pijnu has a raft of tree manipulators. I don't think I want all of them, but
469
+ a judicious subset might be nice. Don't get into mixing formatting with tree
470
+ manipulation.
471
+ https://github.com/erikrose/pijnu/blob/master/library/node.py#L333. PyPy's
472
+ parsing lib exposes a sane subset:
473
+ http://doc.pypy.org/en/latest/rlib.html#tree-transformations.
474
+
475
+
476
+ Version History
477
+ ===============
478
+
479
+ 0.11.0
480
+ * Correctly handle `/` expressions with multiple terms in a row. (lucaswiman)
481
+ * Start using pyproject.toml. (Kolanich)
482
+ * Add a ``ParsimoniusError`` exception base class. (Kevin Kirsche)
483
+ * Fall back to ``re`` when the ``regex`` lib is not available. (Pavel Kirienko)
484
+
485
+ 0.10.0
486
+ * Fix infinite recursion in __eq__ in some cases. (FelisNivalis)
487
+ * Improve error message in left-recursive rules. (lucaswiman)
488
+ * Add support for range ``{min,max}`` repetition expressions (righthandabacus)
489
+ * Fix bug in ``*`` and ``+`` for token grammars (lucaswiman)
490
+ * Add support for grammars on bytestrings (lucaswiman)
491
+ * Fix LazyReference resolution bug #134 (righthandabacus)
492
+ * ~15% speedup on benchmarks with a faster node cache (ethframe)
493
+
494
+ .. warning::
495
+
496
+ This release makes backward-incompatible changes:
497
+
498
+ * Fix precedence of string literal modifiers ``u/r/b``.
499
+ This will break grammars with no spaces between a
500
+ reference and a string literal. (lucaswiman)
501
+
502
+
503
+ 0.9.0
504
+ * Add support for Python 3.7, 3.8, 3.9, 3.10 (righthandabacus, Lonnen)
505
+ * Drop support for Python 2.x, 3.3, 3.4 (righthandabacus, Lonnen)
506
+ * Remove six and go all in on Python 3 idioms (Lonnen)
507
+ * Replace re with regex for improved handling of unicode characters
508
+ in regexes (Oderjunkie)
509
+ * Dropped nose for unittest (swayson)
510
+ * `Grammar.__repr__()` now correctly escapes backslashes (ingolemo)
511
+ * Custom rules can now be class methods in addition to
512
+ functions (James Addison)
513
+ * Make the ascii flag available in the regex syntax (Roman Inflianskas)
514
+
515
+ 0.8.1
516
+ * Switch to a function-style ``print`` in the benchmark tests so we work
517
+ cleanly as a dependency on Python 3. (Edward Betts)
518
+
519
+ 0.8.0
520
+ * Make Grammar iteration ordered, making the ``__repr__`` more like the
521
+ original input. (Lucas Wiman)
522
+ * Improve text representation and error messages for anonymous
523
+ subexpressions. (Lucas Wiman)
524
+ * Expose BadGrammar and VisitationError as top-level imports.
525
+ * No longer crash when you try to compare a Node to an instance of a
526
+ different class. (Esben Sonne)
527
+ * Pin ``six`` at 1.9.0 to ensure we have ``python_2_unicode_compatible``.
528
+ (Sam Raker)
529
+ * Drop Python 2.6 support.
530
+
531
+ 0.7.0
532
+ * Add experimental token-based parsing, via TokenGrammar class, for those
533
+ operating on pre-lexed streams of tokens. This can, for example, help parse
534
+ indentation-sensitive languages that use the "off-side rule", like Python.
535
+ (Erik Rose)
536
+ * Common codebase for Python 2 and 3: no more 2to3 translation step (Mattias
537
+ Urlichs, Lucas Wiman)
538
+ * Drop Python 3.1 and 3.2 support.
539
+ * Fix a bug in ``Grammar.__repr__`` which fails to work on Python 3 since the
540
+ string_escape codec is gone in Python 3. (Lucas Wiman)
541
+ * Don't lose parentheses when printing representations of expressions.
542
+ (Michael Kelly)
543
+ * Make Grammar an immutable mapping (until we add automatic recompilation).
544
+ (Michael Kelly)
545
+
546
+ 0.6.2
547
+ * Make grammar compilation 100x faster. Thanks to dmoisset for the initial
548
+ patch.
549
+
550
+ 0.6.1
551
+ * Fix bug which made the default rule of a grammar invalid when it
552
+ contained a forward reference.
553
+
554
+ 0.6
555
+ .. warning::
556
+
557
+ This release makes backward-incompatible changes:
558
+
559
+ * The ``default_rule`` arg to Grammar's constructor has been replaced
560
+ with a method, ``some_grammar.default('rule_name')``, which returns a
561
+ new grammar just like the old except with its default rule changed.
562
+ This is to free up the constructor kwargs for custom rules.
563
+ * ``UndefinedLabel`` is no longer a subclass of ``VisitationError``. This
564
+ matters only in the unlikely case that you were catching
565
+ ``VisitationError`` exceptions and expecting to thus also catch
566
+ ``UndefinedLabel``.
567
+
568
+ * Add support for "custom rules" in Grammars. These provide a hook for simple
569
+ custom parsing hooks spelled as Python lambdas. For heavy-duty needs,
570
+ you can put in Compound Expressions with LazyReferences as subexpressions,
571
+ and the Grammar will hook them up for optimal efficiency--no calling
572
+ ``__getitem__`` on Grammar at parse time.
573
+ * Allow grammars without a default rule (in cases where there are no string
574
+ rules), which leads to also allowing empty grammars. Perhaps someone
575
+ building up grammars dynamically will find that useful.
576
+ * Add ``@rule`` decorator, allowing grammars to be constructed out of
577
+ notations on ``NodeVisitor`` methods. This saves looking back and forth
578
+ between the visitor and the grammar when there is only one visitor per
579
+ grammar.
580
+ * Add ``parse()`` and ``match()`` convenience methods to ``NodeVisitor``.
581
+ This makes the common case of parsing a string and applying exactly one
582
+ visitor to the AST shorter and simpler.
583
+ * Improve exception message when you forget to declare a visitor method.
584
+ * Add ``unwrapped_exceptions`` attribute to ``NodeVisitor``, letting you
585
+ name certain exceptions which propagate out of visitors without being
586
+ wrapped by ``VisitationError`` exceptions.
587
+ * Expose much more of the library in ``__init__``, making your imports
588
+ shorter.
589
+ * Drastically simplify reference resolution machinery. (Vladimir Keleshev)
590
+
591
+ 0.5
592
+ .. warning::
593
+
594
+ This release makes some backward-incompatible changes. See below.
595
+
596
+ * Add alpha-quality error reporting. Now, rather than returning ``None``,
597
+ ``parse()`` and ``match()`` raise ``ParseError`` if they don't succeed.
598
+ This makes more sense, since you'd rarely attempt to parse something and
599
+ not care if it succeeds. It was too easy before to forget to check for a
600
+ ``None`` result. ``ParseError`` gives you a human-readable unicode
601
+ representation as well as some attributes that let you construct your own
602
+ custom presentation.
603
+ * Grammar construction now raises ``ParseError`` rather than ``BadGrammar``
604
+ if it can't parse your rules.
605
+ * ``parse()`` now takes an optional ``pos`` argument, like ``match()``.
606
+ * Make the ``_str__()`` method of ``UndefinedLabel`` return the right type.
607
+ * Support splitting rules across multiple lines, interleaving comments,
608
+ putting multiple rules on one line (but don't do that) and all sorts of
609
+ other horrific behavior.
610
+ * Tolerate whitespace after opening parens.
611
+ * Add support for single-quoted literals.
612
+
613
+ 0.4
614
+ * Support Python 3.
615
+ * Fix ``import *`` for ``parsimonius.expressions``.
616
+ * Rewrite grammar compiler so right-recursive rules can be compiled and
617
+ parsing no longer fails in some cases with forward rule references.
618
+
619
+ 0.3
620
+ * Support comments, the ``!`` ("not") operator, and parentheses in grammar
621
+ definition syntax.
622
+ * Change the ``&`` operator to a prefix operator to conform to the original
623
+ PEG syntax. The version in Parsing Techniques was infix, and that's what I
624
+ used as a reference. However, the unary version is more convenient, as it
625
+ lets you spell ``AB & A`` as simply ``A &B``.
626
+ * Take the ``print`` statements out of the benchmark tests.
627
+ * Give Node an evaluate-able ``__repr__``.
628
+
629
+ 0.2
630
+ * Support matching of prefixes and other not-to-the-end slices of strings by
631
+ making ``match()`` public and able to initialize a new cache. Add
632
+ ``match()`` callthrough method to ``Grammar``.
633
+ * Report a ``BadGrammar`` exception (rather than crashing) when there are
634
+ mistakes in a grammar definition.
635
+ * Simplify grammar compilation internals: get rid of superfluous visitor
636
+ methods and factor up repetitive ones. Simplify rule grammar as well.
637
+ * Add ``NodeVisitor.lift_child`` convenience method.
638
+ * Rename ``VisitationException`` to ``VisitationError`` for consistency with
639
+ the standard Python exception hierarchy.
640
+ * Rework ``repr`` and ``str`` values for grammars and expressions. Now they
641
+ both look like rule syntax. Grammars are even round-trippable! This fixes a
642
+ unicode encoding error when printing nodes that had parsed unicode text.
643
+ * Add tox for testing. Stop advertising Python 2.5 support, which never
644
+ worked (and won't unless somebody cares a lot, since it makes Python 3
645
+ support harder).
646
+ * Settle (hopefully) on the term "rule" to mean "the string representation of
647
+ a production". Get rid of the vague, mysterious "DSL".
648
+
649
+ 0.1
650
+ * A rough but useable preview release
651
+
652
+ Thanks to Wiki Loves Monuments Panama for showing their support with a generous
653
+ gift.