Closed SerafimArts closed 7 years ago
It would be good to show (in UnexpectedToken exception at line 0) in this case not the previous token (null)
.
Maybe some other message, defined in *.pp
file?
%undefined T_UNDEFINED
Unexpected token (T_UNDEFINED) at line 0 and column 0:
some any
↑
Thank @Pierozi for handling this PR and for the review!
@Hywan The problem can be reproduced if the first token and/or character does not correspond to any rule (rule == defined token).
@SerafimArts I took the liberty to implement another approach, please see https://github.com/hoaproject/Compiler/commit/23cc8e191bdd9dd3aec73c7b450200ebccc0deb7. The patch is very minimal too.
You are right, an error token is not always found when backtracking, especially when it happens at the very first position of the text being parsed. In this particular edge case, the current token is used as the error token. So with your example, it produces this error:
Hoa\Compiler\Llk\Parser::parse(): (0) Unexpected token "type" (T_NAME) at line 1 and column 1:
type Test { }
↑
instead of:
Hoa\Compiler\Llk\Parser::parse(): (0) Unexpected token "(null)" ((null)) at line 1 and column 1:
type Test { }
↑
as your patch suggested.
Thank you very much for this excellent bug report and your patience!
3.17.08.08 has been released because this is an important bug fix.
@Hywan i think this commit https://github.com/hoaproject/Compiler/commit/23cc8e191bdd9dd3aec73c7b450200ebccc0deb7 are better. I also thought about it, but decided to limit myself to simple bugfix =)
:+1: The harder part was to find the bug, and what you did was excellent. Thank you!
Fix "strrpos()" bug when offset is greater than the length of haystack string. Fix https://github.com/hoaproject/Compiler/issues/71