Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
pip._vendor.pyparsing.results.ParseResults Class Reference
Collaboration diagram for pip._vendor.pyparsing.results.ParseResults:
Collaboration graph
[legend]

Classes

class  List
 

Public Member Functions

 __new__ (cls, toklist=None, name=None, **kwargs)
 
 __init__ (self, toklist=None, name=None, asList=True, modal=True, isinstance=isinstance)
 
 __getitem__ (self, i)
 
 __setitem__ (self, k, v, isinstance=isinstance)
 
 __delitem__ (self, i)
 
bool __contains__ (self, k)
 
int __len__ (self)
 
bool __bool__ (self)
 
Iterator __iter__ (self)
 
Iterator __reversed__ (self)
 
 keys (self)
 
 values (self)
 
 items (self)
 
bool haskeys (self)
 
 pop (self, *args, **kwargs)
 
 get (self, key, default_value=None)
 
 insert (self, index, ins_string)
 
 append (self, item)
 
 extend (self, itemseq)
 
 clear (self)
 
 __getattr__ (self, name)
 
"ParseResults" __add__ (self, "ParseResults" other)
 
"ParseResults" __iadd__ (self, "ParseResults" other)
 
"ParseResults" __radd__ (self, other)
 
str __repr__ (self)
 
str __str__ (self)
 
list as_list (self)
 
dict as_dict (self)
 
"ParseResults" copy (self)
 
"ParseResults" deepcopy (self)
 
 get_name (self)
 
str dump (self, indent="", full=True, include_list=True, _depth=0)
 
 pprint (self, *args, **kwargs)
 
 __getstate__ (self)
 
 __setstate__ (self, state)
 
 __getnewargs__ (self)
 
 __dir__ (self)
 
"ParseResults" from_dict (cls, other, name=None)
 

Static Public Attributes

list asList = as_list
 
dict asDict = as_dict
 
 getName = get_name
 

Protected Member Functions

 _asStringList (self, sep="")
 

Protected Attributes

 _name
 
 _parent
 
 _all_names
 
 _toklist
 
 _tokdict
 
 _modal
 

Static Protected Attributes

tuple _null_values = (None, [], ())
 
str _name
 
str _parent : "ParseResults"
 
Set _all_names [str]
 
bool _modal
 
List _toklist [Any]
 
Dict _tokdict [str, Any]
 

Detailed Description

Structured parse results, to provide multiple means of access to
the parsed data:

- as a list (``len(results)``)
- by list index (``results[0], results[1]``, etc.)
- by attribute (``results.<results_name>`` - see :class:`ParserElement.set_results_name`)

Example::

    integer = Word(nums)
    date_str = (integer.set_results_name("year") + '/'
                + integer.set_results_name("month") + '/'
                + integer.set_results_name("day"))
    # equivalent form:
    # date_str = (integer("year") + '/'
    #             + integer("month") + '/'
    #             + integer("day"))

    # parse_string returns a ParseResults object
    result = date_str.parse_string("1999/12/31")

    def test(s, fn=repr):
        print(f"{s} -> {fn(eval(s))}")
    test("list(result)")
    test("result[0]")
    test("result['month']")
    test("result.day")
    test("'month' in result")
    test("'minutes' in result")
    test("result.dump()", str)

prints::

    list(result) -> ['1999', '/', '12', '/', '31']
    result[0] -> '1999'
    result['month'] -> '12'
    result.day -> '31'
    'month' in result -> True
    'minutes' in result -> False
    result.dump() -> ['1999', '/', '12', '/', '31']
    - day: '31'
    - month: '12'
    - year: '1999'

Member Function Documentation

◆ append()

pip._vendor.pyparsing.results.ParseResults.append (   self,
  item 
)
Add single element to end of ``ParseResults`` list of elements.

Example::

    numlist = Word(nums)[...]
    print(numlist.parse_string("0 123 321")) # -> ['0', '123', '321']

    # use a parse action to compute the sum of the parsed integers, and add it to the end
    def append_sum(tokens):
        tokens.append(sum(map(int, tokens)))
    numlist.add_parse_action(append_sum)
    print(numlist.parse_string("0 123 321")) # -> ['0', '123', '321', 444]

