Pyparsing

Latest version: v3.1.2

Safety actively analyzes 630169 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 11 of 17

1.5.4

----------------------------

- Fixed __builtins__ and file references in Python 3 code, thanks to
Greg Watson, saulspatz, sminos, and Mark Summerfield for reporting
their Python 3 experiences.

- Added new example, apicheck.py, as a sample of scanning a Tcl-like
language for functions with incorrect number of arguments (difficult
to track down in Tcl languages). This example uses some interesting
methods for capturing exceptions while scanning through source
code.

- Added new example deltaTime.py, that takes everyday time references
like "an hour from now", "2 days ago", "next Sunday at 2pm".

1.5.3

--------------------------

- ======= NOTE: API CHANGE!!!!!!! ===============
With this release, and henceforward, the pyparsing module is
imported as "pyparsing" on both Python 2.x and Python 3.x versions.

- Fixed up setup.py to auto-detect Python version and install the
correct version of pyparsing - suggested by Alex Martelli,
thanks, Alex! (and my apologies to all those who struggled with
those spurious installation errors caused by my earlier
fumblings!)

- Fixed bug on Python3 when using parseFile, getting bytes instead of
a str from the input file.

- Fixed subtle bug in originalTextFor, if followed by
significant whitespace (like a newline) - discovered by
Francis Vidal, thanks!

- Fixed very sneaky bug in Each, in which Optional elements were
not completely recognized as optional - found by Tal Weiss, thanks
for your patience.

- Fixed off-by-1 bug in line() method when the first line of the
input text was an empty line. Thanks to John Krukoff for submitting
a patch!

- Fixed bug in transformString if grammar contains Group expressions,
thanks to patch submitted by barnabas79, nice work!

- Fixed bug in originalTextFor in which trailing comments or otherwised
ignored text got slurped in with the matched expression. Thanks to
michael_ramirez44 on the pyparsing wiki for reporting this just in
time to get into this release!

- Added better support for summing ParseResults, see the new example,
parseResultsSumExample.py.

- Added support for composing a Regex using a compiled RE object;
thanks to my new colleague, Mike Thornton!

- In version 1.5.2, I changed the way exceptions are raised in order
to simplify the stacktraces reported during parsing. An anonymous
user posted a bug report on SF that this behavior makes it difficult
to debug some complex parsers, or parsers nested within parsers. In
this release I've added a class attribute ParserElement.verbose_stacktrace,
with a default value of False. If you set this to True, pyparsing will
report stacktraces using the pre-1.5.2 behavior.

- New examples:

. pymicko.py, a MicroC compiler submitted by Zarko Zivanov.
(Note: this example is separately licensed under the GPLv3,
and requires Python 2.6 or higher.) Thank you, Zarko!

. oc.py, a subset C parser, using the BNF from the 1996 Obfuscated C
Contest.

. stateMachine2.py, a modified version of stateMachine.py submitted
by Matt Anderson, that is compatible with Python versions 2.7 and
above - thanks so much, Matt!

. select_parser.py, a parser for reading SQLite SELECT statements,
as specified at https://www.sqlite.org/lang_select.html this goes
into much more detail than the simple SQL parser included in pyparsing's
source code

. excelExpr.py, a *simplistic* first-cut at a parser for Excel
expressions, which I originally posted on comp.lang.python in January,
2010; beware, this parser omits many common Excel cases (addition of
numbers represented as strings, references to named ranges)

. cpp_enum_parser.py, a nice little parser posted my Mark Tolonen on
comp.lang.python in August, 2009 (redistributed here with Mark's
permission). Thanks a bunch, Mark!

. partial_gene_match.py, a sample I posted to Stackoverflow.com,
implementing a special variation on Literal that does "close" matching,
up to a given number of allowed mismatches. The application was to
find matching gene sequences, with allowance for one or two mismatches.

. tagCapture.py, a sample showing how to use a Forward placeholder to
enforce matching of text parsed in a previous expression.

. matchPreviousDemo.py, simple demo showing how the matchPreviousLiteral
helper method is used to match a previously parsed token.

1.5.2

------------------------------
- Added pyparsing_py3.py module, so that Python 3 users can use
pyparsing by changing their pyparsing import statement to:

import pyparsing_py3

Thanks for help from Patrick Laban and his friend Geremy
Condra on the pyparsing wiki.

- Removed __slots__ declaration on ParseBaseException, for
compatibility with IronPython 2.0.1. Raised by David
Lawler on the pyparsing wiki, thanks David!

- Fixed bug in SkipTo/failOn handling - caught by eagle eye
cpennington on the pyparsing wiki!

- Fixed second bug in SkipTo when using the ignore constructor
argument, reported by Catherine Devlin, thanks!

- Fixed obscure bug reported by Eike Welk when using a class
as a ParseAction with an errant __getitem__ method.

- Simplified exception stack traces when reporting parse
exceptions back to caller of parseString or parseFile - thanks
to a tip from Peter Otten on comp.lang.python.

