cp/guest: clean up guest_create's console handling
[hvf.git] / build / re2c / scanner.h
blob27ce44de7d7f2e81d481d1c4376a31506f9be287
1 /* $Id: scanner.h 860 2008-04-09 22:57:45Z nuno-lopes $ */
2 #ifndef _scanner_h
3 #define _scanner_h
5 #include <iosfwd>
6 #include <string>
7 #include "token.h"
8 #include "re.h"
9 #include "globals.h"
11 namespace re2c
14 struct ScannerState
16 ScannerState();
18 char *tok, *ptr, *cur, *pos, *ctx; // positioning
19 char *bot, *lim, *top, *eof; // buffer
20 uint tchar, tline, cline, iscfg, buf_size;
21 bool in_parse;
24 class Scanner:
25 public line_number, private ScannerState
27 private:
28 std::istream& in;
29 std::ostream& out;
31 private:
32 char *fill(char*, uint);
33 Scanner(const Scanner&); //unimplemented
34 Scanner& operator=(const Scanner&); //unimplemented
35 void set_sourceline(char *& cursor);
37 public:
38 Scanner(std::istream&, std::ostream&);
39 ~Scanner();
41 enum ParseMode {
42 Stop,
43 Parse,
44 Reuse,
45 Rules
48 ParseMode echo();
49 int scan();
50 void reuse();
52 size_t get_pos() const;
53 void save_state(ScannerState&) const;
54 void restore_state(const ScannerState&);
56 uint get_cline() const;
57 void set_in_parse(bool new_in_parse);
58 void fatal_at(uint line, uint ofs, const char *msg) const;
59 void fatalf_at(uint line, const char*, ...) const;
60 void fatalf(const char*, ...) const;
61 void fatal(const char*) const;
62 void fatal(uint, const char*) const;
64 void config(const Str&, int);
65 void config(const Str&, const Str&);
67 void check_token_length(char *pos, uint len) const;
68 SubStr token() const;
69 SubStr token(uint start, uint len) const;
70 Str raw_token(std::string enclosure) const;
71 virtual uint get_line() const;
72 uint xlat(uint c) const;
74 uint unescape(SubStr &s) const;
75 std::string& unescape(SubStr& str_in, std::string& str_out) const;
77 Range * getRange(SubStr &s) const;
78 RegExp * matchChar(uint c) const;
79 RegExp * strToName(SubStr s) const;
80 RegExp * strToRE(SubStr s) const;
81 RegExp * strToCaseInsensitiveRE(SubStr s) const;
82 RegExp * ranToRE(SubStr s) const;
83 RegExp * getAnyRE() const;
84 RegExp * invToRE(SubStr s) const;
85 RegExp * mkDot() const;
88 inline size_t Scanner::get_pos() const
90 return cur - bot;
93 inline uint Scanner::get_line() const
95 return cline;
98 inline uint Scanner::get_cline() const
100 return cline;
103 inline void Scanner::save_state(ScannerState& state) const
105 state = *this;
108 inline void Scanner::fatal(const char *msg) const
110 fatal(0, msg);
113 inline SubStr Scanner::token() const
115 check_token_length(tok, cur - tok);
116 return SubStr(tok, cur - tok);
119 inline SubStr Scanner::token(uint start, uint len) const
121 check_token_length(tok + start, len);
122 return SubStr(tok + start, len);
125 inline uint Scanner::xlat(uint c) const
127 return re2c::wFlag ? c : re2c::xlat[c & 0xFF];
130 } // end namespace re2c
132 #endif