-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvparser.js
More file actions
356 lines (351 loc) · 7.74 KB
/
invparser.js
File metadata and controls
356 lines (351 loc) · 7.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
const WARN_CONNECTOR_MISSING = 103;
/*
const WARN_LOCATION_NO_LABEL = 104;
const WARN_LOOSE_RACK = 105;
const WARN_LOOSE_FRAME = 106;
const WARN_RACK_COLLISION = 107;
const WARN_FRAME_COLLISION = 108;
const WARN_LOCATION_OVERLAP = 109;
//*/
inv_warns = {
100: "No object to attach LABEL to",
101: "Duplicate LABEL",
102: "Empty LABEL",
103: "Missing connector of type %conn_type%",
104: "Location missing label",
105: "Rack missing parent",
106: "Frame missing parent",
107: "Rack slot already occupied",
108: "Frame slot already occupied",
109: "Locations %location1% and %location2% overlap"
};
invparser = {
"FRAME": function(current)
{
this.commit("");
let name = this.getRest();
if(this.rootObject.checkName(name))
{
this.err(this.ERR_NAME_COLLISION);
return false;
}
let newframe = new VisualFrameTemplate(this.rootObject, name);
this.objectStack.unshift(newframe);
return true;
},
// needed to resolve ambiguity between CONNECTOR starting a new connector def or adding a connector to a frame
"NEXT": function(current)
{
this.commit("");
return true;
},
"COUNTER": function(current)
{
if(current.type == "frame_tpl")
{
let newval = this.getInt();
let opts = new VisualPortOptions(current,"c_"+current.getNextPrefixedSlot("c_"));
opts.counter = newval;
current.addItem(opts);
}
return true;
},
"PORTLABEL": function(current)
{
if(current.type == "frame_tpl")
{
let newval = this.getRest();
let opts = new VisualPortOptions(current,"c_"+current.getNextPrefixedSlot("c_"));
opts.tpl = newval;
current.addItem(opts);
}
return true;
},
"CONNECTOR": function(current)
{
// under a frame template this keyword adds connectors
if(current.type=="frame_tpl" || current.type == "socket_bank")
{
let name = this.getWord();
let x = this.getInt();
let y = this.getInt();
let factoryLabel = this.getRest().trim();
let conn = this.rootObject.find(name);
if(!conn)
{
// missing connector def
// put a warn or something idk lol
this.statevars['conn_type'] = name;
this.warn(WARN_CONNECTOR_MISSING);
return true;
}
let connref = new VisualConnectorPlacement(current,"c_"+current.getNextPrefixedSlot("c_"));
connref.ref=name;
connref.x=x;
connref.y=y;
connref.label=name;
connref.factoryLabel=factoryLabel;
current.addItem(connref);
//current.subItems.push({name: name, type: "connector", x: x, y: y});
return true;
}
this.commit("");
let name = this.getRest();
if(this.rootObject.checkName(name))
{
this.err(this.ERR_NAME_COLLISION);
return false;
}
let newconn = new VisualConnectorTemplate(this.rootObject, name);
this.objectStack.unshift(newconn);
return true;
},
"BANK": function(current)
{
if(current.type == "frame_tpl")
{
let name = this.getWord();
let x = this.getInt();
let y = this.getInt();
let bank = this.rootObject.find(name);
if(!bank)
{
// missing connector bank def
// put a warn or something idk lol
this.statevars['bank_type'] = name;
this.warn(WARN_CONNECTOR_MISSING);
return true;
}
let bankref = new VisualBankPlacement(current,"c_"+current.getNextPrefixedSlot("c_"));
bankref.ref=name;
bankref.x=x;
bankref.y=y;
bankref.label=name;
current.addItem(bankref);
//current.subItems.push({name: name, type: "bank", x: x, y: y});
return true;
}
this.commit("");
let name = this.getRest();
if(this.rootObject.checkName(name))
{
this.err(this.ERR_NAME_COLLISION);
return false;
}
let newbank = new VisualConnectorBank(this.rootObject, name);
this.objectStack.unshift(newbank);
return true;
},
"LABEL": function(current)
{
if(!current)
{
this.warn(WARN_LOOSE_LABEL);
return true;
}
let text = this.getRest();
if(!text)
{
this.warn(WARN_EMPTY_LABEL);
}
current.label = text;
return true;
},
"TYPE": function(current)
{
if(!current)
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
let text = this.getWord();
if(!text)
{
this.warn(WARN_EMPTY_LABEL);
}
current.subtype = text;
return true;
},
"DIM": function(current)
{
if(!current || current.type != "socket_tpl")
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
let A = this.getInt();
let B = this.getInt();
current.width = A;
current.height = B; // #TODO: keywords
return true;
},
"RENDER": function(current)
{
let parent;
if(this.checkParent("socket_tpl"))
{
parent = this.commit("socket_tpl");
}
else if(this.checkParent("frame_tpl"))
{
parent = this.commit("frame_tpl");
}
else
{
this.warn(WARN_LOOSE_RACK);
return true;
}
if(parent)
{
let newracc = new VisualRenderer(parent, "renderer");
this.objectStack.unshift(newracc);
return true;
}
console.log("fuck");
return true;
},
"LDVAR": function(current)
{
if(current.type != "renderer")
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
let A = this.getInt();
let B = this.getWord();
current.instructions.push(["LDVAR", A, B]);
return true;
},
"LDNUM": function(current)
{
if(current.type != "renderer")
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
let A = this.getInt();
let B = this.getInt();
current.instructions.push(["LDNUM", A, B]);
return true;
},
"INC": function(current)
{
if(current.type != "renderer")
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
let A = this.getInt();
current.instructions.push(["INC", A]);
return true;
},
"DEC": function(current)
{
if(current.type != "renderer")
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
let A = this.getInt();
current.instructions.push(["DEC", A]);
return true;
},
"MUL": function(current)
{
if(current.type != "renderer")
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
let A = this.getInt();
let B = this.getInt();
let C = this.getInt();
current.instructions.push(["MUL", A, B, C]);
return true;
},
"PEN": function(current)
{
if(current.type != "renderer")
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
let A = this.getInt();
let B = this.getRest();
current.instructions.push(["PEN", A, B]);
return true;
},
"FILL": function(current)
{
if(current.type != "renderer")
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
let A = this.getRest();
current.instructions.push(["FILL", A]);
return true;
},
"FONT": function(current)
{
if(current.type != "renderer")
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
let A = this.getRest();
current.instructions.push(["FONT", A]);
return true;
},
"RECT": function(current)
{
if(current.type != "renderer")
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
let A = this.getInt();
let B = this.getInt();
let C = this.getInt();
let D = this.getInt();
current.instructions.push(["RECT", A, B, C, D]);
return true;
},
"PATH": function(current)
{
if(current.type != "renderer")
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
let A = this.getRest();
current.instructions.push(["PATH", A]);
return true;
},
"TEXT": function(current)
{
if(current.type != "renderer")
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
let A = this.getInt();
let B = this.getInt();
let C = this.getRest();
current.instructions.push(["TEXT", A, B, C]);
return true;
},
"DVAR": function(current)
{
if(current.type != "renderer")
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
let A = this.getInt();
let B = this.getInt();
let C = this.getInt();
current.instructions.push(["DVAR", A, B, C]);
return true;
}
};