1 What’s New in Pyparsing 3.2.0¶
- author:
Paul McGuire
- date:
October, 2024
- abstract:
This document summarizes the changes made in the 3.2.x releases of pyparsing.
1.1 Supported Python versions¶
Added support for Python 3.13.
Python versions before 3.9 are no longer supported. Removed legacy Py2.x support and other deprecated features. Pyparsing now requires Python 3.9 or later. If you are using an earlier 3.x version of Python, use pyparsing 3.1; for Python 2.x, use Pyparsing 2.4.7.
1.2 New Features¶
Added type annotations to remainder of
pyparsingpackage, and addedmypyrun totox.ini, so that type annotations are now run as part of pyparsing’s CI.Exception message format can now be customized, by overriding
ParseBaseException.format_message:def custom_exception_message(exc) -> str: found_phrase = f", found {exc.found}" if exc.found else "" return f"{exc.lineno}:{exc.column} {exc.msg}{found_phrase}" ParseBaseException.formatted_message = custom_exception_message
run_testsnow detects if an exception is raised in a parse action, and will report it with an enhanced error message, with the exception type, string, and parse action name.QuotedStringnow handles translation of escaped integer, hex, octal, and Unicode sequences to their corresponding characters.Defined a more performant regular expression used internally by
common_html_entity.Regexinstances can now be created using a callable that takes no arguments and just returns a string or a compiled regular expression, so that creating complex regular expression patterns can be deferred until they are actually used for the first time in the parser.Fixed the displayed output of
Regexterms to deduplicate repeated backslashes, for easier reading in debugging, printing, and railroad diagrams.Fixed railroad diagrams that get generated with a parser containing a Regex element defined using a verbose pattern - the pattern gets flattened and comments removed before creating the corresponding diagram element.
1.3 API Changes¶
1.3.1 Possible breaking changes¶
Fixed code in
ParseElementEnhancesubclasses that replaced detailed exception messages raised in contained expressions with a less-specific and less-informative generic exception message and location.If your code has conditional logic based on the message content in raised
ParseExceptions, this bugfix may require changes in your code.Fixed bug in
transform_string()where whitespace in the input string was not properly preserved in the output string.If your code uses
transform_string, this bugfix may require changes in your code.Fixed bug where an
IndexErrorraised in a parse action was incorrectly handled as anIndexErrorraised as part of theParserElementparsing methods, and reraised as aParseException. Now anIndexErrorthat raises inside a parse action will properly propagate out as anIndexError.If your code raises
IndexErrorin parse actions, this bugfix may require changes in your code.
1.3.2 Additional API changes¶
Added optional
flattenBoolean argument toParseResults.as_list(), to return the parsed values in a flattened list.Added
indentandbase_1arguments topyparsing.testing.with_line_numbers. When usingwith_line_numbersinside a parse action, setbase_1=False, since the reportedlocvalue is 0-based.indentcan be a leading string (typically of spaces or tabs) to indent the numbered string passed towith_line_numbers.
1.4 New / Enhanced Examples¶
Added query syntax to
mongodb_query_expression.pywith:better support for array fields (“contains all”, “contains any”, and “contains none”)
“like” and “not like” operators to support SQL “%” wildcard matching and “=~” operator to support regex matching
text search using “search for”
dates and datetimes as query values
a[0]style array referencing
Added
lox_parser.pyexample, a parser for the Lox language used as a tutorial in Robert Nystrom’s “Crafting Interpreters” (http://craftinginterpreters.com/).Added
complex_chemical_formulas.pyexample, to add parsing capability for formulas such as “Ba(BrO₃)₂·H₂O”.Updated
tag_emitter.pyto use newTagclass, introduced in pyparsing 3.1.3.
1.5 Acknowledgments¶
Again, thanks to the many contributors who submitted issues, questions, suggestions, and PRs.