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:
125
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 | #include <cstring> |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | #include "lexer.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 | static StringList gFileNameStack; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | static Lexer* gMainLexer = null; |
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 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | Lexer::Lexer() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | { |
125
85814c0918c5
- now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
39 | ASSERT_EQ (gMainLexer, null); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | gMainLexer = this; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | Lexer::~Lexer() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | gMainLexer = null; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | void Lexer::processFile (String fileName) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | gFileNameStack << fileName; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | FILE* fp = fopen (fileName, "r"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | if (fp == null) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | error ("couldn't open %1 for reading: %2", fileName, strerror (errno)); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | LexerScanner sc (fp); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | checkFileHeader (sc); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | while (sc.getNextToken()) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | // Preprocessor commands: |
135
8b9132fea327
- massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
134
diff
changeset
|
66 | if (sc.getTokenType() == Token::Hash) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
68 | mustGetFromScanner (sc,Token::Symbol); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | if (sc.getTokenText() == "include") |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
72 | mustGetFromScanner (sc,Token::String); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | String fileName = sc.getTokenText(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | if (gFileNameStack.contains (fileName)) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | error ("attempted to #include %1 recursively", sc.getTokenText()); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | processFile (fileName); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | else |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | error ("unknown preprocessor directive \"#%1\"", sc.getTokenText()); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | else |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | TokenInfo tok; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | tok.file = fileName; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | tok.line = sc.getLine(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | tok.column = sc.getColumn(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | tok.type = sc.getTokenType(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | tok.text = sc.getTokenText(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | // devf ("Token #%1: %2:%3:%4: %5 (%6)\n", mTokens.size(), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | // tok.file, tok.line, tok.column, DescribeToken (&tok), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | // GetTokenTypeString (tok.type)); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | m_tokens << tok; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | m_tokenPosition = m_tokens.begin() - 1; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | gFileNameStack.removeOne (fileName); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | static bool isValidHeader (String header) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | if (header.endsWith ("\n")) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | header.removeFromEnd (1); |
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 | StringList tokens = header.split (" "); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
113 | if (tokens.size() != 2 or tokens[0] != "#!botc" or tokens[1].isEmpty()) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | return false; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | StringList nums = tokens[1].split ("."); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | if (nums.size() == 2) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | nums << "0"; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | elif (nums.size() != 3) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | return false; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | bool okA, okB, okC; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | long major = nums[0].toLong (&okA); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | long minor = nums[1].toLong (&okB); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | long patch = nums[2].toLong (&okC); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
128 | if (!okA or !okB or !okC) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | return false; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | if (VERSION_NUMBER < MAKE_VERSION_NUMBER (major, minor, patch)) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | error ("The script file requires " APPNAME " v%1, this is v%2", |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | makeVersionString (major, minor, patch), versionString (false)); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | return true; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | // ============================================================================ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | void Lexer::checkFileHeader (LexerScanner& sc) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | if (!isValidHeader (sc.readLine())) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | error ("Not a valid botscript file! File must start with '#!botc <version>'"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | // |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
148 | bool Lexer::next (Token req) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | Iterator pos = m_tokenPosition; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | if (m_tokens.isEmpty()) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | return false; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
155 | m_tokenPosition++; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
156 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
157 | if (isAtEnd() or (req !=Token::Any and tokenType() != req)) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
158 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | m_tokenPosition = pos; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | return false; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
162 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
163 | return true; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
165 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
166 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
167 | // |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
168 | void Lexer::mustGetNext (Token tok) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
169 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
170 | if (!next()) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
171 | error ("unexpected EOF"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
172 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
173 | if (tok !=Token::Any) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
174 | tokenMustBe (tok); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
175 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
176 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
177 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
178 | // eugh.. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
179 | // |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
180 | void Lexer::mustGetFromScanner (LexerScanner& sc, Token tt) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
181 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
182 | if (sc.getNextToken() == false) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
183 | error ("unexpected EOF"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
184 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
185 | if (tt != Token::Any and sc.getTokenType() != tt) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
186 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
187 | // TODO |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
188 | TokenInfo tok; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
189 | tok.type = sc.getTokenType(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
190 | tok.text = sc.getTokenText(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
191 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
192 | error ("at %1:%2: expected %3, got %4", |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
193 | gFileNameStack.last(), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | sc.getLine(), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
195 | describeTokenType (tt), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
196 | describeToken (&tok)); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
197 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
198 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
199 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
200 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
201 | // |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
202 | void Lexer::mustGetAnyOf (const List<Token>& toks) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
203 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
204 | if (!next()) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
205 | error ("unexpected EOF"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
206 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
207 | for (Token tok : toks) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
208 | if (tokenType() == tok) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
209 | return; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
210 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
211 | String toknames; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
212 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
213 | for (const Token& tokType : toks) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
214 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
215 | if (&tokType == &toks.last()) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
216 | toknames += " or "; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
217 | elif (toknames.isEmpty() == false) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
218 | toknames += ", "; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
219 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
220 | toknames += describeTokenType (tokType); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
221 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
222 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
223 | error ("expected %1, got %2", toknames, describeToken (token())); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
224 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
225 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
226 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
227 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
228 | int Lexer::getOneSymbol (const StringList& syms) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
229 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
230 | if (!next()) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
231 | error ("unexpected EOF"); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
232 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
233 | if (tokenType() ==Token::Symbol) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
234 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
235 | for (int i = 0; i < syms.size(); ++i) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
236 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
237 | if (syms[i] == token()->text) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
238 | return i; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
239 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
240 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
241 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
242 | error ("expected one of %1, got %2", syms, describeToken (token())); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
243 | return -1; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
244 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
245 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
246 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
247 | // |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
248 | void Lexer::tokenMustBe (Token tok) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
249 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
250 | if (tokenType() != tok) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
251 | error ("expected %1, got %2", describeTokenType (tok), |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
252 | describeToken (token())); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
253 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
254 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
255 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
256 | // |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
257 | String Lexer::describeTokenPrivate (Token tokType, Lexer::TokenInfo* tok) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
258 | { |
135
8b9132fea327
- massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
134
diff
changeset
|
259 | if (tokType < Token::LastNamedToken) |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
260 | return "\"" + LexerScanner::GetTokenString (tokType) + "\""; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
261 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
262 | switch (tokType) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
263 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
264 | case Token::Symbol: return tok ? tok->text : "a symbol"; |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
265 | case Token::Number: return tok ? tok->text : "a number"; |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
266 | case Token::String: return tok ? ("\"" + tok->text + "\"") : "a string"; |
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
267 | case Token::Any: return tok ? tok->text : "any token"; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
268 | default: break; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
269 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
270 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
271 | return ""; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
272 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
273 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
274 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
275 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
276 | bool Lexer::peekNext (Lexer::TokenInfo* tk) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
277 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
278 | Iterator pos = m_tokenPosition; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
279 | bool r = next(); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
280 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
281 | if (r and tk != null) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
282 | *tk = *m_tokenPosition; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
283 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
284 | m_tokenPosition = pos; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
285 | return r; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
286 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
287 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
288 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
289 | // |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
290 | bool Lexer::peekNextType (Token req) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
291 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
292 | Iterator pos = m_tokenPosition; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
293 | bool result = false; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
294 | |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
295 | if (next() and tokenType() == req) |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
296 | result = true; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
297 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
298 | m_tokenPosition = pos; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
299 | return result; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
300 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
301 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
302 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
303 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
304 | Lexer* Lexer::getCurrentLexer() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
305 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
306 | return gMainLexer; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
307 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
308 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
309 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
310 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
311 | String Lexer::peekNextString (int a) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
312 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
313 | if (m_tokenPosition + a >= m_tokens.end()) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
314 | return ""; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
315 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
316 | Iterator oldpos = m_tokenPosition; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
317 | m_tokenPosition += a; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
318 | String result = token()->text; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
319 | m_tokenPosition = oldpos; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
320 | return result; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
321 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
322 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
323 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
324 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
325 | String Lexer::describeCurrentPosition() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
326 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
327 | return token()->file + ":" + token()->line; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
328 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
329 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
330 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
331 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
332 | String Lexer::describeTokenPosition() |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
333 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
334 | return format ("%1 / %2", m_tokenPosition - m_tokens.begin(), m_tokens.size()); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
335 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
336 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
337 | // ============================================================================= |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
338 | // |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
339 | void Lexer::mustGetSymbol (const String& a) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
340 | { |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
341 | mustGetNext (Token::Any); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
342 | if (token()->text != a) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
343 | error ("expected \"%1\", got \"%2\"", a, token()->text); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
344 | } |