-/* Generated by re2c 0.13.4.dev on Mon Mar 24 14:11:59 2008 */
+/* Generated by re2c 0.13.4.dev on Mon Mar 24 15:31:27 2008 */
/* $Id$ */
#include <stdlib.h>
#include <string.h>
namespace re2c
{
-Scanner::Scanner(std::istream& i, std::ostream& o)
- : in(i)
- , out(o)
- , bot(NULL), tok(NULL), ptr(NULL), cur(NULL), pos(NULL), lim(NULL)
+ScannerState::ScannerState()
+ : 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)
{
- ;
+}
+
+Scanner::Scanner(std::istream& i, std::ostream& o)
+ : in(i), out(o)
+{
}
char *Scanner::fill(char *cursor, uint need)
if (cnt)
{
memmove(bot, tok, top - tok);
- tok = bot;
+ tok = bot;
ptr -= cnt;
cursor -= cnt;
pos -= cnt;
++YYCURSOR;
yy115:
{
- if(cursor == eof) RETURN(0);
+ if (cursor == eof) RETURN(0);
pos = cursor;
cline++;
goto scan;
++YYCURSOR;
YYCURSOR = YYCTXMARKER;
{
- if (FFlag)
- {
- cur = ptr > tok ? ptr - 1 : cursor;
- yylval.symbol = Symbol::find(token());
- return FID;
- } else {
- cur = ptr > tok ? ptr - 1 : cursor;
- yylval.symbol = Symbol::find(token());
- return ID;
- }
+ cur = ptr > tok ? ptr - 1 : cursor;
+ yylval.symbol = Symbol::find(token());
+ return FFlag ? FID : ID;
}
yy130:
++YYCURSOR;
yy139:
{
cur = cursor;
- tok+= 5; /* skip "re2c:" */
+ tok += 5; /* skip "re2c:" */
iscfg = 1;
yylval.str = new Str(token());
return CONFIG;
if ((yych = *YYCURSOR) == '>') goto yy180;
{
cur = cursor;
- tok+= 2; /* skip ":=" */
+ tok += 2; /* skip ":=" */
depth = 0;
goto code;
}
if ((yych = *YYCURSOR) == '/') goto yy236;
yy229:
{
- if(cursor == eof)
+ if (cursor == eof)
{
RETURN(0);
}
yy231:
++YYCURSOR;
{
- if(cursor == eof)
+ if (cursor == eof)
{
RETURN(0);
}
yy236:
++YYCURSOR;
{
- if(--depth == 0)
+ if (--depth == 0)
{
goto scan;
}
return o;
}
-uint Scanner::get_line() const
-{
- return cline;
-}
-
void Scanner::config(const Str& cfg, int num)
{
if (cfg.to_string() == "indent:top")
namespace re2c
{
+struct ScannerState
+{
+ ScannerState();
+
+ char *bot, *tok, *ptr, *cur, *pos, *lim, *top, *eof, *ctx;
+ uint tchar, tline, cline, iscfg, buf_size;
+ bool in_parse;
+};
+
class Scanner:
- public line_number
+ public line_number, private ScannerState
{
private:
std::istream& in;
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);
ParseMode echo();
int scan();
+
+ size_t get_pos() const;
+ void save_state(ScannerState&) const;
+ void restore_state(const ScannerState&);
uint get_cline() const;
void set_in_parse(bool new_in_parse);
RegExp * mkDot() const;
};
+inline size_t Scanner::get_pos() const
+{
+ return cur - bot;
+}
+
+inline uint Scanner::get_line() const
+{
+ return cline;
+}
+
inline uint Scanner::get_cline() const
{
return cline;
}
+inline void Scanner::save_state(ScannerState& state) const
+{
+ state = *this;
+}
+
+inline void Scanner::restore_state(const ScannerState& state)
+{
+ if (bot != state.bot)
+ {
+ fatal("illegal internal restore operation");
+ }
+ *(ScannerState*)this = state;
+}
+
inline void Scanner::fatal(const char *msg) const
{
fatal(0, msg);
namespace re2c
{
-Scanner::Scanner(std::istream& i, std::ostream& o)
- : in(i)
- , out(o)
- , bot(NULL), tok(NULL), ptr(NULL), cur(NULL), pos(NULL), lim(NULL)
+ScannerState::ScannerState()
+ : 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)
{
- ;
+}
+
+Scanner::Scanner(std::istream& i, std::ostream& o)
+ : in(i), out(o)
+{
}
char *Scanner::fill(char *cursor, uint need)
if (cnt)
{
memmove(bot, tok, top - tok);
- tok = bot;
+ tok = bot;
ptr -= cnt;
cursor -= cnt;
pos -= cnt;
":=" {
cur = cursor;
- tok+= 2; /* skip ":=" */
+ tok += 2; /* skip ":=" */
depth = 0;
goto code;
}
config {
cur = cursor;
- tok+= 5; /* skip "re2c:" */
+ tok += 5; /* skip "re2c:" */
iscfg = 1;
yylval.str = new Str(token());
return CONFIG;
}
name / (space+ [^=>,]) {
- if (FFlag)
- {
- cur = ptr > tok ? ptr - 1 : cursor;
- yylval.symbol = Symbol::find(token());
- return FID;
- } else {
- cur = ptr > tok ? ptr - 1 : cursor;
- yylval.symbol = Symbol::find(token());
- return ID;
- }
+ cur = ptr > tok ? ptr - 1 : cursor;
+ yylval.symbol = Symbol::find(token());
+ return FFlag ? FID : ID;
}
name / (space* [=>,]) {
}
eol {
- if(cursor == eof) RETURN(0);
+ if (cursor == eof) RETURN(0);
pos = cursor;
cline++;
goto scan;
comment:
/*!re2c
"*/" {
- if(--depth == 0)
+ if (--depth == 0)
{
goto scan;
}
goto comment;
}
"\n" {
- if(cursor == eof)
+ if (cursor == eof)
{
RETURN(0);
}
goto comment;
}
any {
- if(cursor == eof)
+ if (cursor == eof)
{
RETURN(0);
}