Mercurial > dnsbl
comparison src/tokenizer.h @ 213:44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 30 Apr 2008 13:11:32 -0700 |
parents | c7fc218686f5 |
children | 82886d4dd71f |
comparison
equal
deleted
inserted
replaced
212:a47f161c76c9 | 213:44ffef730bc4 |
---|---|
17 | 17 |
18 | 18 |
19 using namespace std; | 19 using namespace std; |
20 | 20 |
21 struct ltstr { | 21 struct ltstr { |
22 bool operator()(char* s1, char* s2) const { | 22 bool operator()(char* s1, char* s2) const { |
23 return strcmp(s1, s2) < 0; | 23 return strcmp(s1, s2) < 0; |
24 } | 24 } |
25 }; | 25 }; |
26 | 26 |
27 typedef list<ifstream *> stream_list; | 27 typedef list<ifstream *> stream_list; |
28 typedef list<char *> string_list; | 28 typedef list<char *> string_list; |
29 typedef set<char *, ltstr> string_set; | 29 typedef set<char *, ltstr> string_set; |
30 typedef list<int> line_list; | 30 typedef list<int> line_list; |
31 | 31 |
32 class TOKEN { | 32 class TOKEN { |
33 stream_list streams; | 33 stream_list streams; |
34 string_list filenames; | 34 string_list filenames; |
35 string_set filenamess; | 35 string_set filenamess; |
36 line_list linenumbers; | 36 line_list linenumbers; |
37 string_list pending_tokens; | 37 string_list pending_tokens; |
38 string_set *include_files; | 38 string_set *include_files; |
39 bool pushed; | 39 bool pushed; |
40 u_char pushed_char; | 40 u_char pushed_char; |
41 | 41 |
42 void pop(); | 42 void pop(); |
43 bool next_char(u_char &c); | 43 bool next_char(u_char &c); |
44 void push_char(u_char c); | 44 void push_char(u_char c); |
45 | 45 |
46 public: | 46 public: |
47 TOKEN(char *fn, string_set *includes); | 47 TOKEN(char *fn, string_set *includes); |
48 ~TOKEN(); | 48 ~TOKEN(); |
49 bool include(char *fn); | 49 bool include(char *fn); |
50 char *next(); // return next token | 50 char *next(); // return next token |
51 int nextint(); | 51 int nextint(); |
52 void skipeol(); // skip to eol | 52 void skipeol(); // skip to eol |
53 void push(char *token) {pending_tokens.push_front(token);}; | 53 void push(char *token) {pending_tokens.push_front(token);}; |
54 char *cur_fn() {return filenames.front();}; | 54 const char *cur_fn() {return filenames.empty() ? "" : filenames.front();}; |
55 int cur_line() {return linenumbers.front();}; | 55 int cur_line() {return linenumbers.empty() ? 0 : linenumbers.front();}; |
56 void token_error(const char *err); | 56 void token_error(const char *err); |
57 void token_error(const char *fmt, int d, const char *s); | 57 void token_error(const char *fmt, int d, const char *s); |
58 void token_error(const char *fmt, const char *t, const char *h); | 58 void token_error(const char *fmt, const char *t, const char *h); |
59 void token_error(const char *want, const char *have); | 59 void token_error(const char *want, const char *have); |
60 void token_error(); | 60 void token_error(); |
61 }; | 61 }; |
62 | 62 |
63 #endif | 63 #endif |