pyparsing_regex package

pyparsing_regex is a reimplementation of the pyparsing interface, building upon regular expressions.

It is intended to be a replacement for pyparsing where no recursion is needed, in order to speed up parsing significantly (factor 100). The outputs are roughly similar

The index-interface of the parse result is analog to the of pyparsing, i.e. with string-keys “example-key” you can access all entries where setResultName("example-key") was called. Alternatively you can access elements with integer-key, in a list like way. Important to know, the Group class creates a nesting within this listing interface.

In addition to pyparsing, pyparsing_regex has a GroupLiftKeys class which works like Group, only that all keys are also available at the upper level (encompassing everything which belongs to that key further down). In a normal Group, the nested keys would be hided from the upper layer, which might not be what is wanted.

The returned object is a schlichtanders.myobjects.Structure which is a general powerful datastructure imitating pyparsings ParseResult in a general way.

For further documentation, see also http://pyparsing.wikispaces.com/

This lives on github https://github.com/schlichtanders/pyparsing_regex

class pyparsing_regex.Literal(str)[source]

Bases: pyparsing_regex._core.ParserElement

class pyparsing_regex.Regex(pattern, flags=0)[source]

Bases: pyparsing_regex._core.ParserElement

class pyparsing_regex.Word(initChars, bodyChars=None, min=1, max=0, exact=0, excludeChars=None)[source]

Bases: pyparsing_regex._core.ParserElement

class pyparsing_regex.CharsNotIn(notChars, min=1, max=0, exact=0)[source]

Bases: pyparsing_regex._interface.Word

class pyparsing_regex.SkipTo(expr, include_=False)[source]

Bases: pyparsing_regex._core.ParserElement

class pyparsing_regex.FollowedBy(expr)[source]

Bases: pyparsing_regex._core.ParserElement

class pyparsing_regex.Combine(expr)[source]

Bases: pyparsing_regex._core.ParserElement

class pyparsing_regex.Suppress(expr)[source]

Bases: pyparsing_regex._core.ParserElement

class pyparsing_regex.StringStart[source]

Bases: pyparsing_regex._core.ParserElement

class pyparsing_regex.StringEnd[source]

Bases: pyparsing_regex._core.ParserElement

class pyparsing_regex.LineStart[source]

Bases: pyparsing_regex._interface.Regex

class pyparsing_regex.LineEnd[source]

Bases: pyparsing_regex._interface.Regex

pyparsing_regex.And(iterable)[source]

__dict__ of first element will be passed through And result

pyparsing_regex.MatchFirst(iterable)[source]

__dict__ of first element will be passed through MatchFirst result

pyparsing_regex.Optional(expr, default=None)[source]
pyparsing_regex.Group(expr)[source]
pyparsing_regex.GroupLiftKeys(expr)[source]
pyparsing_regex.OneOrMore(expr)[source]
pyparsing_regex.ZeroOrMore(expr)[source]
pyparsing_regex.Repeat(expr, min=0, max=None)[source]
pyparsing_regex.setResultsNameInPlace(expr, name, listAllMatches=False)[source]

adds resultsname in place, no copy as with method

Parameters:
  • expr – parser to set resultsname
  • name – resultsname
  • listAllMatches – whether strings matches should all be listed, or only last match should be kept
class pyparsing_regex.ParserElement(pattern, silent=False)[source]

Bases: pyparsing_regex._core.ParserElementType

we can immitate arbitrarily complex formula directly by a single regex-string the output gets restructured (in linear time) to fulfil ParserElement/Structure interface

not implemented: whitespaces support

EMPTY = None
compile()[source]
group(wrapper=None, pseudo=False, liftkeys=False, silent=None)[source]
repeat(min=0, max=None)[source]

repeat on arbitrary ParserElement

setName(name)[source]
setResultsName(name, **kwargs)[source]

kwargs are for compatibility with pyparsing interface

suppress()[source]

Suppresses the output of this C{ParserElement}; useful to keep punctuation from cluttering up returned output.

change all inner brackets, e.g. (...) or (?P<>...) or (?<>...) to non-capturing (?:...) version

CAUTION: NOT REVERSIBLE!