corba.js 0.2.0 → 0.3.0

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