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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
143
ecb40aa3eaa5 require two periods for ip addresses
carl
parents: 83
diff changeset
1 /*
ecb40aa3eaa5 require two periods for ip addresses
carl
parents: 83
diff changeset
2
152
c7fc218686f5 gpl3, block mail to recipients that cannot reply
carl
parents: 143
diff changeset
3 Copyright (c) 2007 Carl Byington - 510 Software Group, released under
c7fc218686f5 gpl3, block mail to recipients that cannot reply
carl
parents: 143
diff changeset
4 the GPL version 3 or any later version at your choice available at
c7fc218686f5 gpl3, block mail to recipients that cannot reply
carl
parents: 143
diff changeset
5 http://www.gnu.org/licenses/gpl-3.0.txt
143
ecb40aa3eaa5 require two periods for ip addresses
carl
parents: 83
diff changeset
6
ecb40aa3eaa5 require two periods for ip addresses
carl
parents: 83
diff changeset
7 */
ecb40aa3eaa5 require two periods for ip addresses
carl
parents: 83
diff changeset
8
73
2b369f7db7bf start coding on new config syntax
carl
parents: 71
diff changeset
9 #ifndef tokenizer_include
2b369f7db7bf start coding on new config syntax
carl
parents: 71
diff changeset
10 #define tokenizer_include
2b369f7db7bf start coding on new config syntax
carl
parents: 71
diff changeset
11
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
12 #include <fstream>
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
13 #include <list>
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
14 #include <set>
83
99049fdc7320 start coding on new config syntax
carl
parents: 75
diff changeset
15 #include <stdio.h>
99049fdc7320 start coding on new config syntax
carl
parents: 75
diff changeset
16 #include <ctype.h>
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
17
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
18
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
19 using namespace std;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
20
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
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
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
25 };
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
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
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
31
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
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
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
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
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
45
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
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
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
61 };
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
62
73
2b369f7db7bf start coding on new config syntax
carl
parents: 71
diff changeset
63 #endif