- Changed behavior of scanString to avoid infinitely looping on
expressions that match zero-length strings. Prompted by a
question posted by ellisonbg on the wiki.

- Enhanced classes that take a list of expressions (And, Or,
MatchFirst, and Each) to accept generator expressions also.
This can be useful when generating lists of alternative
expressions, as in this case, where the user wanted to match
any repetitions of '+', '*', '', or '.', but not mixtures
of them (that is, match '+++', but not '+-+'):

codes = "+*."
format = MatchFirst(Word(c) for c in codes)

Based on a problem posed by Denis Spir on the Python tutor
list.

- Added new example eval_arith.py, which extends the example
simpleArith.py to actually evaluate the parsed expressions.

1.5.1

-------------------------------
- Added new helper method originalTextFor, to replace the use of
the current keepOriginalText parse action. Now instead of
using the parse action, as in:

fullName = Word(alphas) + Word(alphas)
fullName.setParseAction(keepOriginalText)

(in this example, we used keepOriginalText to restore any white
space that may have been skipped between the first and last
names)
You can now write:

fullName = originalTextFor(Word(alphas) + Word(alphas))

The implementation of originalTextFor is simpler and faster than
keepOriginalText, and does not depend on using the inspect or
imp modules.

- Added optional parseAll argument to parseFile, to be consistent
with parseAll argument to parseString. Posted by pboucher on the
pyparsing wiki, thanks!

- Added failOn argument to SkipTo, so that grammars can define
literal strings or pyparsing expressions which, if found in the
skipped text, will cause SkipTo to fail. Useful to prevent
SkipTo from reading past terminating expression. Instigated by
question posed by Aki Niimura on the pyparsing wiki.

- Fixed bug in nestedExpr if multi-character expressions are given
for nesting delimiters. Patch provided by new pyparsing user,
Hans-Martin Gaudecker - thanks, H-M!

- Removed dependency on xml.sax.saxutils.escape, and included
internal implementation instead - proposed by Mike Droettboom on
the pyparsing mailing list, thanks Mike! Also fixed erroneous
mapping in replaceHTMLEntity of " to ', now correctly maps
to ". (Also added support for mapping ' to '.)

- Fixed typo in ParseResults.insert, found by Alejandro Dubrovsky,
good catch!

- Added __dir__() methods to ParseBaseException and ParseResults,
to support new dir() behavior in Py2.6 and Py3.0. If dir() is
called on a ParseResults object, the returned list will include
the base set of attribute names, plus any results names that are
defined.

- Fixed bug in ParseResults.asXML(), in which the first named
item within a ParseResults gets reported with an <ITEM> tag
instead of with the correct results name.

- Fixed bug in '-' error stop, when '-' operator is used inside a
Combine expression.

- Reverted generator expression to use list comprehension, for
better compatibility with old versions of Python. Reported by
jester/artixdesign on the SourceForge pyparsing discussion list.

- Fixed bug in parseString(parseAll=True), when the input string
ends with a comment or whitespace.

- Fixed bug in LineStart and LineEnd that did not recognize any
special whitespace chars defined using ParserElement.setDefault-
WhitespaceChars, found while debugging an issue for Marek Kubica,
thanks for the new test case, Marek!

- Made Forward class more tolerant of subclassing.

1.5.0

--------------------------
This version of pyparsing includes work on two long-standing
FAQ's: support for forcing parsing of the complete input string
(without having to explicitly append StringEnd() to the grammar),
and a method to improve the mechanism of detecting where syntax
errors occur in an input string with various optional and
alternative paths. This release also includes a helper method
to simplify definition of indentation-based grammars. With
these changes (and the past few minor updates), I thought it was
finally time to bump the minor rev number on pyparsing - so
1.5.0 is now available! Read on...

- AT LAST!!! You can now call parseString and have it raise
an exception if the expression does not parse the entire
input string. This has been an FAQ for a LONG time.

The parseString method now includes an optional parseAll
argument (default=False). If parseAll is set to True, then
the given parse expression must parse the entire input
string. (This is equivalent to adding StringEnd() to the
end of the expression.) The default value is False to
retain backward compatibility.

Inspired by MANY requests over the years, most recently by
ecir-hana on the pyparsing wiki!

- Added new operator '-' for composing grammar sequences. '-'
behaves just like '+' in creating And expressions, but '-'
is used to mark grammar structures that should stop parsing
immediately and report a syntax error, rather than just
backtracking to the last successful parse and trying another
alternative. For instance, running the following code:

port_definition = Keyword("port") + '=' + Word(nums)
entity_definition = Keyword("entity") + "{" +
Optional(port_definition) + "}"

entity_definition.parseString("entity { port 100 }")

pyparsing fails to detect the missing '=' in the port definition.
But, since this expression is optional, pyparsing then proceeds
to try to match the closing '}' of the entity_definition. Not
finding it, pyparsing reports that there was no '}' after the '{'
character. Instead, we would like pyparsing to parse the 'port'
keyword, and if not followed by an equals sign and an integer,
to signal this as a syntax error.