◆ as_dict()

dict pip._vendor.pyparsing.results.ParseResults.as_dict (   self)
Returns the named parse results as a nested dictionary.

Example::

    integer = Word(nums)
    date_str = integer("year") + '/' + integer("month") + '/' + integer("day")

    result = date_str.parse_string('12/31/1999')
    print(type(result), repr(result)) # -> <class 'pyparsing.ParseResults'> (['12', '/', '31', '/', '1999'], {'day': [('1999', 4)], 'year': [('12', 0)], 'month': [('31', 2)]})

    result_dict = result.as_dict()
    print(type(result_dict), repr(result_dict)) # -> <class 'dict'> {'day': '1999', 'year': '12', 'month': '31'}

    # even though a ParseResults supports dict-like access, sometime you just need to have a dict
    import json
    print(json.dumps(result)) # -> Exception: TypeError: ... is not JSON serializable
    print(json.dumps(result.as_dict())) # -> {"month": "31", "day": "1999", "year": "12"}

◆ as_list()

list pip._vendor.pyparsing.results.ParseResults.as_list (   self)
Returns the parse results as a nested list of matching tokens, all converted to strings.

Example::

    patt = Word(alphas)[1, ...]
    result = patt.parse_string("sldkj lsdkj sldkj")
    # even though the result prints in string-like form, it is actually a pyparsing ParseResults
    print(type(result), result) # -> <class 'pyparsing.ParseResults'> ['sldkj', 'lsdkj', 'sldkj']

    # Use as_list() to create an actual list
    result_list = result.as_list()
    print(type(result_list), result_list) # -> <class 'list'> ['sldkj', 'lsdkj', 'sldkj']

◆ clear()

pip._vendor.pyparsing.results.ParseResults.clear (   self)
Clear all elements and results names.

◆ copy()

"ParseResults" pip._vendor.pyparsing.results.ParseResults.copy (   self)
Returns a new shallow copy of a :class:`ParseResults` object. `ParseResults`
items contained within the source are shared with the copy. Use
:class:`ParseResults.deepcopy()` to create a copy with its own separate
content values.

◆ deepcopy()

"ParseResults" pip._vendor.pyparsing.results.ParseResults.deepcopy (   self)
Returns a new deep copy of a :class:`ParseResults` object.

◆ dump()

str pip._vendor.pyparsing.results.ParseResults.dump (   self,
  indent = "",
  full = True,
  include_list = True,
  _depth = 0 
)
Diagnostic method for listing out the contents of
a :class:`ParseResults`. Accepts an optional ``indent`` argument so
that this string can be embedded in a nested display of other data.

Example::

    integer = Word(nums)
    date_str = integer("year") + '/' + integer("month") + '/' + integer("day")

    result = date_str.parse_string('1999/12/31')
    print(result.dump())

prints::

    ['1999', '/', '12', '/', '31']
    - day: '31'
    - month: '12'
    - year: '1999'

◆ extend()

pip._vendor.pyparsing.results.ParseResults.extend (   self,
  itemseq 
)
Add sequence of elements to end of ``ParseResults`` list of elements.

Example::

    patt = Word(alphas)[1, ...]

    # use a parse action to append the reverse of the matched strings, to make a palindrome
    def make_palindrome(tokens):
        tokens.extend(reversed([t[::-1] for t in tokens]))
        return ''.join(tokens)
    patt.add_parse_action(make_palindrome)
    print(patt.parse_string("lskdj sdlkjf lksd")) # -> 'lskdjsdlkjflksddsklfjkldsjdksl'

◆ from_dict()

"ParseResults" pip._vendor.pyparsing.results.ParseResults.from_dict (   cls,
  other,
  name = None 
)
Helper classmethod to construct a ``ParseResults`` from a ``dict``, preserving the
name-value relations as results names. If an optional ``name`` argument is
given, a nested ``ParseResults`` will be returned.

◆ get()

pip._vendor.pyparsing.results.ParseResults.get (   self,
  key,
  default_value = None 
)
Returns named result matching the given key, or if there is no
such name, then returns the given ``default_value`` or ``None`` if no
``default_value`` is specified.

Similar to ``dict.get()``.

