From 75bac5978133342537b92cce6e518435d4a8cb57 Mon Sep 17 00:00:00 2001 From: ptmcg Date: Wed, 13 May 2020 14:13:52 -0500 Subject: Convert internal imports to relative imports, to support projects that vendor pyparsing --- pyparsing/helpers.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'pyparsing/helpers.py') 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() -- cgit v1.2.1