Commit 57436e0b authored by Stefan Behnel's avatar Stefan Behnel

Support numeric literals like "0x_1", as allowed by Python.

parent 634324ff
......@@ -29,15 +29,19 @@ def make_lexicon():
def underscore_digits(d):
return Rep1(d) + Rep(Str("_") + Rep1(d))
def prefixed_digits(prefix, digits):
return Any(prefix) + Opt(Str("_")) + underscore_digits(digits)
decimal = underscore_digits(digit)
dot = Str(".")
exponent = Any("Ee") + Opt(Any("+-")) + decimal
decimal_fract = (decimal + dot + Opt(decimal)) | (dot + decimal)
name = letter + Rep(letter | digit)
intconst = decimal | (Str("0") + ((Any("Xx") + underscore_digits(hexdigit)) |
(Any("Oo") + underscore_digits(octdigit)) |
(Any("Bb") + underscore_digits(bindigit)) ))
# FIXME: in PY_VERSION_HEX < 2, octal literals can start with plain 0, but not in Py3.
intconst = decimal | (Str("0") + (prefixed_digits("Xx", hexdigit) |
prefixed_digits("Oo", octdigit) |
prefixed_digits("Bb", bindigit) ))
intsuffix = (Opt(Any("Uu")) + Opt(Any("Ll")) + Opt(Any("Ll"))) | (Opt(Any("Ll")) + Opt(Any("Ll")) + Opt(Any("Uu")))
intliteral = intconst + intsuffix
fltconst = (decimal_fract + Opt(exponent)) | (decimal + exponent)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment