Package parserFwk :: Module pyparsing :: Class ParserElement
[frames | no frames]

Type ParserElement

object --+
         |
        ParserElement

Known Subclasses:
ParseElementEnhance, ParseExpression, Token

Abstract base level parser element class.
Method Summary
  __init__(self, savelist)
  __add__(self, other)
Implementation of + operator - returns And
  __and__(self, other)
Implementation of & operator - returns Each
  __invert__(self)
Implementation of ~ operator - returns NotAny
  __or__(self, other)
Implementation of | operator - returns MatchFirst
  __radd__(self, other)
Implementation of += operator
  __rand__(self, other)
Implementation of right-& operator
  __repr__(self)
  __ror__(self, other)
Implementation of |= operator
  __rxor__(self, other)
Implementation of ^= operator
  __str__(self)
  __xor__(self, other)
Implementation of ^ operator - returns Or
  addParseAction(self, *fns)
Add parse action to expression's list of parse actions.
  checkRecursion(self, parseElementList)
  copy(self)
Make a copy of this ParserElement.
  enablePackrat()
Enables "packrat" parsing, which adds memoizing to the parsing logic. (Static method)
  ignore(self, other)
Define expression to be ignored (e.g., comments) while doing pattern matching; may be called repeatedly, to define multiple comment or other ignorable patterns.
  leaveWhitespace(self)
Disables the skipping of whitespace before matching the characters in the ParserElement's defined pattern.
  normalizeParseActionArgs(f)
Internal method used to decorate parse actions that take fewer than 3 arguments, so that all parse actions can be called as f(s,l,t). (Static method)
  parseFile(self, file_or_filename)
Execute the parse expression on the given file or filename.
  parseImpl(self, instring, loc, doActions)
  parseString(self, instring)
Execute the parse expression with the given string.
  parseWithTabs(self)
Overrides default behavior to expand <TAB>s to spaces before parsing the input string.
  postParse(self, instring, loc, tokenlist)
  preParse(self, instring, loc)
  resetCache()
(Static method)
  scanString(self, instring, maxMatches)
Scan the input string for expression matches.
  searchString(self, instring, maxMatches)
Another extension to scanString, simplifying the access to the tokens found to match the given parse expression.
  setDebug(self, flag)
Enable display of debugging messages while doing pattern matching.
  setDebugActions(self, startAction, successAction, exceptionAction)
Enable display of debugging messages while doing pattern matching.
  setDefaultWhitespaceChars(chars)
Overrides the default whitespace chars (Static method)
  setFailAction(self, fn)
Define action to perform if parsing fails at this expression.
  setName(self, name)
Define name for this expression, for use in debugging.
  setParseAction(self, *fns)
Define action to perform when successfully matching parse element definition.
  setResultsName(self, name, listAllMatches)
Define name for referencing matching tokens as a nested attribute of the returned parse results.
  setWhitespaceChars(self, chars)
Overrides the default whitespace chars
  skipIgnorables(self, instring, loc)
  streamline(self)
  suppress(self)
Suppresses the output of this ParserElement; useful to keep punctuation from cluttering up returned output.
  transformString(self, instring)
Extension to scanString, to modify matching text with modified tokens that may be returned from a parse action.
  tryParse(self, instring, loc)
  validate(self, validateTrace)
Check defined expressions for valid structure, check for infinite recursive definitions.
Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__

Class Variable Summary
str DEFAULT_WHITE_CHARS = ' \n\t\r'

Instance Method Details

__add__(self, other)
(Addition operator)

Implementation of + operator - returns And

__and__(self, other)
(And operator)

Implementation of & operator - returns Each

__invert__(self)

Implementation of ~ operator - returns NotAny

__or__(self, other)
(Or operator)

Implementation of | operator - returns MatchFirst

__radd__(self, other)
(Right-side addition operator)

Implementation of += operator

__rand__(self, other)

Implementation of right-& operator

__ror__(self, other)

Implementation of |= operator

__rxor__(self, other)

Implementation of ^= operator

__xor__(self, other)

Implementation of ^ operator - returns Or

addParseAction(self, *fns)

Add parse action to expression's list of parse actions. See setParseAction_.

copy(self)

Make a copy of this ParserElement. Useful for defining different parse actions for the same parsing pattern, using copies of the original parse element.

