This project is read-only.

Expose current token for error messages (yyerror)


The problem with current implementation is that you pass already formatted error message to yyerror. This is not suitable -- one case, very needed, is automatic testing. In such I have to keep the messages exactly the same no matter what tool I use.

Currently fetching current token (NextToken property in Parser) is possible with some hackery, but it would be much better if there was "legal" API for it.

One thing I can think of is changing how you pass error message. Correct me if I am wrong, but args are not used at all, when the data arrive to yyerror, the format actually is the entire message. One approach would be to change it -- format would hold at least one placeholder, and first args ALWAYS would contain NextToken value.

This way the API itself would not change at all, but the user wanting current token could simply grab args[0] to get it or call String.Format(format, args) as usual to get full error message.