From: helly Date: Sat, 5 May 2007 17:14:38 +0000 (+0000) Subject: - Improve error messages X-Git-Tag: 0.13.6~145 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1e05d1e1cd5d12b928a50516b6766b375b63582e;p=re2c - Improve error messages --- diff --git a/re2c/bootstrap/scanner.cc b/re2c/bootstrap/scanner.cc index 3a607375..20c6d45a 100644 --- a/re2c/bootstrap/scanner.cc +++ b/re2c/bootstrap/scanner.cc @@ -1,10 +1,11 @@ -/* Generated by re2c 0.13.0.dev on Tue May 1 09:59:49 2007 */ +/* Generated by re2c 0.13.0.dev on Sat May 5 19:12:48 2007 */ #line 1 "scanner.re" /* $Id$ */ #include #include #include #include +#include #include "scanner.h" #include "parser.h" #include "y.tab.h" @@ -17,8 +18,7 @@ extern YYSTYPE yylval; #define MAX(a,b) (((a)>(b))?(a):(b)) #endif -#define BSIZE 8192 - +#define BSIZE 8192 #define YYCTYPE unsigned char #define YYCURSOR cursor #define YYLIMIT lim @@ -1585,6 +1585,21 @@ void Scanner::fatal(uint ofs, const char *msg) const exit(1); } +void Scanner::fatalf(const char *fmt, ...) const +{ + char szBuf[4096]; + + va_list args; + + va_start(args, fmt); + vsnprintf(szBuf, sizeof(szBuf), fmt, args); + va_end(args); + + szBuf[sizeof(szBuf)-1] = '0'; + + fatal(szBuf); +} + Scanner::~Scanner() { if (bot) diff --git a/re2c/code.cc b/re2c/code.cc index 1acdba2d..307622b6 100644 --- a/re2c/code.cc +++ b/re2c/code.cc @@ -2051,7 +2051,7 @@ void Scanner::config(const Str& cfg, const Str& val) std::make_pair(cfg.to_string().substr(sizeof("variable:") - 1), strVal) ).second) { - fatal("variable already being used and cannot be changed"); + fatalf("variable '%s' already being used and cannot be changed", cfg.to_string().c_str()); } } else if (mapDefineKeys.find(cfg.to_string()) != mapDefineKeys.end()) @@ -2060,7 +2060,7 @@ void Scanner::config(const Str& cfg, const Str& val) std::make_pair(cfg.to_string().substr(sizeof("define:") - 1), strVal) ).second) { - fatal("define already being used and cannot be changed"); + fatalf("define '%s' already being used and cannot be changed", cfg.to_string().c_str()); } } else if (mapLabelKeys.find(cfg.to_string()) != mapLabelKeys.end()) @@ -2069,7 +2069,7 @@ void Scanner::config(const Str& cfg, const Str& val) std::make_pair(cfg.to_string().substr(sizeof("label:") - 1), strVal) ).second) { - fatal("label already being used and cannot be changed"); + fatalf("label '%s' already being used and cannot be changed", cfg.to_string().c_str()); } } else diff --git a/re2c/scanner.h b/re2c/scanner.h index a15e96d6..cce224dc 100644 --- a/re2c/scanner.h +++ b/re2c/scanner.h @@ -32,6 +32,7 @@ public: int echo(); int scan(); + void fatalf(const char*, ...) const; void fatal(const char*) const; void fatal(uint, const char*) const; diff --git a/re2c/scanner.re b/re2c/scanner.re index a03008af..5e2ff816 100644 --- a/re2c/scanner.re +++ b/re2c/scanner.re @@ -3,6 +3,7 @@ #include #include #include +#include #include "scanner.h" #include "parser.h" #include "y.tab.h" @@ -15,8 +16,7 @@ extern YYSTYPE yylval; #define MAX(a,b) (((a)>(b))?(a):(b)) #endif -#define BSIZE 8192 - +#define BSIZE 8192 #define YYCTYPE unsigned char #define YYCURSOR cursor #define YYLIMIT lim @@ -492,6 +492,21 @@ void Scanner::fatal(uint ofs, const char *msg) const exit(1); } +void Scanner::fatalf(const char *fmt, ...) const +{ + char szBuf[4096]; + + va_list args; + + va_start(args, fmt); + vsnprintf(szBuf, sizeof(szBuf), fmt, args); + va_end(args); + + szBuf[sizeof(szBuf)-1] = '0'; + + fatal(szBuf); +} + Scanner::~Scanner() { if (bot)