Mon, 21 Jul 2014 17:14:42 +0300
- massive refactoring continues (doesn't compile yet)
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
133
dbbdb870c835
- changed all source files to use my correct legal name instead of my calling name
Teemu Piippo <crimsondusk64@gmail.com>
parents:
124
diff
changeset
|
2 | Copyright 2012-2014 Teemu Piippo |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | All rights reserved. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | Redistribution and use in source and binary forms, with or without |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | modification, are permitted provided that the following conditions |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | are met: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | 1. Redistributions of source code must retain the above copyright |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | notice, this list of conditions and the following disclaimer. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | 2. Redistributions in binary form must reproduce the above copyright |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | notice, this list of conditions and the following disclaimer in the |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | documentation and/or other materials provided with the distribution. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | 3. The name of the author may not be used to endorse or promote products |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | derived from this software without specific prior written permission. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | */ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | #ifndef BOTC_LEXER_SCANNER_H |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | #define BOTC_LEXER_SCANNER_H |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | #include <climits> |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | #include "main.h" |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | class LexerScanner |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | { |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
37 | public: |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
38 | struct PositionInfo |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
39 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
40 | char* pos; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
41 | int line; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
42 | }; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
44 | // Flags for check_string() |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
45 | enum |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
46 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
47 | FCheckWord = (1 << 0), // must be followed by whitespace |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
48 | FCheckPeek = (1 << 1), // don't advance cursor |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
49 | }; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
51 | static inline bool IsSymbolCharacter (char c, bool allownumbers) |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
52 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
53 | if (allownumbers and (c >= '0' and c <= '9')) |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
54 | return true; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
56 | return (c >= 'a' and c <= 'z') or |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
57 | (c >= 'A' and c <= 'Z') or |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
58 | (c == '_'); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
59 | } |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
61 | LexerScanner (FILE* fp); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
62 | ~LexerScanner(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
63 | bool getNextToken(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
64 | String readLine(); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
66 | inline const String& getTokenText() const |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
67 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
68 | return m_tokenText; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
69 | } |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
71 | inline int getLine() const |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
72 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
73 | return m_line; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
74 | } |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
76 | inline int getColumn() const |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
77 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
78 | return m_position - m_lineBreakPosition; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
79 | } |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
81 | inline Token getTokenType() const |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
82 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
83 | return m_tokenType; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
84 | } |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
86 | static String GetTokenString (Token a); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
88 | private: |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
89 | char* m_data; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
90 | char* m_position; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
91 | char* m_lineBreakPosition; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
92 | String m_tokenText, |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
93 | m_lastToken; |
135
8b9132fea327
- massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
134
diff
changeset
|
94 | Token m_tokenType; |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
95 | int m_line; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
97 | bool checkString (const char* c, int flags = 0); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
99 | // Yields a copy of the current position information. |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
100 | PositionInfo getPosition() const; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
102 | // Sets the current position based on given data. |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
103 | void setPosition (const PositionInfo& a); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
105 | // Skips one character |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
106 | void skip(); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
108 | // Skips many characters |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
109 | void skip (int chars); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | }; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | #endif // BOTC_LEXER_SCANNER_H |