corba.js 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/lib/idl/src/idl/cc/typeIDLtoCC.d.ts +6 -0
  2. package/lib/idl/src/idl/cc/typeIDLtoGIOPCC.d.ts +3 -0
  3. package/lib/idl/src/idl/cc/write-code.d.ts +2 -0
  4. package/lib/idl/src/idl/cc/write-interface.d.ts +5 -0
  5. package/lib/idl/src/idl/cc/write-skeleton.d.ts +2 -0
  6. package/lib/idl/src/idl/cc/write-stub.d.ts +2 -0
  7. package/lib/idl/src/idl/idl-lexer.d.ts +19 -0
  8. package/lib/idl/src/idl/idl-node.d.ts +102 -0
  9. package/lib/idl/src/idl/idl-parser.d.ts +3 -0
  10. package/lib/idl/src/idl/idl.d.ts +1 -0
  11. package/lib/idl/src/idl/ts/typeIDLtoGIOPTS.d.ts +3 -0
  12. package/lib/idl/src/idl/ts/typeIDLtoTS.d.ts +3 -0
  13. package/lib/idl/src/idl/ts/write-interface.d.ts +2 -0
  14. package/lib/idl/src/idl/ts/write-skeleton.d.ts +2 -0
  15. package/lib/idl/src/idl/ts/write-stub.d.ts +2 -0
  16. package/lib/idl/src/idl/ts/write-value.d.ts +2 -0
  17. package/lib/idl/src/idl/ts/write-valueimpl.d.ts +2 -0
  18. package/lib/idl/src/idl/ts/write-valuetype.d.ts +2 -0
  19. package/lib/idl/src/idl/util.d.ts +23 -0
  20. package/lib/idl/src/index.d.ts +5 -0
  21. package/lib/idl/src/net/browser.d.ts +7 -0
  22. package/lib/idl/src/net/index.d.ts +3 -0
  23. package/lib/idl/src/net/tcp.d.ts +11 -0
  24. package/lib/idl/src/net/tls.d.ts +24 -0
  25. package/lib/idl/src/net/ws.d.ts +44 -0
  26. package/lib/idl/src/orb/asn1.d.ts +48 -0
  27. package/lib/idl/src/orb/connection.d.ts +24 -0
  28. package/lib/idl/src/orb/giop.d.ts +283 -0
  29. package/lib/idl/src/orb/index.d.ts +3 -0
  30. package/lib/idl/src/orb/ior.d.ts +89 -0
  31. package/lib/idl/src/orb/orb.d.ts +143 -0
  32. package/lib/idl/src/orb/protocol.d.ts +6 -0
  33. package/lib/idl/src/orb/uint8map.d.ts +14 -0
  34. package/lib/idl/src/orb/url.d.ts +55 -0
  35. package/lib/src/idl/cc/typeIDLtoCC.d.ts +6 -0
  36. package/lib/src/idl/cc/typeIDLtoCC.js +127 -0
  37. package/lib/src/idl/cc/typeIDLtoCC.js.map +1 -0
  38. package/lib/src/idl/cc/typeIDLtoGIOPCC.d.ts +3 -0
  39. package/lib/src/idl/cc/typeIDLtoGIOPCC.js +127 -0
  40. package/lib/src/idl/cc/typeIDLtoGIOPCC.js.map +1 -0
  41. package/lib/src/idl/cc/write-code.d.ts +2 -0
  42. package/lib/src/idl/cc/write-code.js +213 -0
  43. package/lib/src/idl/cc/write-code.js.map +1 -0
  44. package/lib/src/idl/cc/write-interface.d.ts +5 -0
  45. package/lib/src/idl/cc/write-interface.js +228 -0
  46. package/lib/src/idl/cc/write-interface.js.map +1 -0
  47. package/lib/src/idl/cc/write-skeleton.d.ts +2 -0
  48. package/lib/src/idl/cc/write-skeleton.js +43 -0
  49. package/lib/src/idl/cc/write-skeleton.js.map +1 -0
  50. package/lib/src/idl/cc/write-stub.d.ts +2 -0
  51. package/lib/src/idl/cc/write-stub.js +91 -0
  52. package/lib/src/idl/cc/write-stub.js.map +1 -0
  53. package/lib/src/idl/idl-lexer.d.ts +19 -0
  54. package/lib/src/idl/idl-lexer.js +234 -0
  55. package/lib/src/idl/idl-lexer.js.map +1 -0
  56. package/lib/src/idl/idl-node.d.ts +102 -0
  57. package/lib/src/idl/idl-node.js +214 -0
  58. package/lib/src/idl/idl-node.js.map +1 -0
  59. package/lib/src/idl/idl-parser.d.ts +3 -0
  60. package/lib/src/idl/idl-parser.js +1210 -0
  61. package/lib/src/idl/idl-parser.js.map +1 -0
  62. package/lib/src/idl/idl.d.ts +1 -0
  63. package/lib/src/idl/idl.js +219 -0
  64. package/lib/src/idl/idl.js.map +1 -0
  65. package/lib/src/idl/ts/typeIDLtoGIOPTS.d.ts +3 -0
  66. package/lib/src/idl/ts/typeIDLtoGIOPTS.js +101 -0
  67. package/lib/src/idl/ts/typeIDLtoGIOPTS.js.map +1 -0
  68. package/lib/src/idl/ts/typeIDLtoTS.d.ts +3 -0
  69. package/lib/src/idl/ts/typeIDLtoTS.js +92 -0
  70. package/lib/src/idl/ts/typeIDLtoTS.js.map +1 -0
  71. package/lib/src/idl/ts/write-interface.d.ts +2 -0
  72. package/lib/src/idl/ts/write-interface.js +214 -0
  73. package/lib/src/idl/ts/write-interface.js.map +1 -0
  74. package/lib/src/idl/ts/write-skeleton.d.ts +2 -0
  75. package/lib/src/idl/ts/write-skeleton.js +118 -0
  76. package/lib/src/idl/ts/write-skeleton.js.map +1 -0
  77. package/lib/src/idl/ts/write-stub.d.ts +2 -0
  78. package/lib/src/idl/ts/write-stub.js +118 -0
  79. package/lib/src/idl/ts/write-stub.js.map +1 -0
  80. package/lib/src/idl/ts/write-value.d.ts +2 -0
  81. package/lib/src/idl/ts/write-value.js +208 -0
  82. package/lib/src/idl/ts/write-value.js.map +1 -0
  83. package/lib/src/idl/ts/write-valueimpl.d.ts +2 -0
  84. package/lib/src/idl/ts/write-valueimpl.js +159 -0
  85. package/lib/src/idl/ts/write-valueimpl.js.map +1 -0
  86. package/lib/src/idl/ts/write-valuetype.d.ts +2 -0
  87. package/lib/src/idl/ts/write-valuetype.js +99 -0
  88. package/lib/src/idl/ts/write-valuetype.js.map +1 -0
  89. package/lib/src/idl/util.d.ts +23 -0
  90. package/lib/src/idl/util.js +84 -0
  91. package/lib/src/idl/util.js.map +1 -0
  92. package/lib/src/index.d.ts +5 -0
  93. package/lib/src/index.js +6 -0
  94. package/lib/src/index.js.map +1 -0
  95. package/lib/src/net/browser.d.ts +7 -0
  96. package/lib/src/net/browser.js +55 -0
  97. package/lib/src/net/browser.js.map +1 -0
  98. package/lib/src/net/index.d.ts +3 -0
  99. package/lib/src/net/index.js +4 -0
  100. package/lib/src/net/index.js.map +1 -0
  101. package/lib/src/net/tcp.d.ts +11 -0
  102. package/lib/src/net/tcp.js +66 -0
  103. package/lib/src/net/tcp.js.map +1 -0
  104. package/lib/src/net/tls.d.ts +24 -0
  105. package/lib/src/net/tls.js +69 -0
  106. package/lib/src/net/tls.js.map +1 -0
  107. package/lib/src/net/ws.d.ts +44 -0
  108. package/lib/src/net/ws.js +158 -0
  109. package/lib/src/net/ws.js.map +1 -0
  110. package/lib/src/orb/asn1.d.ts +48 -0
  111. package/lib/src/orb/asn1.js +60 -0
  112. package/lib/src/orb/asn1.js.map +1 -0
  113. package/lib/src/orb/connection.d.ts +24 -0
  114. package/lib/src/orb/connection.js +19 -0
  115. package/lib/src/orb/connection.js.map +1 -0
  116. package/lib/src/orb/giop.d.ts +283 -0
  117. package/lib/src/orb/giop.js +1301 -0
  118. package/lib/src/orb/giop.js.map +1 -0
  119. package/lib/src/orb/index.d.ts +3 -0
  120. package/lib/src/orb/index.js +4 -0
  121. package/lib/src/orb/index.js.map +1 -0
  122. package/lib/src/orb/ior.d.ts +89 -0
  123. package/lib/src/orb/ior.js +113 -0
  124. package/lib/src/orb/ior.js.map +1 -0
  125. package/lib/src/orb/orb.d.ts +143 -0
  126. package/lib/src/orb/orb.js +693 -0
  127. package/lib/src/orb/orb.js.map +1 -0
  128. package/lib/src/orb/protocol.d.ts +6 -0
  129. package/lib/src/orb/protocol.js +2 -0
  130. package/lib/src/orb/protocol.js.map +1 -0
  131. package/lib/src/orb/uint8map.d.ts +14 -0
  132. package/lib/src/orb/uint8map.js +48 -0
  133. package/lib/src/orb/uint8map.js.map +1 -0
  134. package/lib/src/orb/url.d.ts +55 -0
  135. package/lib/src/orb/url.js +255 -0
  136. package/lib/src/orb/url.js.map +1 -0
  137. package/package.json +79 -71
  138. package/m13-es-transformer.cjs +0 -190
