| |
- __builtin__.object
-
- OnlyOnce
- ParseResults
- ParserElement
-
- ParseElementEnhance
-
- FollowedBy
- Forward
- NotAny
- OneOrMore
- Optional
- SkipTo
- TokenConverter
-
- Combine
- Dict
- Group
- Suppress
- Upcase
- ZeroOrMore
- ParseExpression
-
- And
- Each
- MatchFirst
- Or
- Token
-
- CharsNotIn
- Empty
- Keyword
-
- CaselessKeyword
- Literal
-
- CaselessLiteral
- NoMatch
- QuotedString
- Regex
- White
- Word
- exceptions.Exception(exceptions.BaseException)
-
- ParseBaseException
-
- ParseException
- ParseFatalException
-
- ParseSyntaxException
- RecursiveGrammarException
- _PositionToken(Token)
-
- GoToColumn
- LineEnd
- LineStart
- StringEnd
- StringStart
- WordEnd
- WordStart
class And(ParseExpression) |
|
Requires all given C{ParseExpression}s to be found in the given order.
Expressions may be separated by whitespace.
May be constructed using the C{'+'} operator. |
|
- Method resolution order:
- And
- ParseExpression
- ParserElement
- __builtin__.object
Methods defined here:
- __iadd__(self, other)
- __init__(self, exprs, savelist=True)
- __str__(self)
- checkRecursion(self, parseElementList)
- parseImpl(self, instring, loc, doActions=True)
Data and other attributes defined here:
- __slotnames__ = []
Methods inherited from ParseExpression:
- __getitem__(self, i)
- append(self, other)
- copy(self)
- ignore(self, other)
- leaveWhitespace(self)
- Extends C{leaveWhitespace} defined in base class, and also invokes C{leaveWhitespace} on
all contained expressions.
- setResultsName(self, name, listAllMatches=False)
- streamline(self)
- validate(self, validateTrace=[])
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- parseFile(self, file_or_filename, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class CaselessKeyword(Keyword) |
| |
- Method resolution order:
- CaselessKeyword
- Keyword
- Token
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, matchString, identChars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$')
- parseImpl(self, instring, loc, doActions=True)
Methods inherited from Keyword:
- copy(self)
Static methods inherited from Keyword:
- setDefaultKeywordChars(chars)
- Overrides the default Keyword chars
Data and other attributes inherited from Keyword:
- DEFAULT_KEYWORD_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$'
Methods inherited from Token:
- setName(self, name)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __str__(self)
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- 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
C{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, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class CaselessLiteral(Literal) |
|
Token to match a specified string, ignoring case of letters.
Note: the matched results will always be in the case of the given
match string, NOT the case of the input text. |
|
- Method resolution order:
- CaselessLiteral
- Literal
- Token
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, matchString)
- parseImpl(self, instring, loc, doActions=True)
Data and other attributes inherited from Literal:
- __slotnames__ = []
Methods inherited from Token:
- setName(self, name)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __str__(self)
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- copy(self)
- Make a copy of this C{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
C{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, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class CharsNotIn(Token) |
|
Token for matching words composed of characters *not* in a given set.
Defined with string containing all disallowed characters, and an optional
minimum, maximum, and/or exact length. The default value for C{min} is 1 (a
minimum value < 1 is not valid); the default values for C{max} and C{exact}
are 0, meaning no maximum or exact length restriction. |
|
- Method resolution order:
- CharsNotIn
- Token
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, notChars, min=1, max=0, exact=0)
- __str__(self)
- parseImpl(self, instring, loc, doActions=True)
Methods inherited from Token:
- setName(self, name)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- copy(self)
- Make a copy of this C{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
C{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, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class Combine(TokenConverter) |
|
Converter to concatenate all matching tokens to a single string.
By default, the matching patterns must also be contiguous in the input string;
this can be disabled by specifying C{'adjacent=False'} in the constructor. |
|
- Method resolution order:
- Combine
- TokenConverter
- ParseElementEnhance
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, expr, joinString='', adjacent=True)
- ignore(self, other)
- postParse(self, instring, loc, tokenlist)
Data and other attributes defined here:
- __slotnames__ = []
Methods inherited from ParseElementEnhance:
- __str__(self)
- checkRecursion(self, parseElementList)
- leaveWhitespace(self)
- parseImpl(self, instring, loc, doActions=True)
- streamline(self)
- validate(self, validateTrace=[])
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- copy(self)
- Make a copy of this C{ParserElement}. Useful for defining different parse actions
for the same parsing pattern, using copies of the original parse element.
- parseFile(self, file_or_filename, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class Dict(TokenConverter) |
|
Converter to return a repetitive expression as a list, but also as a dictionary.
Each element can also be referenced using the first token in the expression as its key.
Useful for tabular report scraping when the first column can be used as a item key. |
|
- Method resolution order:
- Dict
- TokenConverter
- ParseElementEnhance
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, exprs)
- postParse(self, instring, loc, tokenlist)
Data and other attributes defined here:
- __slotnames__ = []
Methods inherited from ParseElementEnhance:
- __str__(self)
- checkRecursion(self, parseElementList)
- ignore(self, other)
- leaveWhitespace(self)
- parseImpl(self, instring, loc, doActions=True)
- streamline(self)
- validate(self, validateTrace=[])
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- copy(self)
- Make a copy of this C{ParserElement}. Useful for defining different parse actions
for the same parsing pattern, using copies of the original parse element.
- parseFile(self, file_or_filename, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class Each(ParseExpression) |
|
Requires all given C{ParseExpression}s to be found, but in any order.
Expressions may be separated by whitespace.
May be constructed using the C{'&'} operator. |
|
- Method resolution order:
- Each
- ParseExpression
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, exprs, savelist=True)
- __str__(self)
- checkRecursion(self, parseElementList)
- parseImpl(self, instring, loc, doActions=True)
Methods inherited from ParseExpression:
- __getitem__(self, i)
- append(self, other)
- copy(self)
- ignore(self, other)
- leaveWhitespace(self)
- Extends C{leaveWhitespace} defined in base class, and also invokes C{leaveWhitespace} on
all contained expressions.
- setResultsName(self, name, listAllMatches=False)
- streamline(self)
- validate(self, validateTrace=[])
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- parseFile(self, file_or_filename, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class Empty(Token) |
|
An empty token, will always match. |
|
- Method resolution order:
- Empty
- Token
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self)
Methods inherited from Token:
- setName(self, name)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __str__(self)
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- copy(self)
- Make a copy of this C{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
C{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, parseAll=False)
- 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.
- parseImpl(self, instring, loc, doActions=True)
- parseString(self, instring, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class FollowedBy(ParseElementEnhance) |
|
Lookahead matching of the given parse expression. C{FollowedBy}
does *not* advance the parsing position within the input string, it only
verifies that the specified parse expression matches at the current
position. C{FollowedBy} always returns a null token list. |
|
- Method resolution order:
- FollowedBy
- ParseElementEnhance
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, expr)
- parseImpl(self, instring, loc, doActions=True)
Methods inherited from ParseElementEnhance:
- __str__(self)
- checkRecursion(self, parseElementList)
- ignore(self, other)
- leaveWhitespace(self)
- streamline(self)
- validate(self, validateTrace=[])
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- copy(self)
- Make a copy of this C{ParserElement}. Useful for defining different parse actions
for the same parsing pattern, using copies of the original parse element.
- parseFile(self, file_or_filename, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class Forward(ParseElementEnhance) |
|
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 C{Forward} variable using the '<<' operator.
Note: take care when assigning to C{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 C{Forward}::
fwdExpr << (a | b | c)
Converting to use the '<<=' operator instead will avoid this problem. |
|
- Method resolution order:
- Forward
- ParseElementEnhance
- ParserElement
- __builtin__.object
Methods defined here:
- __ilshift__(self, other)
- __init__(self, other=None)
- __lshift__(self, other)
- __str__(self)
- copy(self)
- leaveWhitespace(self)
- streamline(self)
- validate(self, validateTrace=[])
Methods inherited from ParseElementEnhance:
- checkRecursion(self, parseElementList)
- ignore(self, other)
- parseImpl(self, instring, loc, doActions=True)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- parseFile(self, file_or_filename, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class GoToColumn(_PositionToken) |
|
Token to advance to a specific column of input text; useful for tabular report scraping. |
|
- Method resolution order:
- GoToColumn
- _PositionToken
- Token
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, colno)
- parseImpl(self, instring, loc, doActions=True)
- preParse(self, instring, loc)
Methods inherited from Token:
- setName(self, name)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __str__(self)
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- copy(self)
- Make a copy of this C{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
C{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, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class Group(TokenConverter) |
|
Converter to return the matched tokens as a list - useful for returning tokens of C{L{ZeroOrMore}} and C{L{OneOrMore}} expressions. |
|
- Method resolution order:
- Group
- TokenConverter
- ParseElementEnhance
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, expr)
- postParse(self, instring, loc, tokenlist)
Data and other attributes defined here:
- __slotnames__ = []
Methods inherited from ParseElementEnhance:
- __str__(self)
- checkRecursion(self, parseElementList)
- ignore(self, other)
- leaveWhitespace(self)
- parseImpl(self, instring, loc, doActions=True)
- streamline(self)
- validate(self, validateTrace=[])
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- copy(self)
- Make a copy of this C{ParserElement}. Useful for defining different parse actions
for the same parsing pattern, using copies of the original parse element.
- parseFile(self, file_or_filename, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class Keyword(Token) |
|
Token to exactly match a specified string as a keyword, that is, it must be
immediately followed by a non-keyword character. Compare with C{L{Literal}}::
Literal("if") will match the leading C{'if'} in C{'ifAndOnlyIf'}.
Keyword("if") will not; it will only match the leading C{'if'} in C{'if x=1'}, or C{'if(y==2)'}
Accepts two optional constructor arguments in addition to the keyword string:
C{identChars} is a string of characters that would be valid identifier characters,
defaulting to all alphanumerics + "_" and "$"; C{caseless} allows case-insensitive
matching, default is C{False}. |
|
- Method resolution order:
- Keyword
- Token
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, matchString, identChars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$', caseless=False)
- copy(self)
- parseImpl(self, instring, loc, doActions=True)
Static methods defined here:
- setDefaultKeywordChars(chars)
- Overrides the default Keyword chars
Data and other attributes defined here:
- DEFAULT_KEYWORD_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$'
Methods inherited from Token:
- setName(self, name)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __str__(self)
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- 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
C{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, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class LineEnd(_PositionToken) |
|
Matches if current position is at the end of a line within the parse string |
|
- Method resolution order:
- LineEnd
- _PositionToken
- Token
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self)
- parseImpl(self, instring, loc, doActions=True)
Data and other attributes defined here:
- __slotnames__ = []
Methods inherited from Token:
- setName(self, name)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __str__(self)
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- copy(self)
- Make a copy of this C{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
C{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, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class LineStart(_PositionToken) |
|
Matches if current position is at the beginning of a line within the parse string |
|
- Method resolution order:
- LineStart
- _PositionToken
- Token
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self)
- parseImpl(self, instring, loc, doActions=True)
- preParse(self, instring, loc)
Methods inherited from Token:
- setName(self, name)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __str__(self)
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- copy(self)
- Make a copy of this C{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
C{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, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class Literal(Token) |
|
Token to exactly match a specified string. |
|
- Method resolution order:
- Literal
- Token
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, matchString)
- parseImpl(self, instring, loc, doActions=True)
- # Performance tuning: this routine gets called a *lot*
# if this is a single character match string and the first character matches,
# short-circuit as quickly as possible, and avoid calling startswith
#~ @profile
Data and other attributes defined here:
- __slotnames__ = []
Methods inherited from Token:
- setName(self, name)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __str__(self)
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- copy(self)
- Make a copy of this C{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
C{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, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class MatchFirst(ParseExpression) |
|
Requires that at least one C{ParseExpression} is found.
If two expressions match, the first one listed is the one that will match.
May be constructed using the C{'|'} operator. |
|
- Method resolution order:
- MatchFirst
- ParseExpression
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, exprs, savelist=False)
- __ior__(self, other)
- __str__(self)
- checkRecursion(self, parseElementList)
- parseImpl(self, instring, loc, doActions=True)
Methods inherited from ParseExpression:
- __getitem__(self, i)
- append(self, other)
- copy(self)
- ignore(self, other)
- leaveWhitespace(self)
- Extends C{leaveWhitespace} defined in base class, and also invokes C{leaveWhitespace} on
all contained expressions.
- setResultsName(self, name, listAllMatches=False)
- streamline(self)
- validate(self, validateTrace=[])
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- parseFile(self, file_or_filename, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class NoMatch(Token) |
|
A token that will never match. |
|
- Method resolution order:
- NoMatch
- Token
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self)
- parseImpl(self, instring, loc, doActions=True)
Methods inherited from Token:
- setName(self, name)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __str__(self)
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- copy(self)
- Make a copy of this C{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
C{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, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class NotAny(ParseElementEnhance) |
|
Lookahead to disallow matching with the given parse expression. C{NotAny}
does *not* advance the parsing position within the input string, it only
verifies that the specified parse expression does *not* match at the current
position. Also, C{NotAny} does *not* skip over leading whitespace. C{NotAny}
always returns a null token list. May be constructed using the '~' operator. |
|
- Method resolution order:
- NotAny
- ParseElementEnhance
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, expr)
- __str__(self)
- parseImpl(self, instring, loc, doActions=True)
Data and other attributes defined here:
- __slotnames__ = []
Methods inherited from ParseElementEnhance:
- checkRecursion(self, parseElementList)
- ignore(self, other)
- leaveWhitespace(self)
- streamline(self)
- validate(self, validateTrace=[])
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- copy(self)
- Make a copy of this C{ParserElement}. Useful for defining different parse actions
for the same parsing pattern, using copies of the original parse element.
- parseFile(self, file_or_filename, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class OneOrMore(ParseElementEnhance) |
|
Repetition of one or more of the given expression. |
|
- Method resolution order:
- OneOrMore
- ParseElementEnhance
- ParserElement
- __builtin__.object
Methods defined here:
- __str__(self)
- parseImpl(self, instring, loc, doActions=True)
- setResultsName(self, name, listAllMatches=False)
Data and other attributes defined here:
- __slotnames__ = []
Methods inherited from ParseElementEnhance:
- __init__(self, expr, savelist=False)
- checkRecursion(self, parseElementList)
- ignore(self, other)
- leaveWhitespace(self)
- streamline(self)
- validate(self, validateTrace=[])
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- copy(self)
- Make a copy of this C{ParserElement}. Useful for defining different parse actions
for the same parsing pattern, using copies of the original parse element.
- parseFile(self, file_or_filename, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class OnlyOnce(__builtin__.object) |
|
Wrapper for parse actions, to ensure they are only called once. |
|
Methods defined here:
- __call__(self, s, l, t)
- __init__(self, methodCall)
- reset(self)
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class Optional(ParseElementEnhance) |
|
Optional matching of the given expression.
A default return string can also be specified, if the optional expression
is not found. |
|
- Method resolution order:
- Optional
- ParseElementEnhance
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, exprs, default=<pyparsing._NullToken object>)
- __str__(self)
- parseImpl(self, instring, loc, doActions=True)
Data and other attributes defined here:
- __slotnames__ = []
Methods inherited from ParseElementEnhance:
- checkRecursion(self, parseElementList)
- ignore(self, other)
- leaveWhitespace(self)
- streamline(self)
- validate(self, validateTrace=[])
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- copy(self)
- Make a copy of this C{ParserElement}. Useful for defining different parse actions
for the same parsing pattern, using copies of the original parse element.
- parseFile(self, file_or_filename, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class Or(ParseExpression) |
|
Requires that at least one C{ParseExpression} is found.
If two expressions match, the expression that matches the longest string will be used.
May be constructed using the C{'^'} operator. |
|
- Method resolution order:
- Or
- ParseExpression
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, exprs, savelist=False)
- __ixor__(self, other)
- __str__(self)
- checkRecursion(self, parseElementList)
- parseImpl(self, instring, loc, doActions=True)
Methods inherited from ParseExpression:
- __getitem__(self, i)
- append(self, other)
- copy(self)
- ignore(self, other)
- leaveWhitespace(self)
- Extends C{leaveWhitespace} defined in base class, and also invokes C{leaveWhitespace} on
all contained expressions.
- setResultsName(self, name, listAllMatches=False)
- streamline(self)
- validate(self, validateTrace=[])
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- parseFile(self, file_or_filename, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class ParseBaseException(exceptions.Exception) |
|
base exception class for all parsing runtime exceptions |
|
- Method resolution order:
- ParseBaseException
- exceptions.Exception
- exceptions.BaseException
- __builtin__.object
Methods defined here:
- __dir__(self)
- __getattr__(self, aname)
- supported attributes by name are:
- lineno - returns the line number of the exception text
- col - returns the column number of the exception text
- line - returns the line containing the exception text
- __init__(self, pstr, loc=0, msg=None, elem=None)
- # Performance tuning: we construct a *lot* of these, so keep this
# constructor as small and fast as possible
- __repr__(self)
- __str__(self)
- markInputline(self, markerString='>!<')
- Extracts the exception line from the input string, and marks
the location of the exception with a special symbol.
Data descriptors defined here:
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from exceptions.Exception:
- __new__ = <built-in method __new__ of type object>
- T.__new__(S, ...) -> a new object with type S, a subtype of T
Methods inherited from exceptions.BaseException:
- __delattr__(...)
- x.__delattr__('name') <==> del x.name
- __getattribute__(...)
- x.__getattribute__('name') <==> x.name
- __getitem__(...)
- x.__getitem__(y) <==> x[y]
- __getslice__(...)
- x.__getslice__(i, j) <==> x[i:j]
Use of negative indices is not supported.
- __reduce__(...)
- __setattr__(...)
- x.__setattr__('name', value) <==> x.name = value
- __setstate__(...)
- __unicode__(...)
Data descriptors inherited from exceptions.BaseException:
- __dict__
- args
- message
|
class ParseElementEnhance(ParserElement) |
|
Abstract subclass of C{ParserElement}, for combining and post-processing parsed tokens. |
|
- Method resolution order:
- ParseElementEnhance
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, expr, savelist=False)
- __str__(self)
- checkRecursion(self, parseElementList)
- ignore(self, other)
- leaveWhitespace(self)
- parseImpl(self, instring, loc, doActions=True)
- streamline(self)
- validate(self, validateTrace=[])
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- copy(self)
- Make a copy of this C{ParserElement}. Useful for defining different parse actions
for the same parsing pattern, using copies of the original parse element.
- parseFile(self, file_or_filename, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class ParseException(ParseBaseException) |
|
exception thrown when parse expressions don't match class;
supported attributes by name are:
- lineno - returns the line number of the exception text
- col - returns the column number of the exception text
- line - returns the line containing the exception text |
|
- Method resolution order:
- ParseException
- ParseBaseException
- exceptions.Exception
- exceptions.BaseException
- __builtin__.object
Methods inherited from ParseBaseException:
- __dir__(self)
- __getattr__(self, aname)
- supported attributes by name are:
- lineno - returns the line number of the exception text
- col - returns the column number of the exception text
- line - returns the line containing the exception text
- __init__(self, pstr, loc=0, msg=None, elem=None)
- # Performance tuning: we construct a *lot* of these, so keep this
# constructor as small and fast as possible
- __repr__(self)
- __str__(self)
- markInputline(self, markerString='>!<')
- Extracts the exception line from the input string, and marks
the location of the exception with a special symbol.
Data descriptors inherited from ParseBaseException:
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from exceptions.Exception:
- __new__ = <built-in method __new__ of type object>
- T.__new__(S, ...) -> a new object with type S, a subtype of T
Methods inherited from exceptions.BaseException:
- __delattr__(...)
- x.__delattr__('name') <==> del x.name
- __getattribute__(...)
- x.__getattribute__('name') <==> x.name
- __getitem__(...)
- x.__getitem__(y) <==> x[y]
- __getslice__(...)
- x.__getslice__(i, j) <==> x[i:j]
Use of negative indices is not supported.
- __reduce__(...)
- __setattr__(...)
- x.__setattr__('name', value) <==> x.name = value
- __setstate__(...)
- __unicode__(...)
Data descriptors inherited from exceptions.BaseException:
- __dict__
- args
- message
|
class ParseExpression(ParserElement) |
|
Abstract subclass of ParserElement, for combining and post-processing parsed tokens. |
|
- Method resolution order:
- ParseExpression
- ParserElement
- __builtin__.object
Methods defined here:
- __getitem__(self, i)
- __init__(self, exprs, savelist=False)
- __str__(self)
- append(self, other)
- copy(self)
- ignore(self, other)
- leaveWhitespace(self)
- Extends C{leaveWhitespace} defined in base class, and also invokes C{leaveWhitespace} on
all contained expressions.
- setResultsName(self, name, listAllMatches=False)
- streamline(self)
- validate(self, validateTrace=[])
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- parseFile(self, file_or_filename, parseAll=False)
- 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.
- parseImpl(self, instring, loc, doActions=True)
- parseString(self, instring, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class ParseFatalException(ParseBaseException) |
|
user-throwable exception thrown when inconsistent parse content
is found; stops all parsing immediately |
|
- Method resolution order:
- ParseFatalException
- ParseBaseException
- exceptions.Exception
- exceptions.BaseException
- __builtin__.object
Methods inherited from ParseBaseException:
- __dir__(self)
- __getattr__(self, aname)
- supported attributes by name are:
- lineno - returns the line number of the exception text
- col - returns the column number of the exception text
- line - returns the line containing the exception text
- __init__(self, pstr, loc=0, msg=None, elem=None)
- # Performance tuning: we construct a *lot* of these, so keep this
# constructor as small and fast as possible
- __repr__(self)
- __str__(self)
- markInputline(self, markerString='>!<')
- Extracts the exception line from the input string, and marks
the location of the exception with a special symbol.
Data descriptors inherited from ParseBaseException:
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from exceptions.Exception:
- __new__ = <built-in method __new__ of type object>
- T.__new__(S, ...) -> a new object with type S, a subtype of T
Methods inherited from exceptions.BaseException:
- __delattr__(...)
- x.__delattr__('name') <==> del x.name
- __getattribute__(...)
- x.__getattribute__('name') <==> x.name
- __getitem__(...)
- x.__getitem__(y) <==> x[y]
- __getslice__(...)
- x.__getslice__(i, j) <==> x[i:j]
Use of negative indices is not supported.
- __reduce__(...)
- __setattr__(...)
- x.__setattr__('name', value) <==> x.name = value
- __setstate__(...)
- __unicode__(...)
Data descriptors inherited from exceptions.BaseException:
- __dict__
- args
- message
|
class ParseResults(__builtin__.object) |
|
Structured parse results, to provide multiple means of access to the parsed data:
- as a list (C{len(results)})
- by list index (C{results[0], results[1]}, etc.)
- by attribute (C{results.<resultsName>}) |
|
Methods defined here:
- __add__(self, other)
- __bool__(self)
- __contains__(self, k)
- __delitem__(self, i)
- __dir__(self)
- __getattr__(self, name)
- __getitem__(self, i)
- __getstate__(self)
- # add support for pickle protocol
- __iadd__(self, other)
- __init__(self, toklist, name=None, asList=True, modal=True, isinstance=<built-in function isinstance>)
- # Performance tuning: we construct a *lot* of these, so keep this
# constructor as small and fast as possible
- __iter__(self)
- __len__(self)
- __nonzero__ = __bool__(self)
- __radd__(self, other)
- __repr__(self)
- __reversed__(self)
- __setitem__(self, k, v, isinstance=<built-in function isinstance>)
- __setstate__(self, state)
- __str__(self)
- asDict(self)
- Returns the named parse results as dictionary.
- asList(self)
- Returns the parse results as a nested list of matching tokens, all converted to strings.
- asXML(self, doctag=None, namedItemsOnly=False, indent='', formatted=True)
- Returns the parse results as XML. Tags are created for tokens and lists that have defined results names.
- copy(self)
- Returns a new copy of a C{ParseResults} object.
- dump(self, indent='', depth=0)
- Diagnostic method for listing out the contents of a C{ParseResults}.
Accepts an optional C{indent} argument so that this string can be embedded
in a nested display of other data.
- get(self, key, defaultValue=None)
- Returns named result matching the given key, or if there is no
such name, then returns the given C{defaultValue} or C{None} if no
C{defaultValue} is specified.
- getName(self)
- Returns the results name for this token expression.
- insert(self, index, insStr)
- Inserts new element at location index in the list of parsed tokens.
- items(self)
- Returns all named result keys and values as a list of tuples.
- keys(self)
- Returns all named result keys.
- pop(self, index=-1)
- Removes and returns item at specified index (default=last).
Will work with either numeric indices or dict-key indicies.
- values(self)
- Returns all named result values.
Static methods defined here:
- __new__(cls, toklist, name=None, asList=True, modal=True)
- #~ __slots__ = ( "__toklist", "__tokdict", "__doinit", "__name", "__parent", "__accumNames", "__weakref__" )
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class ParserElement(__builtin__.object) |
|
Abstract base level parser element class. |
|
Methods defined here:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __init__(self, savelist=False)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __str__(self)
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- copy(self)
- Make a copy of this C{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
C{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, parseAll=False)
- 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.
- parseImpl(self, instring, loc, doActions=True)
- parseString(self, instring, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods defined here:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes defined here:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class QuotedString(Token) |
|
Token for matching strings that are delimited by quoting characters. |
|
- Method resolution order:
- QuotedString
- Token
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, quoteChar, escChar=None, escQuote=None, multiline=False, unquoteResults=True, endQuoteChar=None)
- Defined with the following parameters:
- quoteChar - string of one or more characters defining the quote delimiting string
- escChar - character to escape quotes, typically backslash (default=None)
- escQuote - special quote sequence to escape an embedded quote string (such as SQL's "" to escape an embedded ") (default=None)
- multiline - boolean indicating whether quotes can span multiple lines (default=C{False})
- unquoteResults - boolean indicating whether the matched text should be unquoted (default=C{True})
- endQuoteChar - string of one or more characters defining the end of the quote delimited string (default=C{None} => same as quoteChar)
- __str__(self)
- parseImpl(self, instring, loc, doActions=True)
Methods inherited from Token:
- setName(self, name)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- copy(self)
- Make a copy of this C{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
C{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, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class Regex(Token) |
|
Token for matching strings that match a given regular expression.
Defined with string specifying the regular expression in a form recognized by the inbuilt Python re module. |
|
- Method resolution order:
- Regex
- Token
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, pattern, flags=0)
- The parameters C{pattern} and C{flags} are passed to the C{re.compile()} function as-is. See the Python C{re} module for an explanation of the acceptable patterns and flags.
- __str__(self)
- parseImpl(self, instring, loc, doActions=True)
Data and other attributes defined here:
- __slotnames__ = []
- compiledREtype = <type '_sre.SRE_Pattern'>
- Compiled regular expression objects
Methods inherited from Token:
- setName(self, name)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- copy(self)
- Make a copy of this C{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
C{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, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class SkipTo(ParseElementEnhance) |
|
Token for skipping over all undefined text until the matched expression is found.
If C{include} is set to true, the matched expression is also parsed (the skipped text
and matched expression are returned as a 2-element list). The C{ignore}
argument is used to define grammars (typically quoted strings and comments) that
might contain false matches. |
|
- Method resolution order:
- SkipTo
- ParseElementEnhance
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, other, include=False, ignore=None, failOn=None)
- parseImpl(self, instring, loc, doActions=True)
Methods inherited from ParseElementEnhance:
- __str__(self)
- checkRecursion(self, parseElementList)
- ignore(self, other)
- leaveWhitespace(self)
- streamline(self)
- validate(self, validateTrace=[])
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- copy(self)
- Make a copy of this C{ParserElement}. Useful for defining different parse actions
for the same parsing pattern, using copies of the original parse element.
- parseFile(self, file_or_filename, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class StringEnd(_PositionToken) |
|
Matches if current position is at the end of the parse string |
|
- Method resolution order:
- StringEnd
- _PositionToken
- Token
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self)
- parseImpl(self, instring, loc, doActions=True)
Methods inherited from Token:
- setName(self, name)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __str__(self)
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- copy(self)
- Make a copy of this C{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
C{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, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class StringStart(_PositionToken) |
|
Matches if current position is at the beginning of the parse string |
|
- Method resolution order:
- StringStart
- _PositionToken
- Token
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self)
- parseImpl(self, instring, loc, doActions=True)
Methods inherited from Token:
- setName(self, name)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __str__(self)
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- copy(self)
- Make a copy of this C{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
C{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, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class Suppress(TokenConverter) |
|
Converter for ignoring the results of a parsed expression. |
|
- Method resolution order:
- Suppress
- TokenConverter
- ParseElementEnhance
- ParserElement
- __builtin__.object
Methods defined here:
- postParse(self, instring, loc, tokenlist)
- suppress(self)
Data and other attributes defined here:
- __slotnames__ = []
Methods inherited from TokenConverter:
- __init__(self, expr, savelist=False)
Methods inherited from ParseElementEnhance:
- __str__(self)
- checkRecursion(self, parseElementList)
- ignore(self, other)
- leaveWhitespace(self)
- parseImpl(self, instring, loc, doActions=True)
- streamline(self)
- validate(self, validateTrace=[])
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- copy(self)
- Make a copy of this C{ParserElement}. Useful for defining different parse actions
for the same parsing pattern, using copies of the original parse element.
- parseFile(self, file_or_filename, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class Token(ParserElement) |
|
Abstract C{ParserElement} subclass, for defining atomic matching patterns. |
|
- Method resolution order:
- Token
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self)
- setName(self, name)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __str__(self)
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- copy(self)
- Make a copy of this C{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
C{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, parseAll=False)
- 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.
- parseImpl(self, instring, loc, doActions=True)
- parseString(self, instring, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class TokenConverter(ParseElementEnhance) |
|
Abstract subclass of C{ParseExpression}, for converting parsed results. |
|
- Method resolution order:
- TokenConverter
- ParseElementEnhance
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, expr, savelist=False)
Methods inherited from ParseElementEnhance:
- __str__(self)
- checkRecursion(self, parseElementList)
- ignore(self, other)
- leaveWhitespace(self)
- parseImpl(self, instring, loc, doActions=True)
- streamline(self)
- validate(self, validateTrace=[])
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- copy(self)
- Make a copy of this C{ParserElement}. Useful for defining different parse actions
for the same parsing pattern, using copies of the original parse element.
- parseFile(self, file_or_filename, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class Upcase(TokenConverter) |
|
Converter to upper case all matching tokens. |
|
- Method resolution order:
- Upcase
- TokenConverter
- ParseElementEnhance
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, *args)
- postParse(self, instring, loc, tokenlist)
Methods inherited from ParseElementEnhance:
- __str__(self)
- checkRecursion(self, parseElementList)
- ignore(self, other)
- leaveWhitespace(self)
- parseImpl(self, instring, loc, doActions=True)
- streamline(self)
- validate(self, validateTrace=[])
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- copy(self)
- Make a copy of this C{ParserElement}. Useful for defining different parse actions
for the same parsing pattern, using copies of the original parse element.
- parseFile(self, file_or_filename, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class White(Token) |
|
Special matching class for matching whitespace. Normally, whitespace is ignored
by pyparsing grammars. This class is included when some whitespace structures
are significant. Define with a string containing the whitespace characters to be
matched; default is C{" \t\r\n"}. Also takes optional C{min}, C{max}, and C{exact} arguments,
as defined for the C{L{Word}} class. |
|
- Method resolution order:
- White
- Token
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, ws=' \t\r\n', min=1, max=0, exact=0)
- parseImpl(self, instring, loc, doActions=True)
Data and other attributes defined here:
- whiteStrs = {'\t': '<TAB>', '\n': '<LF>', '\x0c': '<FF>', '\r': '<CR>', ' ': '<SPC>'}
Methods inherited from Token:
- setName(self, name)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __str__(self)
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- copy(self)
- Make a copy of this C{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
C{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, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class Word(Token) |
|
Token for matching words composed of allowed character sets.
Defined with string containing all allowed initial characters,
an optional string containing allowed body characters (if omitted,
defaults to the initial character set), and an optional minimum,
maximum, and/or exact length. The default value for C{min} is 1 (a
minimum value < 1 is not valid); the default values for C{max} and C{exact}
are 0, meaning no maximum or exact length restriction. An optional
C{exclude} parameter can list characters that might be found in
the input C{bodyChars} string; useful to define a word of all printables
except for one or two characters, for instance. |
|
- Method resolution order:
- Word
- Token
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, initChars, bodyChars=None, min=1, max=0, exact=0, asKeyword=False, excludeChars=None)
- __str__(self)
- parseImpl(self, instring, loc, doActions=True)
Data and other attributes defined here:
- __slotnames__ = []
Methods inherited from Token:
- setName(self, name)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- copy(self)
- Make a copy of this C{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
C{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, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class WordEnd(_PositionToken) |
|
Matches if the current position is at the end of a Word, and
is not followed by any character in a given set of C{wordChars}
(default=C{printables}). To emulate the C{} behavior of regular expressions,
use C{WordEnd(alphanums)}. C{WordEnd} will also match at the end of
the string being parsed, or at the end of a line. |
|
- Method resolution order:
- WordEnd
- _PositionToken
- Token
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, wordChars='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~')
- parseImpl(self, instring, loc, doActions=True)
Methods inherited from Token:
- setName(self, name)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __str__(self)
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- copy(self)
- Make a copy of this C{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
C{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, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class WordStart(_PositionToken) |
|
Matches if the current position is at the beginning of a Word, and
is not preceded by any character in a given set of C{wordChars}
(default=C{printables}). To emulate the C{} behavior of regular expressions,
use C{WordStart(alphanums)}. C{WordStart} will also match at the beginning of
the string being parsed, or at the beginning of a line. |
|
- Method resolution order:
- WordStart
- _PositionToken
- Token
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, wordChars='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~')
- parseImpl(self, instring, loc, doActions=True)
Methods inherited from Token:
- setName(self, name)
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __str__(self)
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- checkRecursion(self, parseElementList)
- copy(self)
- Make a copy of this C{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
C{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, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- 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 C{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.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- streamline(self)
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
- validate(self, validateTrace=[])
- Check defined expressions for valid structure, check for infinite recursive definitions.
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
|
class ZeroOrMore(ParseElementEnhance) |
|
Optional repetition of zero or more of the given expression. |
|
- Method resolution order:
- ZeroOrMore
- ParseElementEnhance
- ParserElement
- __builtin__.object
Methods defined here:
- __init__(self, expr)
- __str__(self)
- parseImpl(self, instring, loc, doActions=True)
- setResultsName(self, name, listAllMatches=False)
Methods inherited from ParseElementEnhance:
- checkRecursion(self, parseElementList)
- ignore(self, other)
- leaveWhitespace(self)
- streamline(self)
- validate(self, validateTrace=[])
Methods inherited from ParserElement:
- __add__(self, other)
- Implementation of + operator - returns C{L{And}}
- __and__(self, other)
- Implementation of & operator - returns C{L{Each}}
- __call__(self, name)
- Shortcut for C{L{setResultsName}}, with C{listAllMatches=default}::
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
could be written as::
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
- __eq__(self, other)
- __hash__(self)
- __invert__(self)
- Implementation of ~ operator - returns C{L{NotAny}}
- __mul__(self, other)
- Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
- __ne__(self, other)
- __or__(self, other)
- Implementation of | operator - returns C{L{MatchFirst}}
- __radd__(self, other)
- Implementation of + operator when left operand is not a C{L{ParserElement}}
- __rand__(self, other)
- Implementation of & operator when left operand is not a C{L{ParserElement}}
- __repr__(self)
- __req__(self, other)
- __rmul__(self, other)
- __rne__(self, other)
- __ror__(self, other)
- Implementation of | operator when left operand is not a C{L{ParserElement}}
- __rsub__(self, other)
- Implementation of - operator when left operand is not a C{L{ParserElement}}
- __rxor__(self, other)
- Implementation of ^ operator when left operand is not a C{L{ParserElement}}
- __sub__(self, other)
- Implementation of - operator, returns C{L{And}} with error stop
- __xor__(self, other)
- Implementation of ^ operator - returns C{L{Or}}
- addParseAction(self, *fns, **kwargs)
- Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
- copy(self)
- Make a copy of this C{ParserElement}. Useful for defining different parse actions
for the same parsing pattern, using copies of the original parse element.
- parseFile(self, file_or_filename, parseAll=False)
- 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, parseAll=False)
- Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
- parseWithTabs(self)
- Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
- postParse(self, instring, loc, tokenlist)
- preParse(self, instring, loc)
- scanString(self, instring, maxMatches=9223372036854775807, overlap=False)
- Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
- searchString(self, instring, maxMatches=9223372036854775807)
- Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
- setBreak(self, breakFlag=True)
- Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
- setDebug(self, flag=True)
- Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
- 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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.
- setName(self, name)
- Define name for this expression, for use in debugging.
- setParseAction(self, *fns, **kwargs)
- Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{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.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
- setWhitespaceChars(self, chars)
- Overrides the default whitespace chars
- suppress(self)
- Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
- transformString(self, instring)
- Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
- tryParse(self, instring, loc)
Static methods inherited from ParserElement:
- 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 C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
- inlineLiteralsUsing(cls)
- Set class to be used for inclusion of string literals into a parser.
- resetCache()
- setDefaultWhitespaceChars(chars)
- Overrides the default whitespace chars
Data descriptors inherited from ParserElement:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes inherited from ParserElement:
- DEFAULT_WHITE_CHARS = ' \n\t\r'
- literalStringClass = <class 'pyparsing.Literal'>
- Token to exactly match a specified string.
- verbose_stacktrace = False
| |