From 4dee8c62c965acbe5621e9e9fdb7eb6484f11987 Mon Sep 17 00:00:00 2001 From: Hayodea Hakol Date: Tue, 14 Jan 2025 23:13:02 -0400 Subject: [PATCH] devSpec:yacc: We now print out the current lex token string We used some preprocessor logic to enable access to yytext and now we can have verbose, useful error messages from the parser :) --- hcore/deviceManager/deviceSpecp.yy | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hcore/deviceManager/deviceSpecp.yy b/hcore/deviceManager/deviceSpecp.yy index 6027abc..3cc9bfd 100644 --- a/hcore/deviceManager/deviceSpecp.yy +++ b/hcore/deviceManager/deviceSpecp.yy @@ -25,13 +25,20 @@ #undef yylex #define yylex deviceSpecllex +#ifdef yytext +#undef yytext +#endif +#define yytext deviceSpecltext + // Declare the symbols that our lexer will export. int yylex(void); +extern char* yytext; // Declare yytext to access the current token text void yyerror(const char *message) { - throw std::runtime_error( + throw std::runtime_error( std::string("deviceSpec parser error: ") - + std::string(message)); + + std::string(message) + + " at token: " + std::string(yytext)); } %}