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
  __invert__(self)
Implementation of ~ operator - returns NotAny
  __or__(self, other)
Implementation of | operator - returns MatchFirst
  __radd__(self, other)
Implementation of += 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
  checkRecursion(self, parseElementList)
  copy(self)
Make a copy of this ParseElement.
  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.
  parse(self, instring, loc, doActions, callPreParse)
  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)
  scanString(self, instring)
Scan the input string for expression matches.
  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)
  setName(self, name)
Define name for this expression, for use in debugging.
  setParseAction(self, fn)
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 ParseElement; 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

__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

__ror__(self, other)

Implementation of |= operator

__rxor__(self, other)

Implementation of ^= operator

__xor__(self, other)

Implementation of ^ operator - returns Or

copy(self)

Make a copy of this ParseElement. 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)

Scan the input string for expression matches. Each match will return the matching tokens, start location, and end location.

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.

setName(self, name)

Define name for this expression, for use in debugging.

setParseAction(self, fn)

Define action to perform when successfully matching parse element definition. Parse action fn is a callable method with the arguments (s, loc, toks) 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 function fn modifies the tokens, it 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 ParseElement 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 ParseElement; 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

setDefaultWhitespaceChars(chars)

Overrides the default whitespace chars

Class Variable Details

DEFAULT_WHITE_CHARS

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

Generated by Epydoc 2.1 on Sun Jun 12 22:30:07 2005 http://epydoc.sf.net