-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhwparser.js
More file actions
242 lines (239 loc) · 4.93 KB
/
Copy pathhwparser.js
File metadata and controls
242 lines (239 loc) · 4.93 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
const WARN_LOOSE_LABEL = 100;
const WARN_DUPLICATE_LABEL = 101;
const WARN_EMPTY_LABEL = 102;
const WARN_LOCATION_NO_NAME = 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;
const WARN_BAD_FRAME_TPL = 110;
const WARN_INVALID_CABLE = 111;
hw_warns = {
100: "No object to attach LABEL to",
101: "Duplicate LABEL",
102: "Empty LABEL",
103: "Location missing name",
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",
110: "Unknown frame template %frame_tpl_name%",
111: "Cable %cable_name% invalid: %frame_ref% doesn't exist"
};
hwparser = {
"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;
},
"SLOT": function(current)
{
if(!current)
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
let slot = this.getInt();
if(!slot)
{
this.statevars['last_param'] = 1;
this.warn(this.WARN_MISSING_PARAM);
current.slot = -1;
}
else
{
current.slot = slot-1;
}
return true;
},
"TYPE": function(current)
{
if(!current)
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
let ftype = this.getWord();
if(!ftype)
{
this.statevars['last_param'] = 1;
this.warn(this.WARN_MISSING_PARAM);
}
if(current.type!="frame")
{
this.WARN_UNEXPECTED_TOKEN;
return true;
}
current.frametype = ftype;
return true;
},
"SOCKETLABEL": function(current)
{
if(!current)
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
let socketname = this.getWord();
if(!socketname)
{
this.statevars['last_param'] = 1;
this.warn(this.WARN_MISSING_PARAM);
return true;
}
let socketlabel = this.getRest();
if(!socketlabel)
{
this.statevars['last_param'] = 2;
this.warn(this.WARN_MISSING_PARAM);
}
if(current.type!="frame")
{
this.WARN_UNEXPECTED_TOKEN;
return true;
}
current.socketlabels[socketname]=socketlabel;
return true;
},
"POSITION": function(current)
{
if(!current)
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
if(current.type!="location")
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
const posx = this.getInt(true);
const posy = this.getInt(true);
current.x = posx;
current.y = posy;
return true;
},
"COMPACT": function(current)
{
if(!current)
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
if(current.type!="location")
{
this.warn(this.WARN_UNEXPECTED_TOKEN);
return true;
}
current.collapseState = true;
return true;
},
"LOCATION": function(current)
{
//console.log(this.objectStack);
this.commit("");
let name = this.getRest();
if(this.rootObject.checkName(name))
{
this.err(this.ERR_NAME_COLLISION);
return false;
}
let newloc = new VisualLocation(this.rootObject, name);
this.objectStack.unshift(newloc);
return true;
},
"RACK": function(current)
{
//console.log(this.objectStack);
if(!this.checkParent("location"))
{
this.warn(WARN_LOOSE_RACK);
return true;
}
let parent = this.commit("location");
let name = this.getRest();
if(parent)
{
if(parent.checkName(name))
{
this.err(this.ERR_NAME_COLLISION);
return false;
}
let newracc = new VisualRack(parent, name);
this.objectStack.unshift(newracc);
}
return true;
},
"FRAME": function(current)
{
//console.log(this.objectStack);
if(!this.checkParent("rack"))
{
this.warn(WARN_LOOSE_FRAME);
return true;
}
let parent = this.commit("rack");
let name = this.getRest();
if(parent)
{
if(parent.checkName(name))
{
this.error(this.ERR_NAME_COLLISION);
return false;
}
let newframe = new VisualFrame(parent, name);
this.objectStack.unshift(newframe);
}
return true;
},
"CABLE": function(current)
{
this.commit("");
let cablename = this.getWord();
let L1 = this.getWord();
let R1 = this.getWord();
let F1 = this.getWord();
let L2 = this.getWord();
let R2 = this.getWord();
let F2 = this.getWord();
if(false && this.terrain.checkName(name))
{
this.err(this.ERR_NAME_COLLISION);
return false;
}
let newcable = new VisualCable(this.rootObject, cablename);
let from = this.rootObject.find(L1,R1,F1);
let to = this.rootObject.find(L2,R2,F2);
this.statevars['cable_name'] = cablename;
this.statevars['frame_ref'] = L1+"$"+R1+"$"+F1;
if(!from)
{
this.warn(WARN_INVALID_CABLE);
return true;
}
this.statevars['frame_ref'] = L2+"$"+R2+"$"+F2;
if(!to)
{
this.warn(WARN_INVALID_CABLE);
return true;
}
newcable.from=from;
newcable.to=to;
this.objectStack.unshift(newcable);
return true;
}
};