Mercurial > dnsbl
annotate 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 |
rev | line source |
---|---|
143 | 1 /* |
2 | |
152 | 3 Copyright (c) 2007 Carl Byington - 510 Software Group, released under |
4 the GPL version 3 or any later version at your choice available at | |
5 http://www.gnu.org/licenses/gpl-3.0.txt | |
143 | 6 |
7 */ | |
8 | |
73 | 9 #ifndef tokenizer_include |
10 #define tokenizer_include | |
11 | |
71 | 12 #include <fstream> |
13 #include <list> | |
14 #include <set> | |
83 | 15 #include <stdio.h> |
16 #include <ctype.h> | |
71 | 17 |
18 | |
19 using namespace std; | |
20 | |
21 struct ltstr { | |
213
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
22 bool operator()(char* s1, char* s2) const { |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
23 return strcmp(s1, s2) < 0; |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
24 } |
71 | 25 }; |
26 | |
213
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
27 typedef list<ifstream *> stream_list; |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
28 typedef list<char *> string_list; |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
29 typedef set<char *, ltstr> string_set; |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
30 typedef list<int> line_list; |
71 | 31 |
32 class TOKEN { | |
213
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
33 stream_list streams; |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
34 string_list filenames; |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
35 string_set filenamess; |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
36 line_list linenumbers; |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
37 string_list pending_tokens; |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
38 string_set *include_files; |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
39 bool pushed; |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
40 u_char pushed_char; |
71 | 41 |
213
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
42 void pop(); |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
43 bool next_char(u_char &c); |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
44 void push_char(u_char c); |
71 | 45 |
46 public: | |
213
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
47 TOKEN(char *fn, string_set *includes); |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
48 ~TOKEN(); |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
49 bool include(char *fn); |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
50 char *next(); // return next token |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
51 int nextint(); |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
52 void skipeol(); // skip to eol |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
53 void push(char *token) {pending_tokens.push_front(token);}; |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
54 const char *cur_fn() {return filenames.empty() ? "" : filenames.front();}; |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
55 int cur_line() {return linenumbers.empty() ? 0 : linenumbers.front();}; |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
56 void token_error(const char *err); |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
57 void token_error(const char *fmt, int d, const char *s); |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
58 void token_error(const char *fmt, const char *t, const char *h); |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
59 void token_error(const char *want, const char *have); |
44ffef730bc4
cleanup tokenizer differences with other projects, update tld list
Carl Byington <carl@five-ten-sg.com>
parents:
152
diff
changeset
|
60 void token_error(); |
71 | 61 }; |
62 | |
73 | 63 #endif |