In a presumably very common usecase the results of the lineno(...) function are wrong, when the parsed string contains tab characters.
A warning about this (and instructions on what to do) should be added to the documentation of the lineno(...) function.
(The same applies to col(...) and line(...))
The computation of line numbers usually happens after the parse function has returned.
When tab expansion takes place, parsing and line number computation work on different strings. The tab expansion makes the string longer and then the parser works on the enlarged string. Therefore the index (loc) reported to parse actions or exceptions is not valid for the original input string.
There are two workarounds if the input string may contain tabs:
- Turn off tab expansion by calling:
- Perform tab expansion on the original string:
PS: Why is tab expansion on by default? Are there any obscure consequences of tabs in the input string?