Sun, 19 Jan 2014 20:39:30 +0200
- use the Skulltag 97c2 license which is slightly differently worded
73
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
85
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
2 | Copyright 2012-2014 Santeri Piippo |
73
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | All rights reserved. |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | Redistribution and use in source and binary forms, with or without |
85
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
6 | modification, are permitted provided that the following conditions |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
7 | are met: |
73
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | |
85
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
9 | 1. Redistributions of source code must retain the above copyright |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
10 | notice, this list of conditions and the following disclaimer. |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
11 | 2. Redistributions in binary form must reproduce the above copyright |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
12 | notice, this list of conditions and the following disclaimer in the |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
13 | documentation and/or other materials provided with the distribution. |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
14 | 3. The name of the author may not be used to endorse or promote products |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
15 | derived from this software without specific prior written permission. |
73
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | |
85
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
264a61e9eba0
- use the Skulltag 97c2 license which is slightly differently worded
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
73
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | */ |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | |
80
2ed3430fdd08
- forgot to rename these header guards when i ported the lexer from an earlier project of mine
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
29 | #ifndef BOTC_LEXER_SCANNER_H |
2ed3430fdd08
- forgot to rename these header guards when i ported the lexer from an earlier project of mine
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
30 | #define BOTC_LEXER_SCANNER_H |
73
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | #include <climits> |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | #include "main.h" |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | class lexer_scanner |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | { |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | types: |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | struct position_info |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | { |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | char* pos; |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | char* line_break_pos; |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | int line; |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | }; |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | // Flags for check_string() |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | enum |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | { |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | f_check_word = (1 << 0), // must be followed by whitespace |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | f_check_peek = (1 << 1), // don't advance cursor |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | }; |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | public: |
79
2425fa6a4f21
- parser now processes commands.def properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
75
diff
changeset
|
53 | static inline bool is_symbol_char (char c, bool allow_numbers) |
73
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | { |
79
2425fa6a4f21
- parser now processes commands.def properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
75
diff
changeset
|
55 | if (allow_numbers && (c >= '0' && c <= '9')) |
2425fa6a4f21
- parser now processes commands.def properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
75
diff
changeset
|
56 | return true; |
2425fa6a4f21
- parser now processes commands.def properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
75
diff
changeset
|
57 | |
73
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | return (c >= 'a' && c <= 'z') || |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | (c >= 'A' && c <= 'Z') || |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | (c == '_'); |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | } |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | lexer_scanner (FILE* fp); |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | ~lexer_scanner(); |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | bool get_next_token(); |
82
841562f5a32f
- added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
80
diff
changeset
|
66 | string read_line(); |
73
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | inline const string& get_token_text() const |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | { |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | return m_token_text; |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | } |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | inline int get_line() const |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | { |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | return m_line; |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | } |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | inline int get_column() const |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | { |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | return m_ptr - m_line_break_pos; |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | } |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | |
74 | 83 | inline e_token get_token_type() const |
73
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | { |
74 | 85 | return m_token_type; |
73
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | } |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | static string get_token_string (e_token a); |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | private: |
80
2ed3430fdd08
- forgot to rename these header guards when i ported the lexer from an earlier project of mine
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
91 | char* m_data; |
2ed3430fdd08
- forgot to rename these header guards when i ported the lexer from an earlier project of mine
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
92 | char* m_ptr; |
2ed3430fdd08
- forgot to rename these header guards when i ported the lexer from an earlier project of mine
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
93 | char* m_line_break_pos; |
73
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | string m_token_text, |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | m_last_token; |
74 | 96 | e_token m_token_type; |
73
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | int m_line; |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | bool check_string (const char* c, int flags = 0); |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | // Yields a copy of the current position information. |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | position_info get_position() const; |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | // Sets the current position based on given data. |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | void set_position (const position_info& a); |
79
2425fa6a4f21
- parser now processes commands.def properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
75
diff
changeset
|
106 | |
2425fa6a4f21
- parser now processes commands.def properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
75
diff
changeset
|
107 | // Skips one character |
2425fa6a4f21
- parser now processes commands.def properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
75
diff
changeset
|
108 | void skip(); |
2425fa6a4f21
- parser now processes commands.def properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
75
diff
changeset
|
109 | |
2425fa6a4f21
- parser now processes commands.def properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
75
diff
changeset
|
110 | // Skips many characters |
2425fa6a4f21
- parser now processes commands.def properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
75
diff
changeset
|
111 | void skip (int chars); |
73
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | }; |
1ee9b312dc18
- *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | |
80
2ed3430fdd08
- forgot to rename these header guards when i ported the lexer from an earlier project of mine
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
114 | #endif // BOTC_LEXER_SCANNER_H |