diff options
author | ptmcg <ptmcg@austin.rr.com> | 2020-05-13 14:13:52 -0500 |
---|---|---|
committer | ptmcg <ptmcg@austin.rr.com> | 2020-05-13 14:13:52 -0500 |
commit | 75bac5978133342537b92cce6e518435d4a8cb57 (patch) | |
tree | d2561fa79f4a3a31babad55a66a8d9c1b164b5bf /pyparsing/helpers.py | |
parent | 42e7022d549d0ded980fb51a57765fcf476954cf (diff) | |
download | pyparsing-git-75bac5978133342537b92cce6e518435d4a8cb57.tar.gz |
Convert internal imports to relative imports, to support projects that vendor pyparsing
Diffstat (limited to 'pyparsing/helpers.py')
-rw-r--r-- | pyparsing/helpers.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/pyparsing/helpers.py b/pyparsing/helpers.py index 97e5943..a4c042c 100644 --- a/pyparsing/helpers.py +++ b/pyparsing/helpers.py @@ -1,6 +1,6 @@ # helpers.py -from pyparsing.core import * -from pyparsing.util import _bslash, _flatten, _escapeRegexRangeChars +from .core import * +from .util import _bslash, _flatten, _escapeRegexRangeChars # @@ -50,6 +50,19 @@ def countedArray(expr, intExpr=None): # '10' indicating that 2 values are in the array binaryConstant = Word('01').setParseAction(lambda t: int(t[0], 2)) countedArray(Word(alphas), intExpr=binaryConstant).parseString('10 ab cd ef') # -> ['ab', 'cd'] + + # if other fields must be parsed after the count but before the + # list items, give the fields results names and they will + # be preserved in the returned ParseResults: + count_with_metadata = integer + Word(alphas)("type") + typed_array = countedArray(Word(alphanums), intExpr=count_with_metadata)("items") + result = typed_array.parseString("3 bool True True False") + print(result.dump()) + + # prints + # ['True', 'True', 'False'] + # - items: ['True', 'True', 'False'] + # - type: 'bool' """ arrayExpr = Forward() |