Home | Trees | Indices | Help |
|
---|
|
object --+ | ParserElement --+ | ParseElementEnhance --+ | _MultipleMatch --+ | OneOrMore
Repetition of one or more of the given expression.
Parameters:
None
) - expression for a terminating
sentinel (only required if the sentinel would ordinarily match the
repetition expression)
Example:
data_word = Word(alphas) label = data_word + FollowedBy(':') attr_expr = Group(label + Suppress(':') + OneOrMore(data_word).setParseAction(' '.join)) text = "shape: SQUARE posn: upper left color: BLACK" OneOrMore(attr_expr).parseString(text).pprint() # Fail! read 'color' as data instead of next label -> [['shape', 'SQUARE color']] # use stopOn attribute for OneOrMore to avoid reading label string as part of the data attr_expr = Group(label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join)) OneOrMore(attr_expr).parseString(text).pprint() # Better -> [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'BLACK']] # could also be written as (attr_expr * (1,)).parseString(text).pprint()
Static Methods | |
Inherited from |
Class Variables | |
__slotnames__ =
|
|
Inherited from |
Properties | |
Inherited from |
Method Details |
str(x)
|
Define name for referencing matching tokens as a nested attribute of
the returned parse results. NOTE: this returns a *copy* of the original
You can also set results names using the abbreviated syntax,
Example: date_str = (integer.setResultsName("year") + '/' + integer.setResultsName("month") + '/' + integer.setResultsName("day")) # equivalent form: date_str = integer("year") + '/' + integer("month") + '/' + integer("day")
|
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sat Sep 10 10:21:42 2016 | http://epydoc.sourceforge.net |