API Reference for Enthought Tool Suite 3.2.0
Parser for various kinds of CSS values as per CSS2 spec section 4.3
integer = Word('0123456789').setParseAction(asInt)
the spec says that the unit is only optional for a 0 length, but there are just too many places where a default is permitted. TODO: Maybe should use a ctor like optional to let clients declare it?
length = ((lengthValue + Optional(lengthUnit, default = None)) + StringEnd())
lengthUnit = oneOf([ 'em', 'ex', 'px', 'pt', 'in', 'cm', 'mm', 'pc', '%' ], caseless = True)
lengthValue = Combine((Optional(sign) + number)).setParseAction(asFloatOrInt)
number = Combine((((Optional(Word('0123456789')) + Literal('.')) + Word('01234567890')) | integer))
sign = oneOf('+ -')
signedNumber = Combine((Optional(sign) + number)).setParseAction(asFloat)
Return an int if possible, otherwise a float
| Local name | Refers to |
|---|---|
| CaselessLiteral | pyparsing.CaselessLiteral |
| Combine | pyparsing.Combine |
| Literal | pyparsing.Literal |
| oneOf | pyparsing.oneOf |
| OneOrMore | pyparsing.OneOrMore |
| Optional | pyparsing.Optional |
| StringEnd | pyparsing.StringEnd |
| Word | pyparsing.Word |
© Copyright 2002-2009 Enthought, Inc.