2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module gaem
.parser
.gentokens
is aliced
;
89 SpTk("<=", "LessEqu"),
90 SpTk(">=", "GreatEqu"),
98 SpTk("&=", "AssBitAnd"),
99 SpTk("|=", "AssBitOr"),
100 SpTk("^=", "AssBitXor"),
101 SpTk("<<=", "AssLShift"),
102 SpTk(">>=", "AssRShift"),
111 SpTk("[", "LBracket"),
112 SpTk("]", "RBracket"),
113 SpTk("<<", "LShift"),
114 SpTk(">>", "RShift"),
115 SpTk("++", "PlusPlus"),
116 SpTk("--", "MinusMinus"),
121 import std
.algorithm
;
124 tokens
= tokens
.sort
!((a
, b
) => a
< b
).array
;
128 foreach (string s
; tokens
) {
129 if (s
in tk
) assert(0, "duplicate token: "~s
);
132 foreach (ref st
; sptk
) {
133 if (st
.text
in tk
) assert(0, "duplicate token: "~st
.text
);
140 auto fo
= File("tokens.d", "w");
141 fo
.writeln(`/* GML parser
142 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
143 * Understanding is not required. Only obedience.
145 * This program is free software: you can redistribute it and/or modify
146 * it under the terms of the GNU General Public License as published by
147 * the Free Software Foundation, version 3 of the License ONLY.
149 * This program is distributed in the hope that it will be useful,
150 * but WITHOUT ANY WARRANTY; without even the implied warranty of
151 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
152 * GNU General Public License for more details.
154 * You should have received a copy of the GNU General Public License
155 * along with this program. If not, see <http://www.gnu.org/licenses/>.
157 fo
.writeln("module gaem.parser.tokens;");
162 fo
.writeln("enum Keyword {");
163 fo
.writeln(" NoKW,");
164 foreach (string n
; tokens
) {
165 import std
.uni
: toLower
, toUpper
;
166 string tename
= n
[0..1].toUpper
~n
[1..$].toLower
;
167 if (tename
in tnm
) assert(0, "duplicate token name: "~tename
);
169 fo
.writeln(" ", tename
, ",");
171 foreach (ref ti
; sptk
) {
172 if (ti
.name
in tnm
) assert(0, "duplicate token name: "~ti
.name
);
174 fo
.writeln(" ", ti
.name
, ",");
180 fo
.writeln("__gshared immutable Keyword[string] keywords;");
181 fo
.writeln("__gshared immutable string[int] keywordstx;");
185 fo
.writeln("shared static this () {");
186 fo
.writeln(" keywords = [");
187 foreach (string n
; tokens
) {
188 import std
.uni
: toLower
, toUpper
;
189 fo
.writeln(" \"", n
, "\": Keyword.", n
[0..1].toUpper
, n
[1..$].toLower
, ",");
191 foreach (ref ti
; sptk
) fo
.writeln(" \"", ti
.text
, "\": Keyword.", ti
.name
, ",");
193 fo
.writeln(" keywordstx = [");
194 foreach (string n
; tokens
) {
195 import std
.uni
: toLower
, toUpper
;
196 fo
.writeln(" Keyword.", n
[0..1].toUpper
, n
[1..$].toLower
, ": \"", n
, "\",");
198 foreach (ref ti
; sptk
) fo
.writeln(" Keyword.", ti
.name
, ": \"", ti
.text
, "\",");
204 fo
.writeln("static string keywordtext (uint id) {");
205 fo
.writeln(" if (auto kw = id in keywordstx) return *kw;");
206 fo
.writeln(" return \"<unknown>\";");