Skip to content

Fix number parsing issues

finesse importer requested to merge fix/fractional-tokenisation into develop

Closes #437 (closed), as well as adding more tests and special error handling for a situation discovered in the process of debugging - leading zeros on integers don't parse either (nor do they parse in Python) but the error wasn't clear so this was made clearer. I also improved the docs on what exactly constitutes the different types of number.

While it has no practical effect as far as I can tell, the fix here also changes the behaviour of float parsing in the case of numbers that could be integers. Previously any KatScript floats that could be parsed as ints, like "5.0", were cast to integers automatically. As far as I remember this behaviour was copied from Phil's original parser, but it is a bit strange because it meant even "5." parsed as integer 5, even though writing something like "5." is a common pattern in e.g. C to force something that could be an int to stay as a float. Now the KatScript parser tries to cast whatever the string is to an int, but if that fails, it becomes a float. And since Python considers "5." to have no integer representation, this means it stays as a float. Incidentally this also passes the burden of interpretation of what constitutes an int or float to Python, which is nice (for us).

Edited by finesse importer

Merge request reports