Example::

    integer = Word(nums)
    date_str = integer("year") + '/' + integer("month") + '/' + integer("day")

    result = date_str.parse_string("1999/12/31")
    print(result.get("year")) # -> '1999'
    print(result.get("hour", "not specified")) # -> 'not specified'
    print(result.get("hour")) # -> None

◆ get_name()

pip._vendor.pyparsing.results.ParseResults.get_name (   self)
Returns the results name for this token expression. Useful when several
different expressions might match at a particular location.

Example::

integer = Word(nums)
ssn_expr = Regex(r"\d\d\d-\d\d-\d\d\d\d")
house_number_expr = Suppress('#') + Word(nums, alphanums)
user_data = (Group(house_number_expr)("house_number")
        | Group(ssn_expr)("ssn")
        | Group(integer)("age"))
user_info = user_data[1, ...]

result = user_info.parse_string("22 111-22-3333 #221B")
for item in result:
print(item.get_name(), ':', item[0])

prints::

age : 22
ssn : 111-22-3333
house_number : 221B

◆ haskeys()

bool pip._vendor.pyparsing.results.ParseResults.haskeys (   self)
Since ``keys()`` returns an iterator, this method is helpful in bypassing
code that looks for the existence of any defined results names.

◆ insert()

pip._vendor.pyparsing.results.ParseResults.insert (   self,
  index,
  ins_string 
)
Inserts new element at location index in the list of parsed tokens.

Similar to ``list.insert()``.

Example::

    numlist = Word(nums)[...]
    print(numlist.parse_string("0 123 321")) # -> ['0', '123', '321']

    # use a parse action to insert the parse location in the front of the parsed results
    def insert_locn(locn, tokens):
        tokens.insert(0, locn)
    numlist.add_parse_action(insert_locn)
    print(numlist.parse_string("0 123 321")) # -> [0, '0', '123', '321']

◆ pop()

pip._vendor.pyparsing.results.ParseResults.pop (   self,
args,
**  kwargs 
)
Removes and returns item at specified index (default= ``last``).
Supports both ``list`` and ``dict`` semantics for ``pop()``. If
passed no argument or an integer argument, it will use ``list``
semantics and pop tokens from the list of parsed tokens. If passed
a non-integer argument (most likely a string), it will use ``dict``
semantics and pop the corresponding value from any defined results
names. A second default return value argument is supported, just as in
``dict.pop()``.

Example::

    numlist = Word(nums)[...]
    print(numlist.parse_string("0 123 321")) # -> ['0', '123', '321']

    def remove_first(tokens):
        tokens.pop(0)
    numlist.add_parse_action(remove_first)
    print(numlist.parse_string("0 123 321")) # -> ['123', '321']

    label = Word(alphas)
    patt = label("LABEL") + Word(nums)[1, ...]
    print(patt.parse_string("AAB 123 321").dump())

    # Use pop() in a parse action to remove named result (note that corresponding value is not
    # removed from list form of results)
    def remove_LABEL(tokens):
        tokens.pop("LABEL")
        return tokens
    patt.add_parse_action(remove_LABEL)
    print(patt.parse_string("AAB 123 321").dump())

prints::

    ['AAB', '123', '321']
    - LABEL: 'AAB'

    ['AAB', '123', '321']

◆ pprint()

pip._vendor.pyparsing.results.ParseResults.pprint (   self,
args,
**  kwargs 
)
Pretty-printer for parsed results as a list, using the
`pprint <https://docs.python.org/3/library/pprint.html>`_ module.
Accepts additional positional or keyword args as defined for
`pprint.pprint <https://docs.python.org/3/library/pprint.html#pprint.pprint>`_ .

Example::

    ident = Word(alphas, alphanums)
    num = Word(nums)
    func = Forward()
    term = ident | num | Group('(' + func + ')')
    func <<= ident + Group(Optional(DelimitedList(term)))
    result = func.parse_string("fna a,b,(fnb c,d,200),100")
    result.pprint(width=40)

prints::

    ['fna',
     ['a',
      'b',
      ['(', 'fnb', ['c', 'd', '200'], ')'],
      '100']]

The documentation for this class was generated from the following file: