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, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 module gmlparser
.gentokens
is aliced
;
90 SpTk("<=", "LessEqu"),
91 SpTk(">=", "GreatEqu"),
99 SpTk("&=", "AssBitAnd"),
100 SpTk("|=", "AssBitOr"),
101 SpTk("^=", "AssBitXor"),
102 SpTk("<<=", "AssLShift"),
103 SpTk(">>=", "AssRShift"),
112 SpTk("[", "LBracket"),
113 SpTk("]", "RBracket"),
114 SpTk("<<", "LShift"),
115 SpTk(">>", "RShift"),
116 SpTk("++", "PlusPlus"),
117 SpTk("--", "MinusMinus"),
122 import std
.algorithm
;
125 tokens
= tokens
.sort
!((a
, b
) => a
< b
).array
;
129 foreach (string s
; tokens
) {
130 if (s
in tk
) assert(0, "duplicate token: "~s
);
133 foreach (ref st
; sptk
) {
134 if (st
.text
in tk
) assert(0, "duplicate token: "~st
.text
);
141 auto fo
= File("tokens.d", "w");
142 fo
.writeln(`/* GML parser
143 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
144 * Understanding is not required. Only obedience.
146 * This program is free software: you can redistribute it and/or modify
147 * it under the terms of the GNU General Public License as published by
148 * the Free Software Foundation, either version 3 of the License, or
149 * (at your option) any later version.
151 * This program is distributed in the hope that it will be useful,
152 * but WITHOUT ANY WARRANTY; without even the implied warranty of
153 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
154 * GNU General Public License for more details.
156 * You should have received a copy of the GNU General Public License
157 * along with this program. If not, see <http://www.gnu.org/licenses/>.
159 fo
.writeln("module gmlparser.tokens;");
164 fo
.writeln("enum Keyword {");
165 fo
.writeln(" NoKW,");
166 foreach (string n
; tokens
) {
167 import std
.uni
: toLower
, toUpper
;
168 string tename
= n
[0..1].toUpper
~n
[1..$].toLower
;
169 if (tename
in tnm
) assert(0, "duplicate token name: "~tename
);
171 fo
.writeln(" ", tename
, ",");
173 foreach (ref ti
; sptk
) {
174 if (ti
.name
in tnm
) assert(0, "duplicate token name: "~ti
.name
);
176 fo
.writeln(" ", ti
.name
, ",");
182 fo
.writeln("__gshared immutable Keyword[string] keywords;");
183 fo
.writeln("__gshared immutable string[int] keywordstx;");
187 fo
.writeln("shared static this () {");
188 fo
.writeln(" keywords = [");
189 foreach (string n
; tokens
) {
190 import std
.uni
: toLower
, toUpper
;
191 fo
.writeln(" \"", n
, "\": Keyword.", n
[0..1].toUpper
, n
[1..$].toLower
, ",");
193 foreach (ref ti
; sptk
) fo
.writeln(" \"", ti
.text
, "\": Keyword.", ti
.name
, ",");
195 fo
.writeln(" keywordstx = [");
196 foreach (string n
; tokens
) {
197 import std
.uni
: toLower
, toUpper
;
198 fo
.writeln(" Keyword.", n
[0..1].toUpper
, n
[1..$].toLower
, ": \"", n
, "\",");
200 foreach (ref ti
; sptk
) fo
.writeln(" Keyword.", ti
.name
, ": \"", ti
.text
, "\",");
206 fo
.writeln("static string keywordtext (uint id) {");
207 fo
.writeln(" if (auto kw = id in keywordstx) return *kw;");
208 fo
.writeln(" return \"<unknown>\";");