Home | Trees | Indices | Help |
---|
|
object --+ | ParserElement --+ | ParseElementEnhance --+ | Forward
Forward declaration of an expression to be defined later - used for recursive grammars, such as algebraic infix notation. When the expression is known, it is assigned to the ``Forward`` variable using the '<<' operator.
Note: take care when assigning to ``Forward`` not to overlook precedence of operators.
Specifically, '|' has a lower precedence than '<<', so that:
fwdExpr << a | b | c
will actually be evaluated as:
(fwdExpr << a) | b | c
thereby leaving b and c out as parseable alternatives. It is recommended that you explicitly group the values inserted into the ``Forward``:
fwdExpr << (a | b | c)
Converting to use the '<<=' operator instead will avoid this problem.
See :class:`ParseResults.pprint` for an example of a recursive parser created using ``Forward``.
|
|||
Inherited from |
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
Inherited from Inherited from Inherited from Inherited from |
|
|||
Inherited from |
|
|||
Inherited from Inherited from |
|
|||
Inherited from |
|
x.__init__(...) initializes x; see help(type(x)) for signature
|
Disables the skipping of whitespace before matching the characters in the :class:`ParserElement`'s defined pattern. This is normally only used internally by the pyparsing module, but may be needed in some whitespace-sensitive grammars.
|
|
Check defined expressions for valid structure, check for infinite recursive definitions.
|
str(x)
|
Make a copy of this :class:`ParserElement`. Useful for defining different parse actions for the same parsing pattern, using copies of the original parse element. Example: integer = Word(nums).setParseAction(lambda toks: int(toks[0])) integerK = integer.copy().addParseAction(lambda toks: toks[0] * 1024) + Suppress("K") integerM = integer.copy().addParseAction(lambda toks: toks[0] * 1024 * 1024) + Suppress("M") print(OneOrMore(integerK | integerM | integer).parseString("5K 100 640K 256M")) prints: [5120, 100, 655360, 268435456] Equivalent form of ``expr.copy()`` is just ``expr()``: integerM = integer().addParseAction(lambda toks: toks[0] * 1024 * 1024) + Suppress("M")
|
|
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Wed Dec 25 07:03:29 2019 | http://epydoc.sourceforge.net |