std::ostream& out;
char *bot, *tok, *ptr, *cur, *pos, *lim, *top, *eof, *ctx;
uint tchar, tline, cline, iscfg, buf_size;
+ bool in_parse;
private:
char *fill(char*, uint);
Scanner(std::istream&, std::ostream&);
~Scanner();
- enum EchoState {
+ enum ParseMode {
Stop,
Parse,
- Reuse,
+ Reuse
};
- EchoState echo();
+ ParseMode echo();
int scan();
-
+
+ uint get_cline() const;
+ void set_in_parse(bool new_in_parse);
+ void fatal_at(uint line, uint ofs, const char *msg) const;
+ void fatalf_at(uint line, const char*, ...) const;
void fatalf(const char*, ...) const;
void fatal(const char*) const;
void fatal(uint, const char*) const;
RegExp * mkDot() const;
};
+inline uint Scanner::get_cline() const
+{
+ return cline;
+}
+
inline void Scanner::fatal(const char *msg) const
{
fatal(0, msg);
, out(o)
, bot(NULL), tok(NULL), ptr(NULL), cur(NULL), pos(NULL), lim(NULL)
, top(NULL), eof(NULL), ctx(NULL), tchar(0), tline(0), cline(1), iscfg(0)
+ , in_parse(false)
{
;
}
lim -= cnt;
}
need = MAX(need, BSIZE);
- if((top - lim) < need)
+ if(static_cast<uint>(top - lim) < need)
{
char *buf = new char[(lim - bot) + need];
if (!buf)
value = [^\r\n; \t]* | dstring | sstring;
*/
-Scanner::EchoState Scanner::echo()
+Scanner::ParseMode Scanner::echo()
{
char *cursor = cur;
bool ignore_eoc = false;
{
return Stop;
}
-
+
tok = cursor;
echo:
/*!re2c
*/
}
-
int Scanner::scan()
{
char *cursor = cur;
*/
}
-void Scanner::fatal(uint ofs, const char *msg) const
+void Scanner::set_in_parse(bool new_in_parse)
+{
+ in_parse = new_in_parse;
+}
+
+void Scanner::fatal_at(uint line, uint ofs, const char *msg) const
{
out.flush();
std::cerr << "re2c: error: "
- << "line " << tline << ", column " << (tchar + ofs + 1) << ": "
+ << "line " << line << ", column " << (tchar + ofs + 1) << ": "
<< msg << std::endl;
exit(1);
}
+void Scanner::fatal(uint ofs, const char *msg) const
+{
+ fatal_at(in_parse ? tline : cline, ofs, msg);
+}
+
+void Scanner::fatalf_at(uint line, 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_at(line, 0, szBuf);
+}
+
void Scanner::fatalf(const char *fmt, ...) const
{
char szBuf[4096];