@@ -0,0 +1,1210 @@
1
+ import { Type, Node } from "./idl-node.js";
2
+ let lexer;
3
+ let scoper;
4
+ export function specification(aLexer) {
5
+ lexer = aLexer;
6
+ scoper = new ScopeManager();
7
+ let node = new Node(Type.SYN_SPECIFICATION);
8
+ while (true) {
9
+ let t0 = definition();
10
+ if (t0 === undefined)
11
+ break;
12
+ node.append(t0);
13
+ }
14
+ const tail = lexer.lex();
15
+ if (tail !== undefined) {
16
+ throw Error(`Unparsed token '${tail.toString()}' at end of specification.`);
17
+ }
18
+ return node;
19
+ }
20
+ function definition() {
21
+ let t0;
22
+ t0 = type_dcl();
23
+ if (t0 === undefined)
24
+ t0 = except_dcl();
25
+ if (t0 === undefined)
26
+ t0 = _interface();
27
+ if (t0 === undefined)
28
+ t0 = _module();
29
+ if (t0 === undefined)
30
+ t0 = value();
31
+ if (t0 !== undefined) {
32
+ expect(';');
33
+ }
34
+ return t0;
35
+ }
36
+ function _module() {
37
+ let t0 = lexer.lex();
38
+ if (t0 !== undefined && t0.type === Type.TKN_MODULE) {
39
+ let t1 = identifier();
40
+ if (t1 === undefined)
41
+ throw Error("expected identifier after 'module'");
42
+ t0.text = t1.text;
43
+ expect("{");
44
+ scoper.enterModule(t0);
45
+ while (true) {
46
+ let t2 = definition();
47
+ if (t2 === undefined)
48
+ break;
49
+ if (t2.type == Type.TKN_NATIVE)
50
+ throw Error("'native' can not be used within 'module'");
51
+ t0.append(t2);
52
+ }
53
+ expect("}");
54
+ scoper.leaveModule(t0);
55
+ return t0;
56
+ }
57
+ lexer.unlex(t0);
58
+ return undefined;
59
+ }
60
+ function _interface() {
61
+ return interface_dcl();
62
+ }
63
+ function interface_dcl() {
64
+ let t0 = interface_header();
65
+ if (!t0) {
66
+ t0 = lexer.lex();
67
+ if (t0) {
68
+ lexer.unlex(t0);
69
+ }
70
+ return undefined;
71
+ }
72
+ let t1 = lexer.lex();
73
+ if (t1 === undefined)
74
+ throw Error("expected { after interface header but got end of file");
75
+ if (t1.type !== Type.TKN_TEXT && t1.text != '{')
76
+ throw Error(`expected { after interface header but got ${t0}`);
77
+ let node = new Node(Type.SYN_INTERFACE, t0.child[1].text);
78
+ scoper.addType(t0.child[1].text, node);
79
+ node.append(t0);
80
+ let t2 = interface_body();
81
+ node.append(t2);
82
+ let t3 = lexer.lex();
83
+ if (!t3)
84
+ throw Error("unexpected end of file");
85
+ if (t3.type !== Type.TKN_TEXT && t3.text != '}')
86
+ throw Error(`expected } after interface body but got '${t3}'`);
87
+ return node;
88
+ }
89
+ function interface_header() {
90
+ let t0 = lexer.lex();
91
+ if (t0 === undefined)
92
+ return undefined;
93
+ let t1;
94
+ if (t0.type !== Type.TKN_ABSTRACT && t0.type !== Type.TKN_LOCAL) {
95
+ t1 = t0;
96
+ t0 = undefined;
97
+ }
98
+ else {
99
+ t1 = lexer.lex();
100
+ }
101
+ if (t1 === undefined) {
102
+ lexer.unlex(t0);
103
+ return undefined;
104
+ }
105
+ if (t1.type !== Type.TKN_INTERFACE) {
106
+ lexer.unlex(t1);
107
+ lexer.unlex(t0);
108
+ return undefined;
109
+ }
110
+ let t2 = identifier();
111
+ if (t2 === undefined)
112
+ throw Error("expected identifier after 'interface'");
113
+ let header = new Node(Type.SYN_INTERFACE_HEADER);
114
+ header.append(t0);
115
+ header.append(t2);
116
+ header.append(undefined);
117
+ return header;
118
+ }
119
+ function interface_body() {
120
+ let body = new Node(Type.SYN_INTERFACE_BODY);
121
+ while (true) {
122
+ let t0 = _export();
123
+ if (t0 === undefined)
124
+ return body;
125
+ body.append(t0);
126
+ }
127
+ }
128
+ function _export() {
129
+ let t0 = attr_dcl();
130
+ if (t0 === undefined)
131
+ t0 = op_dcl();
132
+ if (t0 === undefined)
133
+ return undefined;
134
+ expect(';');
135
+ return t0;
136
+ }
137
+ function scoped_name() {
138
+ let globalNamespaceToken = undefined;
139
+ let identifierToken = lexer.lex();
140
+ if (identifierToken === undefined)
141
+ return undefined;
142
+ if (identifierToken.type === Type.TKN_COLON_COLON) {
143
+ globalNamespaceToken = identifierToken;
144
+ identifierToken = lexer.lex();
145
+ if (identifierToken === undefined) {
146
+ lexer.unlex(globalNamespaceToken);
147
+ return undefined;
148
+ }
149
+ }
150
+ if (identifierToken.type !== Type.TKN_IDENTIFIER) {
151
+ lexer.unlex(identifierToken);
152
+ lexer.unlex(globalNamespaceToken);
153
+ return undefined;
154
+ }
155
+ let type;
156
+ if (globalNamespaceToken === undefined) {
157
+ type = scoper.getType(identifierToken.text);
158
+ }
159
+ else {
160
+ type = scoper.getGlobalScope().getType(identifierToken.text);
161
+ throw Error(`No way known to translate '::${identifierToken.text}' to TypeScript`);
162
+ }
163
+ if (type === undefined) {
164
+ throw Error(`unknown type ${identifierToken}`);
165
+ }
166
+ identifierToken.append(type);
167
+ if (type.type === Type.TKN_MODULE) {
168
+ resolve_module(identifierToken, type);
169
+ }
170
+ if (type.type === Type.TKN_NATIVE &&
171
+ type.text.length > 4 &&
172
+ type.text.substring(type.text.length - 4) === "_ptr" &&
173
+ type.typeParent === undefined) {
174
+ type.typeParent = scoper.getType(type.text.substring(0, type.text.length - 4));
175
+ }
176
+ return identifierToken;
177
+ }
178
+ function value() {
179
+ let t0;
180
+ t0 = value_dcl();
181
+ if (t0 !== undefined)
182
+ return t0;
183
+ t0 = value_abs_dcl();
184
+ if (t0 !== undefined)
185
+ return t0;
186
+ t0 = value_box_dcl();
187
+ if (t0 !== undefined)
188
+ return t0;
189
+ t0 = value_forward_dcl();
190
+ if (t0 !== undefined)
191
+ return t0;
192
+ return undefined;
193
+ }
194
+ function value_forward_dcl() {
195
+ return undefined;
196
+ }
197
+ function value_box_dcl() {
198
+ return undefined;
199
+ }
200
+ function value_abs_dcl() {
201
+ return undefined;
202
+ }
203
+ function value_dcl() {
204
+ let header = value_header();
205
+ if (header === undefined) {
206
+ return undefined;
207
+ }
208
+ expect('{');
209
+ let node = new Node(Type.TKN_VALUETYPE);
210
+ node.append(header);
211
+ let identifier = header.child[1].text;
212
+ node.text = identifier;
213
+ scoper.addType(identifier, node);
214
+ while (true) {
215
+ let t1 = value_element();
216
+ if (t1 === undefined)
217
+ break;
218
+ node.append(t1);
219
+ }
220
+ expect('}');
221
+ return node;
222
+ }
223
+ function value_header() {
224
+ let t0 = lexer.lex();
225
+ if (t0 !== undefined) {
226
+ let t1;
227
+ if (t0.type === Type.TKN_CUSTOM) {
228
+ throw Error("corba.js currently does not support custom valuetypes");
229
+ }
230
+ else {
231
+ t1 = t0;
232
+ t0 = undefined;
233
+ }
234
+ if (t1 !== undefined && t1.type === Type.TKN_VALUETYPE) {
235
+ let t2 = identifier();
236
+ if (t2 === undefined)
237
+ throw Error("expected an identifier after valuetype");
238
+ let t3 = value_inheritance_spec();
239
+ let node = new Node(Type.SYN_VALUE_HEADER);
240
+ node.append(t0);
241
+ node.append(t2);
242
+ node.append(t3);
243
+ return node;
244
+ }
245
+ lexer.unlex(t1);
246
+ }
247
+ lexer.unlex(t0);
248
+ return undefined;
249
+ }
250
+ function value_inheritance_spec() {
251
+ let t0 = lexer.lex();
252
+ if (t0 === undefined || t0.type !== Type.TKN_TEXT || t0.text !== ":") {
253
+ lexer.unlex(t0);
254
+ return undefined;
255
+ }
256
+ let t1 = lexer.lex();
257
+ if (t1 !== undefined && t1.type !== Type.TKN_TRUNCATABLE) {
258
+ lexer.unlex(t1);
259
+ t1 = undefined;
260
+ }
261
+ if (t1 !== undefined)
262
+ throw Error("'truncatable' is not supported");
263
+ let node = new Node(Type.SYN_VALUE_INHERITANCE_SPEC);
264
+ node.append(t1);
265
+ while (true) {
266
+ let t2 = value_name();
267
+ if (t2 === undefined) {
268
+ throw Error("expected a value name after '" + t0.text + "'");
269
+ }
270
+ node.append(t2);
271
+ let t3 = lexer.lex();
272
+ if (t3 === undefined)
273
+ throw Error("unexpected end of file");
274
+ if (t3.type !== Type.TKN_TEXT || t3.text !== ",") {
275
+ lexer.unlex(t3);
276
+ break;
277
+ }
278
+ t0 = value_name();
279
+ if (t0 === undefined)
280
+ throw Error("expected a value name after ':'");
281
+ }
282
+ return node;
283
+ }
284
+ function value_name() {
285
+ return scoped_name();
286
+ }
287
+ function value_element() {
288
+ let t0 = _export();
289
+ if (t0 === undefined)
290
+ t0 = state_member();
291
+ return t0;
292
+ }
293
+ function state_member() {
294
+ let t0 = lexer.lex();
295
+ if (t0 === undefined)
296
+ return undefined;
297
+ if (t0.type !== Type.TKN_PUBLIC && t0.type !== Type.TKN_PRIVATE) {
298
+ lexer.unlex(t0);
299
+ return undefined;
300
+ }
301
+ let t1 = type_spec();
302
+ if (t1 === undefined) {
303
+ lexer.unlex(t0);
304
+ return undefined;
305
+ }
306
+ let t2 = declarators();
307
+ if (t2 === undefined) {
308
+ throw Error("expected declarators");
309
+ }
310
+ expect(";");
311
+ let node = new Node(Type.SYN_STATE_MEMBER);
312
+ node.append(t0);
313
+ node.append(t1);
314
+ node.append(t2);
315
+ return node;
316
+ }
317
+ function type_dcl() {
318
+ let t0 = lexer.lex();
319
+ if (t0 !== undefined && t0.type === Type.TKN_TYPEDEF) {
320
+ let t1 = type_declarator();
321
+ if (t1 === undefined) {
322
+ lexer.unlex(t0);
323
+ return undefined;
324
+ }
325
+ const identifiers = t1.child[1].child;
326
+ for (const id of identifiers) {
327
+ scoper.addType(id.text, t1.child[0]);
328
+ }
329
+ t1.type = t0.type;
330
+ return t1;
331
+ }
332
+ lexer.unlex(t0);
333
+ t0 = struct_type();
334
+ if (t0 !== undefined)
335
+ return t0;
336
+ t0 = union_type();
337
+ if (t0 !== undefined)
338
+ return t0;
339
+ t0 = enum_type();
340
+ if (t0 !== undefined)
341
+ return t0;
342
+ t0 = lexer.lex();
343
+ if (t0 !== undefined && t0.type === Type.TKN_NATIVE) {
344
+ let t1 = simple_declarator();
345
+ if (t1 === undefined) {
346
+ throw Error("expected simple declarator after 'native'");
347
+ }
348
+ t0.append(t1);
349
+ t0.text = t1.text;
350
+ scoper.addType(t1.text, t0);
351
+ return t0;
352
+ }
353
+ lexer.unlex(t0);
354
+ return undefined;
355
+ }
356
+ function type_declarator() {
357
+ const t0 = type_spec();
358
+ if (t0 === undefined)
359
+ return undefined;
360
+ const t1 = declarators();
361
+ if (t1 == undefined) {
362
+ throw Error("expected at least one declarator");
363
+ }
364
+ const n = new Node(Type.SYN_TYPE_DECLARATOR);
365
+ n.append(t0);
366
+ n.append(t1);
367
+ return n;
368
+ }
369
+ function type_spec() {
370
+ let t0;
371
+ t0 = simple_type_spec();
372
+ if (t0 === undefined)
373
+ t0 = constr_type_spec();
374
+ return t0;
375
+ }
376
+ function simple_type_spec() {
377
+ let t0;
378
+ t0 = base_type_spec();
379
+ if (t0 === undefined)
380
+ t0 = template_type_spec();
381
+ if (t0 === undefined)
382
+ t0 = scoped_name();
383
+ return t0;
384
+ }
385
+ function base_type_spec() {
386
+ let t0;
387
+ t0 = floating_pt_type();
388
+ if (t0 !== undefined)
389
+ return t0;
390
+ t0 = integer_type();
391
+ if (t0 !== undefined)
392
+ return t0;
393
+ t0 = char_type();
394
+ if (t0 !== undefined)
395
+ return t0;
396
+ t0 = wide_char_type();
397
+ if (t0 !== undefined)
398
+ return t0;
399
+ t0 = boolean_type();
400
+ if (t0 !== undefined)
401
+ return t0;
402
+ t0 = octet_type();
403
+ if (t0 !== undefined)
404
+ return t0;
405
+ t0 = any_type();
406
+ if (t0 !== undefined)
407
+ return t0;
408
+ return undefined;
409
+ }
410
+ function template_type_spec() {
411
+ let t0;
412
+ t0 = sequence_type();
413
+ if (t0 !== undefined)
414
+ return t0;
415
+ t0 = string_type();
416
+ if (t0 !== undefined)
417
+ return t0;
418
+ t0 = wide_string_type();
419
+ if (t0 !== undefined)
420
+ return t0;
421
+ return undefined;
422
+ }
423
+ function constr_type_spec() {
424
+ let t0 = struct_type();
425
+ if (t0 === undefined)
426
+ t0 = union_type();
427
+ if (t0 === undefined)
428
+ t0 = enum_type();
429
+ return t0;
430
+ }
431
+ function declarators() {
432
+ let t0 = declarator();
433
+ if (t0 === undefined)
434
+ return undefined;
435
+ let node = new Node(Type.SYN_DECLARATORS);
436
+ while (true) {
437
+ node.append(t0);
438
+ let t1 = lexer.lex();
439
+ if (t1 === undefined || t1.type !== Type.TKN_TEXT || t1.text !== ",") {
440
+ lexer.unlex(t1);
441
+ break;
442
+ }
443
+ t0 = declarator();
444
+ if (t0 === undefined)
445
+ throw Error("expected another declarator after ','");
446
+ }
447
+ return node;
448
+ }
449
+ function declarator() {
450
+ let t0;
451
+ t0 = simple_declarator();
452
+ return t0;
453
+ }
454
+ function simple_declarator() {
455
+ return identifier();
456
+ }
457
+ function floating_pt_type() {
458
+ let t0 = lexer.lex();
459
+ if (t0 === undefined)
460
+ return undefined;
461
+ if (t0.type === Type.TKN_FLOAT)
462
+ return t0;
463
+ if (t0.type === Type.TKN_DOUBLE)
464
+ return t0;
465
+ if (t0.type === Type.TKN_LONG) {
466
+ let t1 = lexer.lex();
467
+ if (t1 !== undefined && t1.type === Type.TKN_DOUBLE) {
468
+ t1.type = Type.SYN_LONG_DOUBLE;
469
+ return t1;
470
+ }
471
+ lexer.unlex(t1);
472
+ }
473
+ lexer.unlex(t0);
474
+ return undefined;
475
+ }
476
+ function integer_type() {
477
+ let t0;
478
+ t0 = signed_int();
479
+ if (t0 !== undefined)
480
+ return t0;
481
+ t0 = unsigned_int();
482
+ if (t0 !== undefined) {
483
+ return t0;
484
+ }
485
+ t0 = lexer.lex();
486
+ if (t0 !== undefined && [Type.TKN_SHORT, Type.TKN_LONG, Type.TKN_UNSIGNED].includes(t0.type)) {
487
+ throw Error('valid integer types are: short, unsigned short, long, unsigned long, long long, unsigned long long');
488
+ }
489
+ lexer.unlex(t0);
490
+ return undefined;
491
+ }
492
+ function signed_int() {
493
+ let t0;
494
+ t0 = signed_short_int();
495
+ if (t0 !== undefined)
496
+ return t0;
497
+ t0 = signed_longlong_int();
498
+ if (t0 !== undefined)
499
+ return t0;
500
+ t0 = signed_long_int();
501
+ if (t0 !== undefined)
502
+ return t0;
503
+ return undefined;
504
+ }
505
+ function signed_short_int() {
506
+ let t0 = lexer.lex();
507
+ if (t0 !== undefined && t0.type === Type.TKN_SHORT)
508
+ return t0;
509
+ lexer.unlex(t0);
510
+ return undefined;
511
+ }
512
+ function signed_long_int() {
513
+ let t0 = lexer.lex();
514
+ if (t0 === undefined)
515
+ return undefined;
516
+ if (t0.type === Type.TKN_LONG)
517
+ return t0;
518
+ lexer.unlex(t0);
519
+ return undefined;
520
+ }
521
+ function signed_longlong_int() {
522
+ let t0 = lexer.lex();
523
+ if (t0 !== undefined && t0.type === Type.TKN_LONG) {
524
+ let t1 = lexer.lex();
525
+ if (t1 !== undefined && t1.type === Type.TKN_LONG) {
526
+ t0.type = Type.SYN_LONGLONG;
527
+ return t0;
528
+ }
529
+ lexer.unlex(t1);
530
+ }
531
+ lexer.unlex(t0);
532
+ return undefined;
533
+ }
534
+ function unsigned_int() {
535
+ let t0;
536
+ t0 = unsigned_short_int();
537
+ if (t0 !== undefined)
538
+ return t0;
539
+ t0 = unsigned_longlong_int();
540
+ if (t0 !== undefined)
541
+ return t0;
542
+ t0 = unsigned_long_int();
543
+ if (t0 !== undefined)
544
+ return t0;
545
+ return undefined;
546
+ }
547
+ function unsigned_short_int() {
548
+ let t0 = lexer.lex();
549
+ if (t0 !== undefined && t0.type === Type.TKN_UNSIGNED) {
550
+ let t1 = lexer.lex();
551
+ if (t1 !== undefined && t1.type === Type.TKN_SHORT) {
552
+ t0.type = Type.SYN_UNSIGNED_SHORT;
553
+ return t0;
554
+ }
555
+ lexer.unlex(t1);
556
+ }
557
+ lexer.unlex(t0);
558
+ return undefined;
559
+ }
560
+ function unsigned_long_int() {
561
+ let t0 = lexer.lex();
562
+ if (t0 !== undefined && t0.type === Type.TKN_UNSIGNED) {
563
+ let t1 = lexer.lex();
564
+ if (t1 !== undefined && t1.type === Type.TKN_LONG) {
565
+ t0.type = Type.SYN_UNSIGNED_LONG;
566
+ return t0;
567
+ }
568
+ lexer.unlex(t1);
569
+ }
570
+ lexer.unlex(t0);
571
+ return undefined;
572
+ }
573
+ function unsigned_longlong_int() {
574
+ let t0 = lexer.lex();
575
+ if (t0 !== undefined && t0.type === Type.TKN_UNSIGNED) {
576
+ let t1 = lexer.lex();
577
+ if (t1 !== undefined && t1.type === Type.TKN_LONG) {
578
+ let t2 = lexer.lex();
579
+ if (t2 !== undefined && t2.type === Type.TKN_LONG) {
580
+ t0.type = Type.SYN_UNSIGNED_LONGLONG;
581
+ return t0;
582
+ }
583
+ lexer.unlex(t2);
584
+ }
585
+ lexer.unlex(t1);
586
+ }
587
+ lexer.unlex(t0);
588
+ return undefined;
589
+ }
590
+ function char_type() {
591
+ let t0 = lexer.lex();
592
+ if (t0 !== undefined && t0.type == Type.TKN_CHAR)
593
+ return t0;
594
+ lexer.unlex(t0);
595
+ return undefined;
596
+ }
597
+ function wide_char_type() {
598
+ let t0 = lexer.lex();
599
+ if (t0 !== undefined && t0.type == Type.TKN_WCHAR)
600
+ return t0;
601
+ lexer.unlex(t0);
602
+ return undefined;
603
+ }
604
+ function boolean_type() {
605
+ let t0 = lexer.lex();
606
+ if (t0 !== undefined && t0.type == Type.TKN_BOOLEAN)
607
+ return t0;
608
+ lexer.unlex(t0);
609
+ return undefined;
610
+ }
611
+ function octet_type() {
612
+ let t0 = lexer.lex();
613
+ if (t0 !== undefined && t0.type == Type.TKN_OCTET)
614
+ return t0;
615
+ lexer.unlex(t0);
616
+ return undefined;
617
+ }
618
+ function any_type() {
619
+ const t0 = lexer.lex();
620
+ if (t0 !== undefined && t0.type == Type.TKN_ANY)
621
+ return t0;
622
+ lexer.unlex(t0);
623
+ return undefined;
624
+ }
625
+ function struct_type() {
626
+ const t0 = lexer.lex();
627
+ if (t0 === undefined || t0.type !== Type.TKN_STRUCT) {
628
+ lexer.unlex(t0);
629
+ return undefined;
630
+ }
631
+ const t1 = identifier();
632
+ if (t1 === undefined)
633
+ throw Error("expected identifier after 'struct'");
634
+ expect('{');
635
+ const t2 = member_list();
636
+ if (t2 === undefined)
637
+ throw Error("expected at least one member within 'struct'");
638
+ expect('}');
639
+ t2.type = t0.type;
640
+ t2.text = t1.text;
641
+ scoper.addType(t2.text, t2);
642
+ return t2;
643
+ }
644
+ function member_list() {
645
+ const t0 = member();
646
+ if (t0 === undefined)
647
+ return undefined;
648
+ const node = new Node(Type.SYN_MEMBER_LIST);
649
+ node.append(t0);
650
+ while (true) {
651
+ const t1 = member();
652
+ if (t1 === undefined)
653
+ break;
654
+ node.append(t1);
655
+ }
656
+ return node;
657
+ }
658
+ function member() {
659
+ const node = new Node(Type.SYN_MEMBER);
660
+ const t0 = type_spec();
661
+ if (t0 === undefined)
662
+ return undefined;
663
+ const t1 = declarators();
664
+ if (t1 === undefined)
665
+ throw Error(`expected declarators after type_spec ${t0.toString()}`);
666
+ expect(";");
667
+ node.append(t0);
668
+ node.append(t1);
669
+ return node;
670
+ }
671
+ function union_type() {
672
+ let t0 = lexer.lex();
673
+ if (t0 === undefined)
674
+ return undefined;
675
+ if (t0.type !== Type.TKN_UNION) {
676
+ lexer.unlex(t0);
677
+ return undefined;
678
+ }
679
+ let t1 = identifier();
680
+ if (t1 === undefined)
681
+ throw Error(`expected identifier after 'union'`);
682
+ let t2 = lexer.lex();
683
+ if (t2 === undefined || t2.type !== Type.TKN_SWITCH) {
684
+ throw Error(`expected 'switch' after union <identifier>`);
685
+ }
686
+ expect("(");
687
+ let t3 = switch_type_spec();
688
+ if (t3 === undefined) {
689
+ throw Error(`expected switch type specifier after union <identifier> switch(`);
690
+ }
691
+ expect(")");
692
+ expect("{");
693
+ let t4 = switch_body();
694
+ expect("}");
695
+ t0.text = t1.text;
696
+ t0.append(t3);
697
+ t0.append(t4);
698
+ scoper.addType(t0.text, t0);
699
+ return t0;
700
+ }
701
+ function switch_type_spec() {
702
+ let t0 = integer_type();
703
+ if (t0 !== undefined)
704
+ return t0;
705
+ t0 = char_type();
706
+ if (t0 !== undefined)
707
+ return t0;
708
+ t0 = boolean_type();
709
+ if (t0 !== undefined)
710
+ return t0;
711
+ t0 = enum_type();
712
+ if (t0 !== undefined)
713
+ return t0;
714
+ return scoped_name();
715
+ }
716
+ function switch_body() {
717
+ let t0 = new Node(Type.SYN_SWITCH_BODY);
718
+ while (true) {
719
+ const t1 = _case();
720
+ if (t1 === undefined)
721
+ break;
722
+ t0.append(t1);
723
+ }
724
+ return t0;
725
+ }
726
+ function _case() {
727
+ let t0 = case_label();
728
+ if (t0 === undefined)
729
+ return t0;
730
+ let t1 = element_spec();
731
+ if (t1 === undefined)
732
+ throw Error(`expected element specification after '${t0}'`);
733
+ t0.append(t1.child[0]);
734
+ t0.append(t1.child[1]);
735
+ expect(";");
736
+ return t0;
737
+ }
738
+ function case_label() {
739
+ let t0 = lexer.lex();
740
+ if (t0 === undefined)
741
+ return undefined;
742
+ if (t0.type === Type.TKN_CASE) {
743
+ let t1 = identifier();
744
+ if (t1 === undefined) {
745
+ throw Error(`expected enum identifier after 'case'`);
746
+ }
747
+ const t = scoper.getType(t1.text);
748
+ if (t?.typeParent?.type === Type.TKN_ENUM) {
749
+ }
750
+ else {
751
+ throw Error(`unsupported value after 'case'`);
752
+ }
753
+ expect(":");
754
+ t0.append(t);
755
+ return t0;
756
+ }
757
+ if (t0.type === Type.TKN_DEFAULT) {
758
+ expect(":");
759
+ return t0;
760
+ }
761
+ lexer.unlex(t0);
762
+ return undefined;
763
+ }
764
+ function element_spec() {
765
+ let t0 = type_spec();
766
+ if (t0 === undefined)
767
+ return undefined;
768
+ let t1 = declarator();
769
+ if (t1 === undefined)
770
+ throw Error(`expected declarator after ${t0}`);
771
+ let t2 = new Node(Type.NONE);
772
+ t2.append(t0);
773
+ t2.append(t1);
774
+ return t2;
775
+ }
776
+ function enum_type() {
777
+ let t0 = lexer.lex();
778
+ if (t0 !== undefined && t0.type == Type.TKN_ENUM) {
779
+ const t1 = identifier();
780
+ if (t1 === undefined)
781
+ throw Error("expected identifier after 'enum'");
782
+ t0.text = t1.text;
783
+ expect("{");
784
+ const usedNames = new Set();
785
+ let t3;
786
+ while (true) {
787
+ let t2 = lexer.lex();
788
+ if (t2 === undefined) {
789
+ throw Error("unexpected end of file");
790
+ }
791
+ if (t2.type !== Type.TKN_IDENTIFIER) {
792
+ if (t3) {
793
+ throw Error(`expected identifier after ',' but got ${t2})`);
794
+ }
795
+ else {
796
+ throw Error(`expected identifier but got ${t2})`);
797
+ }
798
+ }
799
+ if (usedNames.has(t2.text)) {
800
+ throw Error(`Declaration of enumerator '${t2.text}' clashes with earlier declaration of enumerator '${t2.text}'`);
801
+ }
802
+ usedNames.add(t2.text);
803
+ scoper.addType(t2.text, t2);
804
+ t0.append(t2);
805
+ t2.typeParent = t0;
806
+ t3 = lexer.lex();
807
+ if (t3 === undefined)
808
+ throw Error("unexpected end of file");
809
+ if (t3.type !== Type.TKN_TEXT)
810
+ throw Error(`expected ',' or '}' but got ${t3}`);
811
+ if (t3.text === "}")
812
+ break;
813
+ if (t3.text !== ",") {
814
+ throw Error(`expected ',' or '}' but got ${t3}`);
815
+ }
816
+ }
817
+ scoper.addType(t0.text, t0);
818
+ return t0;
819
+ }
820
+ lexer.unlex(t0);
821
+ return undefined;
822
+ }
823
+ function sequence_type() {
824
+ let t0 = lexer.lex();
825
+ if (t0 !== undefined && t0.type === Type.TKN_SEQUENCE) {
826
+ expect("<");
827
+ let t1 = simple_type_spec();
828
+ if (t1 === undefined)
829
+ throw Error("expected type after 'sequence <'");
830
+ expect(">");
831
+ t0.append(t1);
832
+ t0.append(undefined);
833
+ return t0;
834
+ }
835
+ lexer.unlex(t0);
836
+ return undefined;
837
+ }
838
+ function string_type() {
839
+ let t0 = lexer.lex();
840
+ if (t0 !== undefined && t0.type === Type.TKN_STRING) {
841
+ return t0;
842
+ }
843
+ lexer.unlex(t0);
844
+ return undefined;
845
+ }
846
+ function wide_string_type() {
847
+ let t0 = lexer.lex();
848
+ if (t0 !== undefined && t0.type === Type.TKN_WSTRING) {
849
+ return t0;
850
+ }
851
+ lexer.unlex(t0);
852
+ return undefined;
853
+ }
854
+ function attr_dcl() {
855
+ let t0;
856
+ t0 = readonly_attr_spec();
857
+ if (t0 === undefined)
858
+ t0 = attr_spec();
859
+ return t0;
860
+ }
861
+ function except_dcl() {
862
+ let t0 = lexer.lex();
863
+ if (t0 === undefined || t0.type != Type.TKN_EXCEPTION) {
864
+ lexer.unlex(t0);
865
+ return undefined;
866
+ }
867
+ let t1 = identifier();
868
+ if (t1 === undefined)
869
+ throw Error(`expected identifier after '${t0.toString()}'`);
870
+ t0.text = t1.text;
871
+ expect("{");
872
+ while (true) {
873
+ let t2 = member();
874
+ if (t2 === undefined)
875
+ break;
876
+ t0.append(t2);
877
+ }
878
+ expect("}");
879
+ scoper.addType(t0.text, t0);
880
+ return t0;
881
+ }
882
+ function op_dcl() {
883
+ const t0 = op_attribute();
884
+ const t1 = op_type_spec();
885
+ if (t1 === undefined) {
886
+ lexer.unlex(t0);
887
+ return undefined;
888
+ }
889
+ const t2 = identifier();
890
+ if (t2 === undefined) {
891
+ throw Error(`expected identifier after '${t1.toString()}'`);
892
+ }
893
+ const t3 = parameter_dcls();
894
+ if (t3 === undefined) {
895
+ lexer.unlex(t2);
896
+ if (t1.child.length != 0) {
897
+ throw Error("expected parameter declaration after " + t2.toString());
898
+ }
899
+ lexer.unlex(t1);
900
+ lexer.unlex(t0);
901
+ return undefined;
902
+ }
903
+ const t4 = raises_expr();
904
+ let node = new Node(Type.SYN_OPERATION_DECLARATION);
905
+ node.append(t0);
906
+ node.append(t1);
907
+ node.append(t2);
908
+ node.append(t3);
909
+ node.append(t4);
910
+ node.append(undefined);
911
+ return node;
912
+ }
913
+ function op_attribute() {
914
+ let t0 = lexer.lex();
915
+ if (!t0)
916
+ return undefined;
917
+ if (t0.type !== Type.TKN_ONEWAY) {
918
+ lexer.unlex(t0);
919
+ return undefined;
920
+ }
921
+ return t0;
922
+ }
923
+ function op_type_spec() {
924
+ let t0 = param_type_spec();
925
+ if (t0 !== undefined)
926
+ return t0;
927
+ t0 = lexer.lex();
928
+ if (t0 !== undefined && t0.type === Type.TKN_VOID)
929
+ return t0;
930
+ lexer.unlex(t0);
931
+ return undefined;
932
+ }
933
+ function parameter_dcls() {
934
+ let t0 = lexer.lex();
935
+ if (!t0) {
936
+ return undefined;
937
+ }
938
+ if (t0.type !== Type.TKN_TEXT || t0.text !== '(') {
939
+ lexer.unlex(t0);
940
+ return undefined;
941
+ }
942
+ let declarations = new Node(Type.SYN_PARAMETER_DECLARATIONS);
943
+ while (true) {
944
+ let t1 = param_dcl();
945
+ if (t1 !== undefined)
946
+ declarations.append(t1);
947
+ let t2 = lexer.lex();
948
+ if (t2 !== undefined && t2.type === Type.TKN_TEXT && t2.text === ')') {
949
+ break;
950
+ }
951
+ if (t2 !== undefined && t2.type === Type.TKN_TEXT && t2.text === ",") {
952
+ continue;
953
+ }
954
+ if (t2 !== undefined)
955
+ throw Error("expected 'in', 'out', 'inout' or ')' to end for parameter declaration but got " + t2.toString());
956
+ else
957
+ throw Error("expected 'in', 'out', 'inout' or ')' to end for parameter declaration but end of file");
958
+ }
959
+ return declarations;
960
+ }
961
+ function param_dcl() {
962
+ let t0 = param_attribute();
963
+ if (t0 === undefined)
964
+ return undefined;
965
+ let t1 = param_type_spec();
966
+ if (t1 === undefined) {
967
+ t1 = lexer.lex();
968
+ if (t1 !== undefined)
969
+ throw Error("expected type specification but got " + t1.toString());
970
+ else
971
+ throw Error("expected type specification but found end of file");
972
+ }
973
+ let t2 = simple_declarator();
974
+ if (t2 === undefined) {
975
+ throw Error("Missing parameter name.");
976
+ }
977
+ let declaration = new Node(Type.SYN_PARAMETER_DECLARATION);
978
+ declaration.append(t0);
979
+ declaration.append(t1);
980
+ declaration.append(t2);
981
+ return declaration;
982
+ }
983
+ function param_attribute() {
984
+ let t0 = lexer.lex();
985
+ if (t0 === undefined)
986
+ return undefined;
987
+ switch (t0.type) {
988
+ case Type.TKN_IN:
989
+ case Type.TKN_OUT:
990
+ case Type.TKN_INOUT:
991
+ return t0;
992
+ }
993
+ lexer.unlex(t0);
994
+ return undefined;
995
+ }
996
+ function raises_expr() {
997
+ let t0 = lexer.lex();
998
+ if (t0 === undefined || t0.type !== Type.TKN_RAISES) {
999
+ lexer.unlex(t0);
1000
+ return undefined;
1001
+ }
1002
+ expect("(");
1003
+ let t1 = scoped_name();
1004
+ if (t1 === undefined)
1005
+ throw Error(`expected exception name after 'raises('`);
1006
+ if (t1.child[0] === undefined || t1.child[0].type !== Type.TKN_EXCEPTION)
1007
+ throw Error(`expected ${t1.toString()} to be an exception`);
1008
+ if (t1.type)
1009
+ t0.append(t1);
1010
+ while (true) {
1011
+ let t2 = lexer.lex();
1012
+ if (t2 === undefined || t2.type !== Type.TKN_TEXT || t0.text !== ",") {
1013
+ lexer.unlex(t2);
1014
+ break;
1015
+ }
1016
+ t1 = scoped_name();
1017
+ if (t1 === undefined)
1018
+ throw Error(`expected exception name after 'raises(..., '`);
1019
+ if (t1.child[0] === undefined || t1.child[0].type !== Type.TKN_EXCEPTION)
1020
+ throw Error(`expected ${t1.toString()} to be an exception`);
1021
+ t0.append(t1);
1022
+ }
1023
+ expect(")");
1024
+ return t0;
1025
+ }
1026
+ function param_type_spec() {
1027
+ let t0;
1028
+ t0 = base_type_spec();
1029
+ if (t0 !== undefined)
1030
+ return t0;
1031
+ t0 = template_type_spec();
1032
+ if (t0 !== undefined)
1033
+ return t0;
1034
+ t0 = scoped_name();
1035
+ if (t0)
1036
+ return t0;
1037
+ return undefined;
1038
+ }
1039
+ function readonly_attr_spec() {
1040
+ let t0 = lexer.lex();
1041
+ if (t0 !== undefined && t0.type === Type.TKN_READONLY) {
1042
+ let t1 = lexer.lex();
1043
+ if (t1 !== undefined && t1.type === Type.TKN_ATTRIBUTE) {
1044
+ let t2 = param_type_spec();
1045
+ if (t2 === undefined)
1046
+ throw Error("expected type specifier after 'readonly attribute'");
1047
+ let t3 = readonly_attr_declarator();
1048
+ if (t3 === undefined)
1049
+ throw Error("expected declarator for 'readonly attribute'");
1050
+ t1.append(t0);
1051
+ t1.append(t2);
1052
+ t1.append(t3);
1053
+ return t1;
1054
+ }
1055
+ lexer.unlex(t1);
1056
+ }
1057
+ lexer.unlex(t0);
1058
+ return undefined;
1059
+ }
1060
+ function readonly_attr_declarator() {
1061
+ let t0 = simple_declarator();
1062
+ if (t0 === undefined)
1063
+ return undefined;
1064
+ let node = new Node(Type.SYN_DECLARATORS);
1065
+ while (true) {
1066
+ node.append(t0);
1067
+ let t1 = lexer.lex();
1068
+ if (t1 === undefined || t1.type !== Type.TKN_TEXT || t1.text !== ",") {
1069
+ lexer.unlex(t1);
1070
+ return node;
1071
+ }
1072
+ t0 = simple_declarator();
1073
+ if (t0 === undefined)
1074
+ throw Error("expected another declarator after ','");
1075
+ }
1076
+ }
1077
+ function attr_spec() {
1078
+ let t0 = lexer.lex();
1079
+ if (t0 !== undefined && t0.type === Type.TKN_ATTRIBUTE) {
1080
+ let t1 = param_type_spec();
1081
+ if (t1 === undefined)
1082
+ throw Error("expected type specifier after 'attribute'");
1083
+ let t2 = attr_declarator();
1084
+ if (t2 === undefined)
1085
+ throw Error("expected declarator for 'attribute'");
1086
+ t0.append(undefined);
1087
+ t0.append(t1);
1088
+ t0.append(t2);
1089
+ return t0;
1090
+ }
1091
+ lexer.unlex(t0);
1092
+ return undefined;
1093
+ }
1094
+ function attr_declarator() {
1095
+ let t0 = simple_declarator();
1096
+ if (t0 === undefined)
1097
+ return undefined;
1098
+ let node = new Node(Type.SYN_DECLARATORS);
1099
+ while (true) {
1100
+ node.append(t0);
1101
+ let t1 = lexer.lex();
1102
+ if (t1 === undefined || t1.type !== Type.TKN_TEXT || t1.text !== ",") {
1103
+ lexer.unlex(t1);
1104
+ return node;
1105
+ }
1106
+ t0 = simple_declarator();
1107
+ if (t0 === undefined)
1108
+ throw Error("expected another declarator after ','");
1109
+ }
1110
+ }
1111
+ function identifier() {
1112
+ let t0 = lexer.lex();
1113
+ if (t0 !== undefined && t0.type === Type.TKN_IDENTIFIER)
1114
+ return t0;
1115
+ lexer.unlex(t0);
1116
+ return undefined;
1117
+ }
1118
+ function expect(text, customMessage) {
1119
+ let t0 = lexer.lex();
1120
+ let errorMessage;
1121
+ if (customMessage === undefined)
1122
+ errorMessage = `expected '${text}' but got '${t0?.toString()}'`;
1123
+ else
1124
+ errorMessage = customMessage;
1125
+ if (t0 === undefined)
1126
+ throw Error(errorMessage + " but found end of file");
1127
+ if (t0.type !== Type.TKN_TEXT || t0.text !== text) {
1128
+ throw Error(errorMessage);
1129
+ }
1130
+ }
1131
+ class Scope {
1132
+ constructor(node) {
1133
+ this.node = node;
1134
+ this.types = new Map();
1135
+ this.modules = new Map();
1136
+ }
1137
+ addType(name, type) {
1138
+ if (this.types.has(name))
1139
+ throw Error("duplicate typename '" + name + "'");
1140
+ this.types.set(name, type);
1141
+ type.typeParent = this.node;
1142
+ }
1143
+ getType(name) {
1144
+ return this.types.get(name);
1145
+ }
1146
+ }
1147
+ class ScopeManager {
1148
+ constructor() {
1149
+ this.stack = new Array();
1150
+ this.stack.push(new Scope(undefined));
1151
+ }
1152
+ getGlobalScope() {
1153
+ return this.stack[0];
1154
+ }
1155
+ getCurrentScope() {
1156
+ return this.stack[this.stack.length - 1];
1157
+ }
1158
+ addType(name, type) {
1159
+ this.getCurrentScope().addType(name, type);
1160
+ }
1161
+ getType(name) {
1162
+ for (let i = this.stack.length - 1; i >= 0; --i) {
1163
+ let type = this.stack[i].getType(name);
1164
+ if (type !== undefined)
1165
+ return type;
1166
+ }
1167
+ return undefined;
1168
+ }
1169
+ enterModule(node) {
1170
+ this.getCurrentScope().addType(node.text, node);
1171
+ this.stack.push(new Scope(node));
1172
+ }
1173
+ leaveModule(node) {
1174
+ this.stack.pop();
1175
+ }
1176
+ }
1177
+ function resolve_module(identifierToken, module) {
1178
+ const paamayimNekudotayim = lexer.lex();
1179
+ if (paamayimNekudotayim === undefined || paamayimNekudotayim.type !== Type.TKN_COLON_COLON)
1180
+ throw Error(`Expected :: after module identifier '${identifierToken.text}'`);
1181
+ const identifier = lexer.lex();
1182
+ if (identifier === undefined || identifier.type !== Type.TKN_IDENTIFIER)
1183
+ throw Error(`Expected identifier after ::'`);
1184
+ for (let child of module.child) {
1185
+ switch (child?.type) {
1186
+ case Type.TKN_MODULE:
1187
+ if (child.text === identifier.text) {
1188
+ identifierToken.append(child);
1189
+ resolve_module(identifierToken, child);
1190
+ return;
1191
+ }
1192
+ break;
1193
+ case Type.TKN_NATIVE:
1194
+ case Type.TKN_VALUETYPE:
1195
+ if (child.text === identifier.text) {
1196
+ identifierToken.append(child);
1197
+ return;
1198
+ }
1199
+ break;
1200
+ case Type.SYN_INTERFACE:
1201
+ if (child.child[0].child[1].text === identifier.text) {
1202
+ identifierToken.append(child);
1203
+ return;
1204
+ }
1205
+ break;
1206
+ }
1207
+ }
1208
+ throw Error(`failed to lookup ${identifier.text}`);
1209
+ }
1210
+ //# sourceMappingURL=idl-parser.js.map