Skip to content
Snippets Groups Projects
Commit 35adfade authored by Hugo Hörnquist's avatar Hugo Hörnquist
Browse files

Fail louder in json2 if invalid data.

parent d25e1fbc
No related branches found
No related tags found
No related merge requests found
......@@ -58,13 +58,17 @@ def handle_int(xs: list[MatchObject]) -> list[int]:
Note that this only works if adjacant joining is working.
"""
assert type(xs[0]) is str
return [int(xs[0])]
def _handle_exp(parts: list[MatchObject]) -> list[int]:
"""Convert the exponential part of a float to its integer value."""
total = force(__find('dig', parts)).matched[0]
dig = __find('dig', parts)
assert isinstance(dig, MatchCompound)
total = dig.matched[0]
if sign := __find('sign', parts):
assert isinstance(sign, MatchCompound)
if sign.matched[0][0] == '-':
total *= -1
return [total]
......@@ -91,13 +95,16 @@ def _handle_number(parts: list[MatchObject]) -> list[float]:
print(parts)
# string: str = ''
if base := __find('base', parts):
assert isinstance(base, MatchCompound)
total += base.matched[0]
if frac := __find('fractional', parts):
assert isinstance(frac, MatchCompound)
d = frac.matched[0]
total += d / 10**(math.floor(math.log10(d)) + 1)
if exp := __find('exp', parts):
assert isinstance(exp, MatchCompound)
total *= 10**exp.matched[0]
if __find('minus', parts):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment