Class Each
source code
object --+
|
ParserElement --+
|
ParseExpression --+
|
Each
Requires all given ParseExpressions to be found, but in
any order. Expressions may be separated by whitespace. May be constructed
using the '&' operator.
Example:
color = oneOf("RED ORANGE YELLOW GREEN BLUE PURPLE BLACK WHITE BROWN")
shape_type = oneOf("SQUARE CIRCLE TRIANGLE STAR HEXAGON OCTAGON")
integer = Word(nums)
shape_attr = "shape:" + shape_type("shape")
posn_attr = "posn:" + Group(integer("x") + ',' + integer("y"))("posn")
color_attr = "color:" + color("color")
size_attr = "size:" + integer("size")
# use Each (using operator '&') to accept attributes in any order
# (shape and posn are required, color and size are optional)
shape_spec = shape_attr & posn_attr & Optional(color_attr) & Optional(size_attr)
shape_spec.runTests('''
shape: SQUARE color: BLACK posn: 100, 120
shape: CIRCLE size: 50 color: BLUE posn: 50,80
color:GREEN size:20 shape:TRIANGLE posn:20,40
'''
)
prints:
shape: SQUARE color: BLACK posn: 100, 120
['shape:', 'SQUARE', 'color:', 'BLACK', 'posn:', ['100', ',', '120']]
- color: BLACK
- posn: ['100', ',', '120']
- x: 100
- y: 120
- shape: SQUARE
shape: CIRCLE size: 50 color: BLUE posn: 50,80
['shape:', 'CIRCLE', 'size:', '50', 'color:', 'BLUE', 'posn:', ['50', ',', '80']]
- color: BLUE
- posn: ['50', ',', '80']
- x: 50
- y: 80
- shape: CIRCLE
- size: 50
color: GREEN size: 20 shape: TRIANGLE posn: 20,40
['color:', 'GREEN', 'size:', '20', 'shape:', 'TRIANGLE', 'posn:', ['20', ',', '40']]
- color: GREEN
- posn: ['20', ',', '40']
- x: 20
- y: 40
- shape: TRIANGLE
- size: 20
|
|
__init__(self,
exprs,
savelist=True)
x.__init__(...) initializes x; see help(type(x)) for signature |
source code
|
|
|
|
|
|
|
|
|
|
|
|
Inherited from ParseExpression:
__getitem__,
append,
copy,
ignore,
leaveWhitespace,
setResultsName,
streamline,
validate
Inherited from ParserElement:
__add__,
__and__,
__call__,
__eq__,
__hash__,
__invert__,
__mul__,
__ne__,
__or__,
__radd__,
__rand__,
__repr__,
__req__,
__rmul__,
__rne__,
__ror__,
__rsub__,
__rxor__,
__sub__,
__xor__,
addCondition,
addParseAction,
canParseNext,
matches,
parseFile,
parseString,
parseWithTabs,
postParse,
preParse,
runTests,
scanString,
searchString,
setBreak,
setDebug,
setDebugActions,
setFailAction,
setName,
setParseAction,
setWhitespaceChars,
split,
suppress,
transformString,
tryParse
Inherited from object:
__delattr__,
__format__,
__getattribute__,
__new__,
__reduce__,
__reduce_ex__,
__setattr__,
__sizeof__,
__subclasshook__
|
|
Inherited from object:
__class__
|
__init__(self,
exprs,
savelist=True)
(Constructor)
| source code
|
x.__init__(...) initializes x; see help(type(x)) for signature
- Overrides:
object.__init__
- (inherited documentation)
|
__str__(self)
(Informal representation operator)
| source code
|
str(x)
- Overrides:
object.__str__
- (inherited documentation)
|