Skip to content

Commit 516a9a1

Browse files
committed
micropython compatible RE_NUMBER
1 parent 3e4116d commit 516a9a1

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

src/tomli/_re.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,8 @@
1212
_TIME_RE_STR = r"([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])(?:\.([0-9]{1,6})[0-9]*)?"
1313

1414
RE_NUMBER = re.compile(
15-
r"""
16-
0
17-
(?:
18-
x[0-9A-Fa-f](?:_?[0-9A-Fa-f])* # hex
19-
|
20-
b[01](?:_?[01])* # bin
21-
|
22-
o[0-7](?:_?[0-7])* # oct
23-
)
24-
|
25-
[+-]?(?:0|[1-9](?:_?[0-9])*) # dec, integer part
26-
(?P<floatpart>
27-
(?:\.[0-9](?:_?[0-9])*)? # optional fractional part
28-
(?:[eE][+-]?[0-9](?:_?[0-9])*)? # optional exponent part
29-
)
30-
""",
31-
flags=re.VERBOSE,
15+
r"""0(x[0-9A-Fa-f](_?[0-9A-Fa-f])*|b[01](_?[01])*|o[0-7](_?[0-7])*)|[+-]?(0|[1-9](_?[0-9])*)((\.[0-9](_?[0-9])*)?([eE][+-]?[0-9](_?[0-9])*)?)"""
16+
3217
)
3318
RE_LOCALTIME = re.compile(_TIME_RE_STR)
3419
RE_DATETIME = re.compile(
@@ -97,6 +82,6 @@ def match_to_localtime(match):
9782

9883

9984
def match_to_number(match, parse_float):
100-
if match.group("floatpart"):
85+
if match.group(7):
10186
return parse_float(match.group())
10287
return int(match.group(), 0)

0 commit comments

Comments
 (0)