pyparsing v2.3.1 Release Notes

Release Date: 2019-01-01 // almost 3 years ago
    • πŸš€ POSSIBLE API CHANGE: this release fixes a bug when results names were attached to a MatchFirst or Or object containing an And object. Previously, a results name on an And object within an enclosing MatchFirst or Or could return just the first token in the And. Now, all the tokens matched by the And are correctly returned. This may result in subtle changes in the tokens returned if you have this condition in your pyparsing scripts.

    • πŸ†• New staticmethod ParseException.explain() to help diagnose parse exceptions by showing the failing input line and the trace of ParserElements in the parser leading up to the exception. explain() returns a multiline string listing each element by name. (This is still an experimental method, and the method signature and format of the returned string may evolve over the next few releases.)

    Example: # define a parser to parse an integer followed by an # alphabetic word expr = pp.Word(pp.nums).setName("int") + pp.Word(pp.alphas).setName("word") try: # parse a string with a numeric second value instead of alpha expr.parseString("123 355") except pp.ParseException as pe: print(pp.ParseException.explain(pe))

    Prints: 123 355 ^ ParseException: Expected word (at char 4), (line:1, col:5) main.ExplainExceptionTest pyparsing.And - {int word} pyparsing.Word - word

    explain() will accept any exception type and will list the function names and parse expressions in the stack trace. This is especially useful when an exception is raised in a parse action.

    Note: explain() is only supported under Python 3.

    • πŸ›  Fix bug in dictOf which could match an empty sequence, making it infinitely loop if wrapped in a OneOrMore.

    • βž• Added unicode sets to pyparsing_unicode for Latin-A and Latin-B ranges.

    • βž• Added ability to define custom unicode sets as combinations of other sets using multiple inheritance.

      class Turkish_set(pp.pyparsing_unicode.Latin1, pp.pyparsing_unicode.LatinA): pass

      turkish_word = pp.Word(Turkish_set.alphas)

    • ⚑️ Updated state machine import examples, with state machine demos for: . traffic light . library book checkin/checkout . document review/approval

    In the traffic light example, you can use the custom 'statemachine' keyword to define the states for a traffic light, and have the state classes auto-generated for you:

      statemachine TrafficLightState:
          Red -> Green
          Green -> Yellow
          Yellow -> Red

    Similar for state machines with named transitions, like the library book state example:

      statemachine LibraryBookState:
          New -(shelve)-> Available
          Available -(reserve)-> OnHold
          OnHold -(release)-> Available
          Available -(checkout)-> CheckedOut
          CheckedOut -(checkin)-> Available

    Once the classes are defined, then additional Python code can reference those classes to add class attributes, instance methods, etc.

    See the examples in examples/statemachine

    • βž• Added an example parser for the decaf language. This language is used in CS compiler classes in many colleges and universities.

    • πŸ›  Fixup of docstrings to Sphinx format, inclusion of test files in the source package, and convert markdown to rst throughout the distribution, great job by MatΔ›j Cepl!

    • Expanded the whitespace characters recognized by the White class to include all unicode defined spaces. Suggested in Issue #51 by rtkjbillo.

    • βž• Added optional postParse argument to ParserElement.runTests() to add a custom callback to be called for test strings that parse successfully. Useful for running tests that do additional validation or processing on the parsed results. See updated example.

    • βœ‚ Removed distutils fallback in If installing the package fails, please update to the latest version of setuptools. Plus overall project code cleanup (CRLFs, whitespace, imports, etc.), thanks Jon Dufresne!

    • πŸ›  Fix bug in CaselessKeyword, to make its behavior consistent with Keyword(caseless=True). Fixes Issue #65 reported by telesphore.