Package spade :: Module pyparsing :: Class ParserElement
[hide private]
[frames] | no frames]

Class ParserElement

source code


Abstract base level parser element class.

Instance Methods [hide private]
 
__init__(self, savelist=False)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
copy(self)
Make a copy of this ParseElement.
source code
 
setName(self, name)
Define name for this expression, for use in debugging.
source code
 
setResultsName(self, name, listAllMatches=False)
Define name for referencing matching tokens as a nested attribute of the returned parse results.
source code
 
setParseAction(self, fn)
Define action to perform when successfully matching parse element definition.
source code
 
skipIgnorables(self, instring, loc) source code
 
preParse(self, instring, loc) source code
 
parseImpl(self, instring, loc, doActions=True) source code
 
postParse(self, instring, loc, tokenlist) source code
 
parse(self, instring, loc, doActions=True, callPreParse=True) source code
 
tryParse(self, instring, loc) source code
 
parseString(self, instring)
Execute the parse expression with the given string.
source code
 
scanString(self, instring)
Scan the input string for expression matches.
source code
 
transformString(self, instring)
Extension to scanString, to modify matching text with modified tokens that may be returned from a parse action.
source code
 
__add__(self, other)
Implementation of + operator - returns And
source code
 
__radd__(self, other)
Implementation of += operator
source code
 
__or__(self, other)
Implementation of | operator - returns MatchFirst
source code
 
__ror__(self, other)
Implementation of |= operator
source code
 
__xor__(self, other)
Implementation of ^ operator - returns Or
source code
 
__rxor__(self, other)
Implementation of ^= operator
source code
 
__and__(self, other)
Implementation of & operator - returns Each
source code
 
__rand__(self, other)
Implementation of right-& operator
source code
 
__invert__(self)
Implementation of ~ operator - returns NotAny
source code
 
suppress(self)
Suppresses the output of this ParseElement; useful to keep punctuation from cluttering up returned output.
source code
 
leaveWhitespace(self)
Disables the skipping of whitespace before matching the characters in the ParserElement's defined pattern.
source code
 
setWhitespaceChars(self, chars)
Overrides the default whitespace chars
source code
 
parseWithTabs(self)
Overrides default behavior to expand <TAB>s to spaces before parsing the input string.
source code
 
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.
source code
 
setDebugActions(self, startAction, successAction, exceptionAction)
Enable display of debugging messages while doing pattern matching.
source code
 
setDebug(self, flag=True)
Enable display of debugging messages while doing pattern matching.
source code
 
__str__(self)
str(x)
source code
 
__repr__(self)
repr(x)
source code
 
streamline(self) source code
 
checkRecursion(self, parseElementList) source code
 
validate(self, validateTrace=[])
Check defined expressions for valid structure, check for infinite recursive definitions.
source code
 
parseFile(self, file_or_filename)
Execute the parse expression on the given file or filename.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Static Methods [hide private]
 
setDefaultWhitespaceChars(chars)
Overrides the default whitespace chars
source code
Class Variables [hide private]
  DEFAULT_WHITE_CHARS = ' \n\t\r'
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, savelist=False)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

copy(self)

source code 

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

setResultsName(self, name, listAllMatches=False)

source code 

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.

setParseAction(self, fn)

source code 

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.

parseString(self, instring)

source code 

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

scanString(self, instring)

source code 

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

transformString(self, instring)

source code 

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.

leaveWhitespace(self)

source code 

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.

parseWithTabs(self)

source code 

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.

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

parseFile(self, file_or_filename)

source code 

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.