ignore(self, other)

Define expression to be ignored (e.g., comments) while doing pattern matching; may be called repeatedly, to define multiple comment or other ignorable patterns.

leaveWhitespace(self)

Disables the skipping of whitespace before matching the characters in the ParserElement's defined pattern. This is normally only used internally by the pyparsing module, but may be needed in some whitespace-sensitive grammars.

parseFile(self, file_or_filename)

Execute the parse expression on the given file or filename. If a filename is specified (instead of a file object), the entire file is opened, read, and closed before parsing.

parseString(self, instring)

Execute the parse expression with the given string. This is the main interface to the client code, once the complete expression has been built.

parseWithTabs(self)

Overrides default behavior to expand <TAB>s to spaces before parsing the input string. Must be called before parseString when the input grammar contains elements that match <TAB> characters.

scanString(self, instring, maxMatches=2147483647)

Scan the input string for expression matches. Each match will return the matching tokens, start location, and end location. May be called with optional maxMatches argument, to clip scanning after 'n' matches are found.

searchString(self, instring, maxMatches=2147483647)

Another extension to scanString, simplifying the access to the tokens found to match the given parse expression. May be called with optional maxMatches argument, to clip searching after 'n' matches are found.

setDebug(self, flag=True)

Enable display of debugging messages while doing pattern matching.

setDebugActions(self, startAction, successAction, exceptionAction)

Enable display of debugging messages while doing pattern matching.

setFailAction(self, fn)

Define action to perform if parsing fails at this expression. Fail acton fn is a callable function that takes the arguments fn(s,loc,expr,err) where:
  • s = string being parsed
  • loc = location where expression match was attempted and failed
  • expr = the parse expression that failed
  • err = the exception thrown
The function returns no value. It may throw ParseFatalException if it is desired to stop parsing immediately.

setName(self, name)

Define name for this expression, for use in debugging.

setParseAction(self, *fns)

Define action to perform when successfully matching parse element definition. Parse action fn is a callable method with 0-3 arguments, called as fn(s,loc,toks), fn(loc,toks), fn(toks), or just fn(), where:
  • s = the original string being parsed
  • loc = the location of the matching substring
  • toks = a list of the matched tokens, packaged as a ParseResults object
If the functions in fns modify the tokens, they can return them as the return value from fn, and the modified list of tokens will replace the original. Otherwise, fn does not need to return any value.

setResultsName(self, name, listAllMatches=False)

Define name for referencing matching tokens as a nested attribute of the returned parse results. NOTE: this returns a *copy* of the original ParserElement object; this is so that the client can define a basic element, such as an integer, and reference it in multiple places with different names.

setWhitespaceChars(self, chars)

Overrides the default whitespace chars

suppress(self)

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

transformString(self, instring)

Extension to scanString, to modify matching text with modified tokens that may be returned from a parse action. To use transformString, define a grammar and attach a parse action to it that modifies the returned token list. Invoking transformString() on a target string will then scan for matches, and replace the matched text patterns according to the logic in the parse action. transformString() returns the resulting transformed string.

validate(self, validateTrace=[])

Check defined expressions for valid structure, check for infinite recursive definitions.

Static Method Details

enablePackrat()

Enables "packrat" parsing, which adds memoizing to the parsing logic. Repeated parse attempts at the same string location (which happens often in many complex grammars) can immediately return a cached value, instead of re-executing parsing/validating code. Memoizing is done of both valid results and parsing exceptions.

This speedup may break existing programs that use parse actions that have side-effects. For this reason, packrat parsing is disabled when you first import pyparsing. To activate the packrat feature, your program must call the class method ParserElement.enablePackrat(). If your program uses psyco to "compile as you go", you must call enablePackrat before calling psyco.full(). If you do not do this, Python will crash. For best results, call enablePackrat() immediately after importing pyparsing.

normalizeParseActionArgs(f)

Internal method used to decorate parse actions that take fewer than 3 arguments, so that all parse actions can be called as f(s,l,t).

setDefaultWhitespaceChars(chars)

Overrides the default whitespace chars

Class Variable Details

DEFAULT_WHITE_CHARS

Type:
str
Value:
''' 
\t\r'''                                                                

Generated by Epydoc 2.1 on Fri Dec 22 02:04:35 2006 http://epydoc.sf.net