Skip to content

Commit

Permalink
Prep for 3.1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
ptmcg committed Jun 18, 2023
1 parent 40babe0 commit e4f3ce2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGES
Expand Up @@ -12,6 +12,11 @@ help from Devin J. Pohly in structuring the code to enable this peaceful transit

Version 3.2.0 will also discontinue support for Python versions 3.6 and 3.7.

Version 3.1.0 - June, 2023
--------------------------
- Added `tag_emitter.py` to examples. This example demonstrates how to insert
tags into your parsed results that are not part of the original parsed text.


Version 3.1.0b2 - May, 2023
---------------------------
Expand Down
34 changes: 34 additions & 0 deletions examples/tag_emitter.py
@@ -0,0 +1,34 @@
#
# tag_emitter.py
#
# Example showing how to inject tags into the parsed results by adding
# an Empty() with a parse action to return the desired added data.
#
# Copyright 2023, Paul McGuire
#
import pyparsing as pp

# define expressions to parse different forms of integer constants
# add parse actions that will evaluate the integer correctly
binary_int = ("0b" + pp.Word("01")).add_parse_action(lambda t: int(t[1], base=2))
hex_int = ("0x" + pp.Word(pp.hexnums)).add_parse_action(lambda t: int(t[1], base=16))
dec_int = pp.Word(pp.nums).add_parse_action(lambda t: int(t[0]))


# define function to inject an expression that will add an extra tag in the
# parsed output, to indicate what the original input format was
def emit_tag(s):
return pp.Empty().add_parse_action(pp.replace_with(s))


# define a parser that includes the tag emitter for each integer format type
int_parser = (binary_int("value") + emit_tag("binary")("original_format")
| hex_int("value") + emit_tag("hex")("original_format")
| dec_int("value") + emit_tag("decimal")("original_format")
)

# parse some integers
int_parser.run_tests("""\
0b11011000001
0x6c1
1729""")
2 changes: 1 addition & 1 deletion pyparsing/__init__.py
Expand Up @@ -121,7 +121,7 @@ def __repr__(self):


__version_info__ = version_info(3, 1, 0, "final", 1)
__version_time__ = "27 May 2023 13:51 UTC"
__version_time__ = "18 Jun 2023 14:05 UTC"
__version__ = __version_info__.__version__
__versionTime__ = __version_time__
__author__ = "Paul McGuire <ptmcg.gm+pyparsing@gmail.com>"
Expand Down

0 comments on commit e4f3ce2

Please sign in to comment.