src
scanner.h
Go to the documentation of this file.
1 #ifndef _RE2C_PARSE_SCANNER_
2 #define _RE2C_PARSE_SCANNER_
3 
4 #include "src/util/c99_stdint.h"
5 #include <stddef.h>
6 #include <string>
7 
8 #include "src/parse/input.h"
9 #include "src/util/attribute.h"
10 #include "src/util/forbid_copy.h"
11 
12 namespace re2c
13 {
14 
15 class Range;
16 class RegExp;
17 struct OutputFile;
18 
20 {
22  {
25  };
26 
27  // positioning
28  char * tok;
29  char * ptr;
30  char * cur;
31  char * pos;
32  char * ctx;
33 
34  // buffer
35  char * bot;
36  char * lim;
37  char * top;
38  char * eof;
39 
40  ptrdiff_t tchar;
41  uint32_t tline;
42  uint32_t cline;
43 
44  bool in_parse;
46 
47  ScannerState ();
48  ScannerState (const ScannerState &);
50 };
51 
52 class Scanner: private ScannerState
53 {
54  static const uint32_t BSIZE;
55 
56  Input & in;
57 public:
59 
60 private:
61  void fill (uint32_t);
62  void set_sourceline ();
63  uint32_t lex_cls_chr();
64  uint32_t lex_str_chr(char quote, bool &end);
65  RegExp *lex_cls(bool neg);
66  RegExp *lex_str(char quote, bool casing);
67  RegExp *schr(uint32_t c) const;
68  RegExp *ichr(uint32_t c) const;
69  RegExp *cls(Range *r) const;
70 
71  void lex_conf ();
72  void lex_conf_assign ();
73  void lex_conf_semicolon ();
74  int32_t lex_conf_number ();
75  std::string lex_conf_string ();
76 
77  size_t tok_len () const;
78 
79 public:
80  Scanner(Input &, OutputFile &);
81  ~Scanner();
82 
83  enum ParseMode {
88  };
89 
90  ParseMode echo();
91  int scan();
92  void reuse();
93 
94  void save_state(ScannerState&) const;
95  void restore_state(const ScannerState&);
96 
97  uint32_t get_cline() const;
98  uint32_t get_line() const;
99  const std::string & get_fname () const;
100  void set_in_parse(bool new_in_parse);
101  void fatal_at(uint32_t line, ptrdiff_t ofs, const char *msg) const;
102  void fatalf_at(uint32_t line, const char*, ...) const RE2C_GXX_ATTRIBUTE ((format (printf, 3, 4)));
103  void fatalf(const char*, ...) const RE2C_GXX_ATTRIBUTE ((format (printf, 2, 3)));
104  void fatal(const char*) const;
105  void fatal(ptrdiff_t, const char*) const;
106 
107  RegExp * mkDiff (RegExp * e1, RegExp * e2) const;
108  RegExp * mkDot () const;
109  RegExp * mkDefault () const;
110 
112 };
113 
114 inline size_t Scanner::tok_len () const
115 {
116  // lexing and fill procedures must maintain: token pointer <= cursor pointer
117  return static_cast<size_t> (cur - tok);
118 }
119 
120 inline const std::string & Scanner::get_fname () const
121 {
122  return in.file_name;
123 }
124 
125 inline uint32_t Scanner::get_cline() const
126 {
127  return cline;
128 }
129 
130 inline uint32_t Scanner::get_line() const
131 {
132  return in_parse ? tline : cline;
133 }
134 
135 inline void Scanner::save_state(ScannerState& state) const
136 {
137  state = *this;
138 }
139 
140 inline void Scanner::fatal(const char *msg) const
141 {
142  fatal(0, msg);
143 }
144 
145 } // end namespace re2c
146 
147 #endif // _RE2C_PARSE_SCANNER_
void restore_state(const ScannerState &)
Definition: scanner.cc:189
uint32_t get_cline() const
Definition: scanner.h:125
RegExp * mkDot() const
Definition: regexp.cc:173
uint32_t get_line() const
Definition: scanner.h:130
RegExp * mkDefault() const
Definition: regexp.cc:195
void fatalf_at(uint32_t line, const char *,...) const RE2C_GXX_ATTRIBUTE((format(printf
Definition: scanner.cc:145
std::string file_name
Definition: input.h:14
void reuse()
Definition: scanner.cc:180
void void fatalf(const char *,...) const RE2C_GXX_ATTRIBUTE((format(printf
Definition: scanner.cc:160
void void void fatal(const char *) const
Definition: scanner.h:140
ParseMode echo()
void save_state(ScannerState &) const
Definition: scanner.h:135
#define RE2C_GXX_ATTRIBUTE(x)
Definition: attribute.h:7
void set_in_parse(bool new_in_parse)
Definition: scanner.cc:127
Scanner(Input &, OutputFile &)
Definition: scanner.cc:65
uint32_t cline
Definition: scanner.h:42
FORBID_COPY(Scanner)
uint32_t tline
Definition: scanner.h:41
lexer_state_t lexer_state
Definition: scanner.h:45
ScannerState & operator=(const ScannerState &)
Definition: scanner.cc:58
const std::string & get_fname() const
Definition: scanner.h:120
RegExp * mkDiff(RegExp *e1, RegExp *e2) const
Definition: regexp.cc:160
void fatal_at(uint32_t line, ptrdiff_t ofs, const char *msg) const
Definition: scanner.cc:132
ptrdiff_t tchar
Definition: scanner.h:40
Definition: bitmap.cc:10
OutputFile & out
Definition: scanner.h:58