This can now be done simply by changing the port_definition to:

port_definition = Keyword("port") - '=' + Word(nums)

Now after successfully parsing 'port', pyparsing must also find
an equals sign and an integer, or it will raise a fatal syntax
exception.

By judicious insertion of '-' operators, a pyparsing developer
can have their grammar report much more informative syntax error
messages.

Patches and suggestions proposed by several contributors on
the pyparsing mailing list and wiki - special thanks to
Eike Welk and Thomas/Poldy on the pyparsing wiki!

- Added indentedBlock helper method, to encapsulate the parse
actions and indentation stack management needed to keep track of
indentation levels. Use indentedBlock to define grammars for
indentation-based grouping grammars, like Python's.

indentedBlock takes up to 3 parameters:
- blockStatementExpr - expression defining syntax of statement
that is repeated within the indented block
- indentStack - list created by caller to manage indentation
stack (multiple indentedBlock expressions
within a single grammar should share a common indentStack)
- indent - boolean indicating whether block must be indented
beyond the current level; set to False for block of
left-most statements (default=True)

A valid block must contain at least one indented statement.

- Fixed bug in nestedExpr in which ignored expressions needed
to be set off with whitespace. Reported by Stefaan Himpe,
nice catch!

- Expanded multiplication of an expression by a tuple, to
accept tuple values of None:
. expr*(n,None) or expr*(n,) is equivalent
to expr*n + ZeroOrMore(expr)
(read as "at least n instances of expr")
. expr*(None,n) is equivalent to expr*(0,n)
(read as "0 to n instances of expr")
. expr*(None,None) is equivalent to ZeroOrMore(expr)
. expr*(1,None) is equivalent to OneOrMore(expr)

Note that expr*(None,n) does not raise an exception if
more than n exprs exist in the input stream; that is,
expr*(None,n) does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
expr*(None,n) + ~expr

- Added None as a possible operator for operatorPrecedence.
None signifies "no operator", as in multiplying m times x
in "y=mx+b".

- Fixed bug in Each, reported by Michael Ramirez, in which the
order of terms in the Each affected the parsing of the results.
Problem was due to premature grouping of the expressions in
the overall Each during grammar construction, before the
complete Each was defined. Thanks, Michael!

- Also fixed bug in Each in which Optional's with default values
were not getting the defaults added to the results of the
overall Each expression.

- Fixed a bug in Optional in which results names were not
assigned if a default value was supplied.

- Cleaned up Py3K compatibility statements, including exception
construction statements, and better equivalence between _ustr
and basestring, and __nonzero__ and __bool__.

1.4.11

-------------------------------
- With help from Robert A. Clark, this version of pyparsing
is compatible with Python 3.0a3. Thanks for the help,
Robert!

- Added WordStart and WordEnd positional classes, to support
expressions that must occur at the start or end of a word.
Proposed by piranha on the pyparsing wiki, good idea!

- Added matchOnlyAtCol helper parser action, to simplify
parsing log or data files that have optional fields that are
column dependent. Inspired by a discussion thread with
hubritic on comp.lang.python.

- Added withAttribute.ANY_VALUE as a match-all value when using
withAttribute. Used to ensure that an attribute is present,
without having to match on the actual attribute value.

- Added get() method to ParseResults, similar to dict.get().
Suggested by new pyparsing user, Alejandro Dubrovksy, thanks!

- Added '==' short-cut to see if a given string matches a
pyparsing expression. For instance, you can now write:

integer = Word(nums)
if "123" == integer:
do something

print [ x for x in "123 234 asld".split() if x==integer ]
prints ['123', '234']

- Simplified the use of nestedExpr when using an expression for
the opening or closing delimiters. Now the content expression
will not have to explicitly negate closing delimiters. Found
while working with dfinnie on GHOP Task 277, thanks!

- Fixed bug when defining ignorable expressions that are
later enclosed in a wrapper expression (such as ZeroOrMore,
OneOrMore, etc.) - found while working with Prabhu
Gurumurthy, thanks Prahbu!

- Fixed bug in withAttribute in which keys were automatically
converted to lowercase, making it impossible to match XML
attributes with uppercase characters in them. Using with-
Attribute requires that you reference attributes in all
lowercase if parsing HTML, and in correct case when parsing
XML.

- Changed '<<' operator on Forward to return None, since this
is really used as a pseudo-assignment operator, not as a
left-shift operator. By returning None, it is easier to
catch faulty statements such as a << b | c, where precedence
of operations causes the '|' operation to be performed
*after* inserting b into a, so no alternation is actually
implemented. The correct form is a << (b | c). With this
change, an error will be reported instead of silently
clipping the alternative term. (Note: this may break some
existing code, but if it does, the code had a silent bug in
it anyway.) Proposed by wcbarksdale on the pyparsing wiki,
thanks!

- Several unit tests were added to pyparsing's regression
suite, courtesy of the Google Highly-Open Participation
Contest. Thanks to all who administered and took part in
this event!

Page 11 of 17

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.