events renaming
[gaemu.git] / gmlparser / gentokens.d
blobef1362227f8d083875435ce83b51d4bf8627ccad
1 /* GML parser
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;
20 string[] tokens = [
21 "false",
22 "true",
24 "all",
25 "noone",
26 "self",
27 "other",
28 "global",
30 "not",
31 "and",
32 "or",
33 "xor",
35 "break",
36 "continue",
38 "switch",
39 "case",
40 "default",
42 "div",
43 "mod",
45 "do",
46 "until",
47 "repeat",
48 "while",
50 "if",
51 "else",
53 "for",
55 "return",
56 "exit",
58 "var",
59 "globalvar",
61 "with",
63 "pi",
65 "function",
66 //"with_object",
70 struct SpTk {
71 string text;
72 string name;
75 SpTk[] sptk = [
76 SpTk("+", "Add"),
77 SpTk("-", "Sub"),
78 SpTk("*", "Mul"),
79 SpTk("/", "RDiv"),
80 SpTk("&", "BitAnd"),
81 SpTk("|", "BitOr"),
82 SpTk("^", "BitXor"),
83 SpTk("~", "BitNeg"),
84 SpTk("&&", "LogAnd"),
85 SpTk("||", "LogOr"),
86 SpTk("^^", "LogXor"),
87 SpTk("!", "LogNot"),
88 SpTk("<", "Less"),
89 SpTk(">", "Great"),
90 SpTk("<=", "LessEqu"),
91 SpTk(">=", "GreatEqu"),
92 SpTk("==", "Equ"),
93 SpTk("!=", "NotEqu"),
94 SpTk("=", "Ass"),
95 SpTk("+=", "AssAdd"),
96 SpTk("-=", "AssSub"),
97 SpTk("*=", "AssMul"),
98 SpTk("/=", "AssDiv"),
99 SpTk("&=", "AssBitAnd"),
100 SpTk("|=", "AssBitOr"),
101 SpTk("^=", "AssBitXor"),
102 SpTk("<<=", "AssLShift"),
103 SpTk(">>=", "AssRShift"),
104 SpTk(";", "Semi"),
105 SpTk(":", "Colon"),
106 SpTk(",", "Comma"),
107 SpTk(".", "Dot"),
108 SpTk("{", "LCurly"),
109 SpTk("}", "RCurly"),
110 SpTk("(", "LParen"),
111 SpTk(")", "RParen"),
112 SpTk("[", "LBracket"),
113 SpTk("]", "RBracket"),
114 SpTk("<<", "LShift"),
115 SpTk(">>", "RShift"),
116 SpTk("++", "PlusPlus"),
117 SpTk("--", "MinusMinus"),
121 void main () {
122 import std.algorithm;
123 import std.array;
124 import std.stdio;
125 tokens = tokens.sort!((a, b) => a < b).array;
128 bool[string] tk;
129 foreach (string s; tokens) {
130 if (s in tk) assert(0, "duplicate token: "~s);
131 tk[s] = true;
133 foreach (ref st; sptk) {
134 if (st.text in tk) assert(0, "duplicate token: "~st.text);
135 tk[st.text] = true;
139 bool[string] tnm;
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/>.
158 */`);
159 fo.writeln("module gmlparser.tokens;");
161 // fo.write enum
162 fo.writeln();
163 fo.writeln();
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);
170 tnm[tename] = true;
171 fo.writeln(" ", tename, ",");
173 foreach (ref ti; sptk) {
174 if (ti.name in tnm) assert(0, "duplicate token name: "~ti.name);
175 tnm[ti.name] = true;
176 fo.writeln(" ", ti.name, ",");
178 fo.writeln("}");
180 fo.writeln();
181 fo.writeln();
182 fo.writeln("__gshared immutable Keyword[string] keywords;");
183 fo.writeln("__gshared immutable string[int] keywordstx;");
185 fo.writeln();
186 fo.writeln();
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, ",");
194 fo.writeln(" ];");
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, "\",");
201 fo.writeln(" ];");
202 fo.writeln("}");
204 fo.writeln();
205 fo.writeln();
206 fo.writeln("static string keywordtext (uint id) {");
207 fo.writeln(" if (auto kw = id in keywordstx) return *kw;");
208 fo.writeln(" return \"<unknown>\";");
209 fo.writeln("}");