corba.js 0.0.11 → 0.1.2

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 (144) hide show
  1. package/LICENSE +70 -83
  2. package/README.IDL.txt +285 -0
  3. package/README.md +88 -48
  4. package/bin/corba-idl +15 -2
  5. package/lib/idl/idl.cjs +2732 -0
  6. package/lib/idl/idl.cjs.map +1 -0
  7. package/lib/idl/src/idl/idl-lexer.d.ts +19 -0
  8. package/lib/idl/src/idl/idl-node.d.ts +101 -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/util.d.ts +25 -0
  12. package/lib/idl/src/idl/write-interface.d.ts +2 -0
  13. package/lib/idl/src/idl/write-skeleton.d.ts +2 -0
  14. package/lib/idl/src/idl/write-stub.d.ts +2 -0
  15. package/lib/idl/src/idl/write-value.d.ts +2 -0
  16. package/lib/idl/src/idl/write-valueimpl.d.ts +2 -0
  17. package/lib/idl/src/idl/write-valuetype.d.ts +2 -0
  18. package/lib/idl/src/index.d.ts +5 -0
  19. package/lib/idl/src/net/browser.d.ts +7 -0
  20. package/lib/idl/src/net/index.d.ts +3 -0
  21. package/lib/idl/src/net/tcp.d.ts +11 -0
  22. package/lib/idl/src/net/tls.d.ts +24 -0
  23. package/lib/idl/src/net/ws.d.ts +42 -0
  24. package/lib/idl/src/orb/asn1.d.ts +48 -0
  25. package/lib/idl/src/orb/connection.d.ts +24 -0
  26. package/lib/idl/src/orb/giop.d.ts +273 -0
  27. package/lib/idl/src/orb/index.d.ts +3 -0
  28. package/lib/idl/src/orb/ior.d.ts +89 -0
  29. package/lib/idl/src/orb/orb.d.ts +143 -0
  30. package/lib/idl/src/orb/protocol.d.ts +6 -0
  31. package/lib/idl/src/orb/uint8map.d.ts +14 -0
  32. package/lib/idl/src/orb/url.d.ts +55 -0
  33. package/lib/idl/test/access.spec.d.ts +1 -0
  34. package/lib/idl/test/attribute.spec.d.ts +1 -0
  35. package/lib/idl/test/basics.spec.d.ts +1 -0
  36. package/lib/idl/test/disconnect.spec.d.ts +1 -0
  37. package/lib/idl/test/eventtarget.spec.d.ts +1 -0
  38. package/lib/idl/test/fake.d.ts +31 -0
  39. package/lib/idl/test/giop.spec.d.ts +1 -0
  40. package/lib/idl/test/idl/idl.spec.d.ts +1 -0
  41. package/lib/idl/test/idl_module.spec.d.ts +1 -0
  42. package/lib/idl/test/initialreferences.spec.d.ts +1 -0
  43. package/lib/idl/test/net/tls.spec.d.ts +1 -0
  44. package/lib/idl/test/net/ws.spec.d.ts +1 -0
  45. package/lib/idl/test/net/wss.spec.d.ts +1 -0
  46. package/lib/idl/test/object_by_reference.spec.d.ts +1 -0
  47. package/lib/idl/test/orb/asn1.spec.d.ts +1 -0
  48. package/lib/idl/test/orb/url.spec.d.ts +1 -0
  49. package/lib/idl/test/stub.spec.d.ts +1 -0
  50. package/lib/idl/test/util.d.ts +5 -0
  51. package/lib/idl/test/valuetype.spec.d.ts +1 -0
  52. package/lib/{idl → src/idl}/idl-lexer.d.ts +0 -0
  53. package/lib/src/idl/idl-lexer.js +234 -0
  54. package/lib/src/idl/idl-lexer.js.map +1 -0
  55. package/lib/{idl → src/idl}/idl-node.d.ts +13 -10
  56. package/lib/{idl → src/idl}/idl-node.js +30 -49
  57. package/lib/src/idl/idl-node.js.map +1 -0
  58. package/lib/{idl → src/idl}/idl-parser.d.ts +0 -0
  59. package/lib/{idl → src/idl}/idl-parser.js +367 -291
  60. package/lib/src/idl/idl-parser.js.map +1 -0
  61. package/lib/{idl → src/idl}/idl.d.ts +0 -0
  62. package/lib/src/idl/idl.js +180 -0
  63. package/lib/src/idl/idl.js.map +1 -0
  64. package/lib/src/idl/util.d.ts +25 -0
  65. package/lib/src/idl/util.js +239 -0
  66. package/lib/src/idl/util.js.map +1 -0
  67. package/lib/src/idl/write-interface.d.ts +2 -0
  68. package/lib/src/idl/write-interface.js +111 -0
  69. package/lib/src/idl/write-interface.js.map +1 -0
  70. package/lib/src/idl/write-skeleton.d.ts +2 -0
  71. package/lib/src/idl/write-skeleton.js +116 -0
  72. package/lib/src/idl/write-skeleton.js.map +1 -0
  73. package/lib/src/idl/write-stub.d.ts +2 -0
  74. package/lib/src/idl/write-stub.js +116 -0
  75. package/lib/src/idl/write-stub.js.map +1 -0
  76. package/lib/src/idl/write-value.d.ts +2 -0
  77. package/lib/src/idl/write-value.js +205 -0
  78. package/lib/src/idl/write-value.js.map +1 -0
  79. package/lib/src/idl/write-valueimpl.d.ts +2 -0
  80. package/lib/src/idl/write-valueimpl.js +158 -0
  81. package/lib/src/idl/write-valueimpl.js.map +1 -0
  82. package/lib/src/idl/write-valuetype.d.ts +2 -0
  83. package/lib/src/idl/write-valuetype.js +98 -0
  84. package/lib/src/idl/write-valuetype.js.map +1 -0
  85. package/lib/src/index.d.ts +5 -0
  86. package/lib/src/index.js +6 -0
  87. package/lib/src/index.js.map +1 -0
  88. package/lib/src/net/browser.d.ts +7 -0
  89. package/lib/src/net/browser.js +54 -0
  90. package/lib/src/net/browser.js.map +1 -0
  91. package/lib/src/net/index.d.ts +3 -0
  92. package/lib/src/net/index.js +4 -0
  93. package/lib/src/net/index.js.map +1 -0
  94. package/lib/src/net/tcp.d.ts +11 -0
  95. package/lib/src/net/tcp.js +66 -0
  96. package/lib/src/net/tcp.js.map +1 -0
  97. package/lib/src/net/tls.d.ts +24 -0
  98. package/lib/src/net/tls.js +69 -0
  99. package/lib/src/net/tls.js.map +1 -0
  100. package/lib/src/net/ws.d.ts +42 -0
  101. package/lib/src/net/ws.js +158 -0
  102. package/lib/src/net/ws.js.map +1 -0
  103. package/lib/src/orb/asn1.d.ts +48 -0
  104. package/lib/src/orb/asn1.js +60 -0
  105. package/lib/src/orb/asn1.js.map +1 -0
  106. package/lib/src/orb/connection.d.ts +24 -0
  107. package/lib/src/orb/connection.js +19 -0
  108. package/lib/src/orb/connection.js.map +1 -0
  109. package/lib/src/orb/giop.d.ts +273 -0
  110. package/lib/src/orb/giop.js +1163 -0
  111. package/lib/src/orb/giop.js.map +1 -0
  112. package/lib/src/orb/index.d.ts +3 -0
  113. package/lib/src/orb/index.js +4 -0
  114. package/lib/src/orb/index.js.map +1 -0
  115. package/lib/src/orb/ior.d.ts +89 -0
  116. package/lib/src/orb/ior.js +110 -0
  117. package/lib/src/orb/ior.js.map +1 -0
  118. package/lib/src/orb/orb.d.ts +143 -0
  119. package/lib/src/orb/orb.js +693 -0
  120. package/lib/src/orb/orb.js.map +1 -0
  121. package/lib/src/orb/protocol.d.ts +6 -0
  122. package/lib/src/orb/protocol.js +2 -0
  123. package/lib/src/orb/protocol.js.map +1 -0
  124. package/lib/src/orb/uint8map.d.ts +14 -0
  125. package/lib/src/orb/uint8map.js +48 -0
  126. package/lib/src/orb/uint8map.js.map +1 -0
  127. package/lib/src/orb/url.d.ts +55 -0
  128. package/lib/src/orb/url.js +252 -0
  129. package/lib/src/orb/url.js.map +1 -0
  130. package/package.json +50 -26
  131. package/karma.conf.js +0 -37
  132. package/lib/idl/idl-lexer.js +0 -257
  133. package/lib/idl/idl-lexer.js.map +0 -1
  134. package/lib/idl/idl-node.js.map +0 -1
  135. package/lib/idl/idl-parser.js.map +0 -1
  136. package/lib/idl/idl.js +0 -937
  137. package/lib/idl/idl.js.map +0 -1
  138. package/lib/orb/orb-nodejs.d.ts +0 -7
  139. package/lib/orb/orb-nodejs.js +0 -110
  140. package/lib/orb/orb-nodejs.js.map +0 -1
  141. package/lib/orb/orb.d.ts +0 -62
  142. package/lib/orb/orb.js +0 -514
  143. package/lib/orb/orb.js.map +0 -1
  144. package/tsconfig.json +0 -25
@@ -1,103 +1,27 @@
1
- "use strict";
2
- /*
3
- * corba.js Object Request Broker (ORB) and Interface Definition Language (IDL) compiler
4
- * Copyright (C) 2018, 20202 Mark-André Hopf <mhopf@mark13.org>
5
- *
6
- * This program is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
- */
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.specification = void 0;
21
- const idl_node_1 = require("./idl-node");
1
+ import { Type, Node } from "./idl-node.js";
22
2
  let lexer;
23
- class Scope {
24
- constructor(node) {
25
- this.node = node;
26
- this.types = new Map();
27
- this.modules = new Map();
28
- }
29
- addType(name, type) {
30
- if (this.types.has(name))
31
- throw Error("duplicate typename '" + name + "'");
32
- this.types.set(name, type);
33
- type.typeParent = this.node;
34
- }
35
- getType(name) {
36
- return this.types.get(name);
37
- }
38
- }
39
- class ScopeManager {
40
- constructor() {
41
- this.stack = new Array();
42
- this.stack.push(new Scope(undefined));
43
- }
44
- getGlobalScope() {
45
- return this.stack[0];
46
- }
47
- getCurrentScope() {
48
- return this.stack[this.stack.length - 1];
49
- }
50
- addType(name, type) {
51
- this.getCurrentScope().addType(name, type);
52
- }
53
- getType(name) {
54
- for (let i = this.stack.length - 1; i >= 0; --i) {
55
- let type = this.stack[i].getType(name);
56
- if (type !== undefined)
57
- return type;
58
- }
59
- return undefined;
60
- }
61
- enterModule(node) {
62
- this.getCurrentScope().addType(node.text, node);
63
- this.stack.push(new Scope(node));
64
- }
65
- leaveModule(node) {
66
- this.stack.pop();
67
- }
68
- }
69
3
  let scoper;
70
- function expect(text, customMessage) {
71
- let t0 = lexer.lex();
72
- let errorMessage;
73
- if (customMessage === undefined)
74
- errorMessage = `expected '${text}' but got ${t0 === null || t0 === void 0 ? void 0 : t0.toString()}`;
75
- else
76
- errorMessage = customMessage;
77
- if (t0 === undefined)
78
- throw Error(errorMessage + " but found end of file");
79
- if (t0.type !== idl_node_1.Type.TKN_TEXT || t0.text !== text) {
80
- throw Error(errorMessage); // "expected '"+text+"' but found "+t0.toString())
81
- }
82
- }
83
- // 1
84
- function specification(aLexer) {
4
+ export function specification(aLexer) {
85
5
  lexer = aLexer;
86
6
  scoper = new ScopeManager();
87
- let node = new idl_node_1.Node(idl_node_1.Type.SYN_SPECIFICATION);
7
+ let node = new Node(Type.SYN_SPECIFICATION);
88
8
  while (true) {
89
9
  let t0 = definition();
90
10
  if (t0 === undefined)
91
11
  break;
92
12
  node.append(t0);
93
13
  }
14
+ const tail = lexer.lex();
15
+ if (tail !== undefined) {
16
+ throw Error(`Unparsed token '${tail.toString()}' at end of specification.`);
17
+ }
94
18
  return node;
95
19
  }
96
- exports.specification = specification;
97
- // 2
98
20
  function definition() {
99
21
  let t0;
100
22
  t0 = type_dcl();
23
+ if (t0 === undefined)
24
+ t0 = except_dcl();
101
25
  if (t0 === undefined)
102
26
  t0 = _interface();
103
27
  if (t0 === undefined)
@@ -109,13 +33,12 @@ function definition() {
109
33
  }
110
34
  return t0;
111
35
  }
112
- // 3
113
36
  function _module() {
114
37
  let t0 = lexer.lex();
115
- if (t0 !== undefined && t0.type === idl_node_1.Type.TKN_MODULE) {
38
+ if (t0 !== undefined && t0.type === Type.TKN_MODULE) {
116
39
  let t1 = identifier();
117
40
  if (t1 === undefined)
118
- throw Error("exepted identifer after 'module'");
41
+ throw Error("expected identifier after 'module'");
119
42
  t0.text = t1.text;
120
43
  expect("{");
121
44
  scoper.enterModule(t0);
@@ -123,7 +46,7 @@ function _module() {
123
46
  let t2 = definition();
124
47
  if (t2 === undefined)
125
48
  break;
126
- if (t2.type == idl_node_1.Type.TKN_NATIVE)
49
+ if (t2.type == Type.TKN_NATIVE)
127
50
  throw Error("'native' can not be used within 'module'");
128
51
  t0.append(t2);
129
52
  }
@@ -134,11 +57,9 @@ function _module() {
134
57
  lexer.unlex(t0);
135
58
  return undefined;
136
59
  }
137
- // 4
138
60
  function _interface() {
139
61
  return interface_dcl();
140
62
  }
141
- // 5
142
63
  function interface_dcl() {
143
64
  let t0 = interface_header();
144
65
  if (!t0) {
@@ -151,27 +72,26 @@ function interface_dcl() {
151
72
  let t1 = lexer.lex();
152
73
  if (t1 === undefined)
153
74
  throw Error("expected { after interface header but got end of file");
154
- if (t1.type !== idl_node_1.Type.TKN_TEXT && t1.text != '{')
155
- throw Error("expected { after interface header but got " + t0.toString());
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);
156
80
  let t2 = interface_body();
81
+ node.append(t2);
157
82
  let t3 = lexer.lex();
158
83
  if (!t3)
159
84
  throw Error("unexpected end of file");
160
- if (t3.type !== idl_node_1.Type.TKN_TEXT && t3.text != '}')
161
- throw Error("expected } after interface header but got " + t3.toString());
162
- let node = new idl_node_1.Node(idl_node_1.Type.SYN_INTERFACE, t0.child[1].text);
163
- node.append(t0);
164
- node.append(t2);
165
- scoper.addType(t0.child[1].text, node);
85
+ if (t3.type !== Type.TKN_TEXT && t3.text != '}')
86
+ throw Error(`expected } after interface body but got '${t3}'`);
166
87
  return node;
167
88
  }
168
- // 7
169
89
  function interface_header() {
170
90
  let t0 = lexer.lex();
171
91
  if (t0 === undefined)
172
92
  return undefined;
173
93
  let t1;
174
- if (t0.type !== idl_node_1.Type.TKN_ABSTRACT && t0.type !== idl_node_1.Type.TKN_LOCAL) {
94
+ if (t0.type !== Type.TKN_ABSTRACT && t0.type !== Type.TKN_LOCAL) {
175
95
  t1 = t0;
176
96
  t0 = undefined;
177
97
  }
@@ -182,7 +102,7 @@ function interface_header() {
182
102
  lexer.unlex(t0);
183
103
  return undefined;
184
104
  }
185
- if (t1.type !== idl_node_1.Type.TKN_INTERFACE) {
105
+ if (t1.type !== Type.TKN_INTERFACE) {
186
106
  lexer.unlex(t1);
187
107
  lexer.unlex(t0);
188
108
  return undefined;
@@ -190,16 +110,14 @@ function interface_header() {
190
110
  let t2 = identifier();
191
111
  if (t2 === undefined)
192
112
  throw Error("expected identifier after 'interface'");
193
- // let t3 = interface_inheritance_spec()
194
- let header = new idl_node_1.Node(idl_node_1.Type.SYN_INTERFACE_HEADER);
113
+ let header = new Node(Type.SYN_INTERFACE_HEADER);
195
114
  header.append(t0);
196
115
  header.append(t2);
197
116
  header.append(undefined);
198
117
  return header;
199
118
  }
200
- // 8
201
119
  function interface_body() {
202
- let body = new idl_node_1.Node(idl_node_1.Type.SYN_INTERFACE_BODY);
120
+ let body = new Node(Type.SYN_INTERFACE_BODY);
203
121
  while (true) {
204
122
  let t0 = _export();
205
123
  if (t0 === undefined)
@@ -207,7 +125,6 @@ function interface_body() {
207
125
  body.append(t0);
208
126
  }
209
127
  }
210
- // 9
211
128
  function _export() {
212
129
  let t0 = attr_dcl();
213
130
  if (t0 === undefined)
@@ -217,13 +134,12 @@ function _export() {
217
134
  expect(';');
218
135
  return t0;
219
136
  }
220
- // 12
221
137
  function scoped_name() {
222
138
  let globalNamespaceToken = undefined;
223
139
  let identifierToken = lexer.lex();
224
140
  if (identifierToken === undefined)
225
141
  return undefined;
226
- if (identifierToken.type === idl_node_1.Type.TKN_COLON_COLON) {
142
+ if (identifierToken.type === Type.TKN_COLON_COLON) {
227
143
  globalNamespaceToken = identifierToken;
228
144
  identifierToken = lexer.lex();
229
145
  if (identifierToken === undefined) {
@@ -231,7 +147,7 @@ function scoped_name() {
231
147
  return undefined;
232
148
  }
233
149
  }
234
- if (identifierToken.type !== idl_node_1.Type.TKN_IDENTIFIER) {
150
+ if (identifierToken.type !== Type.TKN_IDENTIFIER) {
235
151
  lexer.unlex(identifierToken);
236
152
  lexer.unlex(globalNamespaceToken);
237
153
  return undefined;
@@ -248,10 +164,10 @@ function scoped_name() {
248
164
  throw Error(`unknown type ${identifierToken}`);
249
165
  }
250
166
  identifierToken.append(type);
251
- if (type.type === idl_node_1.Type.TKN_MODULE) {
167
+ if (type.type === Type.TKN_MODULE) {
252
168
  resolve_module(identifierToken, type);
253
169
  }
254
- if (type.type === idl_node_1.Type.TKN_NATIVE &&
170
+ if (type.type === Type.TKN_NATIVE &&
255
171
  type.text.length > 4 &&
256
172
  type.text.substring(type.text.length - 4) === "_ptr" &&
257
173
  type.typeParent === undefined) {
@@ -259,40 +175,6 @@ function scoped_name() {
259
175
  }
260
176
  return identifierToken;
261
177
  }
262
- function resolve_module(identifierToken, module) {
263
- let paamayimNekudotayim = lexer.lex();
264
- if (paamayimNekudotayim === undefined || paamayimNekudotayim.type !== idl_node_1.Type.TKN_COLON_COLON)
265
- throw Error(`Expected :: after module identifier '${identifierToken.text}'`);
266
- let identifier = lexer.lex();
267
- if (identifier === undefined || identifier.type !== idl_node_1.Type.TKN_IDENTIFIER)
268
- throw Error(`Expected identifier after ::'`);
269
- for (let child of module.child) {
270
- switch (child === null || child === void 0 ? void 0 : child.type) {
271
- case idl_node_1.Type.TKN_MODULE:
272
- if (child.text === identifier.text) {
273
- identifierToken.append(child);
274
- resolve_module(identifierToken, child);
275
- return;
276
- }
277
- break;
278
- case idl_node_1.Type.TKN_NATIVE:
279
- case idl_node_1.Type.TKN_VALUETYPE:
280
- if (child.text === identifier.text) {
281
- identifierToken.append(child);
282
- return;
283
- }
284
- break;
285
- case idl_node_1.Type.SYN_INTERFACE:
286
- if (child.child[0].child[1].text === identifier.text) {
287
- identifierToken.append(child);
288
- return;
289
- }
290
- break;
291
- }
292
- }
293
- throw Error(`failed to lookup ${identifier.text}`);
294
- }
295
- // 13
296
178
  function value() {
297
179
  let t0;
298
180
  t0 = value_dcl();
@@ -309,26 +191,22 @@ function value() {
309
191
  return t0;
310
192
  return undefined;
311
193
  }
312
- // 14
313
194
  function value_forward_dcl() {
314
195
  return undefined;
315
196
  }
316
- // 15
317
197
  function value_box_dcl() {
318
198
  return undefined;
319
199
  }
320
- // 16
321
200
  function value_abs_dcl() {
322
201
  return undefined;
323
202
  }
324
- // 17
325
203
  function value_dcl() {
326
204
  let header = value_header();
327
205
  if (header === undefined) {
328
206
  return undefined;
329
207
  }
330
208
  expect('{');
331
- let node = new idl_node_1.Node(idl_node_1.Type.TKN_VALUETYPE);
209
+ let node = new Node(Type.TKN_VALUETYPE);
332
210
  node.append(header);
333
211
  let identifier = header.child[1].text;
334
212
  node.text = identifier;
@@ -339,28 +217,26 @@ function value_dcl() {
339
217
  break;
340
218
  node.append(t1);
341
219
  }
342
- expect('}'); // , "valuetype attributes must be prefixed with either 'public' or 'private'")
220
+ expect('}');
343
221
  return node;
344
222
  }
345
- // 18
346
223
  function value_header() {
347
224
  let t0 = lexer.lex();
348
225
  if (t0 !== undefined) {
349
226
  let t1;
350
- if (t0.type === idl_node_1.Type.TKN_CUSTOM) {
227
+ if (t0.type === Type.TKN_CUSTOM) {
351
228
  throw Error("corba.js currently does not support custom valuetypes");
352
- // t1 = lexer.lex()
353
229
  }
354
230
  else {
355
231
  t1 = t0;
356
232
  t0 = undefined;
357
233
  }
358
- if (t1 !== undefined && t1.type === idl_node_1.Type.TKN_VALUETYPE) {
234
+ if (t1 !== undefined && t1.type === Type.TKN_VALUETYPE) {
359
235
  let t2 = identifier();
360
236
  if (t2 === undefined)
361
237
  throw Error("expected an identifier after valuetype");
362
238
  let t3 = value_inheritance_spec();
363
- let node = new idl_node_1.Node(idl_node_1.Type.SYN_VALUE_HEADER);
239
+ let node = new Node(Type.SYN_VALUE_HEADER);
364
240
  node.append(t0);
365
241
  node.append(t2);
366
242
  node.append(t3);
@@ -371,21 +247,20 @@ function value_header() {
371
247
  lexer.unlex(t0);
372
248
  return undefined;
373
249
  }
374
- // 19
375
250
  function value_inheritance_spec() {
376
251
  let t0 = lexer.lex();
377
- if (t0 === undefined || t0.type !== idl_node_1.Type.TKN_TEXT || t0.text !== ":") {
252
+ if (t0 === undefined || t0.type !== Type.TKN_TEXT || t0.text !== ":") {
378
253
  lexer.unlex(t0);
379
254
  return undefined;
380
255
  }
381
256
  let t1 = lexer.lex();
382
- if (t1 !== undefined && t1.type !== idl_node_1.Type.TKN_TRUNCATABLE) {
257
+ if (t1 !== undefined && t1.type !== Type.TKN_TRUNCATABLE) {
383
258
  lexer.unlex(t1);
384
259
  t1 = undefined;
385
260
  }
386
261
  if (t1 !== undefined)
387
262
  throw Error("'truncatable' is not supported");
388
- let node = new idl_node_1.Node(idl_node_1.Type.SYN_VALUE_INHERITANCE_SPEC);
263
+ let node = new Node(Type.SYN_VALUE_INHERITANCE_SPEC);
389
264
  node.append(t1);
390
265
  while (true) {
391
266
  let t2 = value_name();
@@ -396,7 +271,7 @@ function value_inheritance_spec() {
396
271
  let t3 = lexer.lex();
397
272
  if (t3 === undefined)
398
273
  throw Error("unexpected end of file");
399
- if (t3.type !== idl_node_1.Type.TKN_TEXT || t3.text !== ",") {
274
+ if (t3.type !== Type.TKN_TEXT || t3.text !== ",") {
400
275
  lexer.unlex(t3);
401
276
  break;
402
277
  }
@@ -406,27 +281,20 @@ function value_inheritance_spec() {
406
281
  }
407
282
  return node;
408
283
  }
409
- // 20
410
284
  function value_name() {
411
285
  return scoped_name();
412
286
  }
413
- // 21
414
287
  function value_element() {
415
288
  let t0 = _export();
416
289
  if (t0 === undefined)
417
290
  t0 = state_member();
418
- /*
419
- if (t0 === undefined)
420
- t0 = init_dcl()
421
- */
422
291
  return t0;
423
292
  }
424
- // 22
425
293
  function state_member() {
426
294
  let t0 = lexer.lex();
427
295
  if (t0 === undefined)
428
296
  return undefined;
429
- if (t0.type !== idl_node_1.Type.TKN_PUBLIC && t0.type !== idl_node_1.Type.TKN_PRIVATE) {
297
+ if (t0.type !== Type.TKN_PUBLIC && t0.type !== Type.TKN_PRIVATE) {
430
298
  lexer.unlex(t0);
431
299
  return undefined;
432
300
  }
@@ -440,16 +308,36 @@ function state_member() {
440
308
  throw Error("expected declarators");
441
309
  }
442
310
  expect(";");
443
- let node = new idl_node_1.Node(idl_node_1.Type.SYN_STATE_MEMBER);
311
+ let node = new Node(Type.SYN_STATE_MEMBER);
444
312
  node.append(t0);
445
313
  node.append(t1);
446
314
  node.append(t2);
447
315
  return node;
448
316
  }
449
- // 42
450
317
  function type_dcl() {
451
318
  let t0 = lexer.lex();
452
- if (t0 !== undefined && t0.type === idl_node_1.Type.TKN_NATIVE) {
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 = enum_type();
337
+ if (t0 !== undefined)
338
+ return t0;
339
+ t0 = lexer.lex();
340
+ if (t0 !== undefined && t0.type === Type.TKN_NATIVE) {
453
341
  let t1 = simple_declarator();
454
342
  if (t1 === undefined) {
455
343
  throw Error("expected simple declarator after 'native'");
@@ -462,17 +350,26 @@ function type_dcl() {
462
350
  lexer.unlex(t0);
463
351
  return undefined;
464
352
  }
465
- // 44
353
+ function type_declarator() {
354
+ const t0 = type_spec();
355
+ if (t0 === undefined)
356
+ return undefined;
357
+ const t1 = declarators();
358
+ if (t1 == undefined) {
359
+ throw Error("expected at least one declarator");
360
+ }
361
+ const n = new Node(Type.SYN_TYPE_DECLARATOR);
362
+ n.append(t0);
363
+ n.append(t1);
364
+ return n;
365
+ }
466
366
  function type_spec() {
467
367
  let t0;
468
368
  t0 = simple_type_spec();
469
- /*
470
- if (t0 === undefined)
471
- t0 = constr_type_spec()
472
- */
369
+ if (t0 === undefined)
370
+ t0 = constr_type_spec();
473
371
  return t0;
474
372
  }
475
- // 45
476
373
  function simple_type_spec() {
477
374
  let t0;
478
375
  t0 = base_type_spec();
@@ -482,7 +379,6 @@ function simple_type_spec() {
482
379
  t0 = scoped_name();
483
380
  return t0;
484
381
  }
485
- // 46
486
382
  function base_type_spec() {
487
383
  let t0;
488
384
  t0 = floating_pt_type();
@@ -508,7 +404,6 @@ function base_type_spec() {
508
404
  return t0;
509
405
  return undefined;
510
406
  }
511
- // 47
512
407
  function template_type_spec() {
513
408
  let t0;
514
409
  t0 = sequence_type();
@@ -520,23 +415,23 @@ function template_type_spec() {
520
415
  t0 = wide_string_type();
521
416
  if (t0 !== undefined)
522
417
  return t0;
523
- /*
524
- t0 = fixed_pt_type()
525
- if (t0 !== undefined)
526
- return t0
527
- */
528
418
  return undefined;
529
419
  }
530
- // 49
420
+ function constr_type_spec() {
421
+ let t0 = struct_type();
422
+ if (t0 === undefined)
423
+ t0 = enum_type();
424
+ return t0;
425
+ }
531
426
  function declarators() {
532
427
  let t0 = declarator();
533
428
  if (t0 === undefined)
534
429
  return undefined;
535
- let node = new idl_node_1.Node(idl_node_1.Type.SYN_DECLARATORS);
430
+ let node = new Node(Type.SYN_DECLARATORS);
536
431
  while (true) {
537
432
  node.append(t0);
538
433
  let t1 = lexer.lex();
539
- if (t1 === undefined || t1.type !== idl_node_1.Type.TKN_TEXT || t1.text !== ",") {
434
+ if (t1 === undefined || t1.type !== Type.TKN_TEXT || t1.text !== ",") {
540
435
  lexer.unlex(t1);
541
436
  break;
542
437
  }
@@ -546,33 +441,26 @@ function declarators() {
546
441
  }
547
442
  return node;
548
443
  }
549
- // 50
550
444
  function declarator() {
551
445
  let t0;
552
446
  t0 = simple_declarator();
553
- /*
554
- if (t0 === undefined)
555
- t0 = complex_declarator()
556
- */
557
447
  return t0;
558
448
  }
559
- // 51
560
449
  function simple_declarator() {
561
450
  return identifier();
562
451
  }
563
- // 53
564
452
  function floating_pt_type() {
565
453
  let t0 = lexer.lex();
566
454
  if (t0 === undefined)
567
455
  return undefined;
568
- if (t0.type === idl_node_1.Type.TKN_FLOAT)
456
+ if (t0.type === Type.TKN_FLOAT)
569
457
  return t0;
570
- if (t0.type === idl_node_1.Type.TKN_DOUBLE)
458
+ if (t0.type === Type.TKN_DOUBLE)
571
459
  return t0;
572
- if (t0.type === idl_node_1.Type.TKN_LONG) {
460
+ if (t0.type === Type.TKN_LONG) {
573
461
  let t1 = lexer.lex();
574
- if (t1 !== undefined && t1.type === idl_node_1.Type.TKN_DOUBLE) {
575
- t1.type = idl_node_1.Type.SYN_LONG_DOUBLE;
462
+ if (t1 !== undefined && t1.type === Type.TKN_DOUBLE) {
463
+ t1.type = Type.SYN_LONG_DOUBLE;
576
464
  return t1;
577
465
  }
578
466
  lexer.unlex(t1);
@@ -580,7 +468,6 @@ function floating_pt_type() {
580
468
  lexer.unlex(t0);
581
469
  return undefined;
582
470
  }
583
- // 54
584
471
  function integer_type() {
585
472
  let t0;
586
473
  t0 = signed_int();
@@ -590,9 +477,13 @@ function integer_type() {
590
477
  if (t0 !== undefined) {
591
478
  return t0;
592
479
  }
480
+ t0 = lexer.lex();
481
+ if (t0 !== undefined && [Type.TKN_SHORT, Type.TKN_LONG, Type.TKN_UNSIGNED].includes(t0.type)) {
482
+ throw Error('valid integer types are: short, unsigned short, long, unsigned long, long long, unsigned long long');
483
+ }
484
+ lexer.unlex(t0);
593
485
  return undefined;
594
486
  }
595
- // 55
596
487
  function signed_int() {
597
488
  let t0;
598
489
  t0 = signed_short_int();
@@ -606,31 +497,28 @@ function signed_int() {
606
497
  return t0;
607
498
  return undefined;
608
499
  }
609
- // 56
610
500
  function signed_short_int() {
611
501
  let t0 = lexer.lex();
612
- if (t0 !== undefined && t0.type === idl_node_1.Type.TKN_SHORT)
502
+ if (t0 !== undefined && t0.type === Type.TKN_SHORT)
613
503
  return t0;
614
504
  lexer.unlex(t0);
615
505
  return undefined;
616
506
  }
617
- // 57
618
507
  function signed_long_int() {
619
508
  let t0 = lexer.lex();
620
509
  if (t0 === undefined)
621
510
  return undefined;
622
- if (t0.type === idl_node_1.Type.TKN_LONG)
511
+ if (t0.type === Type.TKN_LONG)
623
512
  return t0;
624
513
  lexer.unlex(t0);
625
514
  return undefined;
626
515
  }
627
- // 58
628
516
  function signed_longlong_int() {
629
517
  let t0 = lexer.lex();
630
- if (t0 !== undefined && t0.type === idl_node_1.Type.TKN_LONG) {
518
+ if (t0 !== undefined && t0.type === Type.TKN_LONG) {
631
519
  let t1 = lexer.lex();
632
- if (t1 !== undefined && t1.type === idl_node_1.Type.TKN_LONG) {
633
- t0.type = idl_node_1.Type.SYN_LONGLONG;
520
+ if (t1 !== undefined && t1.type === Type.TKN_LONG) {
521
+ t0.type = Type.SYN_LONGLONG;
634
522
  return t0;
635
523
  }
636
524
  lexer.unlex(t1);
@@ -638,7 +526,6 @@ function signed_longlong_int() {
638
526
  lexer.unlex(t0);
639
527
  return undefined;
640
528
  }
641
- // 59
642
529
  function unsigned_int() {
643
530
  let t0;
644
531
  t0 = unsigned_short_int();
@@ -652,13 +539,12 @@ function unsigned_int() {
652
539
  return t0;
653
540
  return undefined;
654
541
  }
655
- // 60
656
542
  function unsigned_short_int() {
657
543
  let t0 = lexer.lex();
658
- if (t0 !== undefined && t0.type === idl_node_1.Type.TKN_UNSIGNED) {
544
+ if (t0 !== undefined && t0.type === Type.TKN_UNSIGNED) {
659
545
  let t1 = lexer.lex();
660
- if (t1 !== undefined && t1.type === idl_node_1.Type.TKN_SHORT) {
661
- t0.type = idl_node_1.Type.SYN_UNSIGNED_SHORT;
546
+ if (t1 !== undefined && t1.type === Type.TKN_SHORT) {
547
+ t0.type = Type.SYN_UNSIGNED_SHORT;
662
548
  return t0;
663
549
  }
664
550
  lexer.unlex(t1);
@@ -666,13 +552,12 @@ function unsigned_short_int() {
666
552
  lexer.unlex(t0);
667
553
  return undefined;
668
554
  }
669
- // 61
670
555
  function unsigned_long_int() {
671
556
  let t0 = lexer.lex();
672
- if (t0 !== undefined && t0.type === idl_node_1.Type.TKN_UNSIGNED) {
557
+ if (t0 !== undefined && t0.type === Type.TKN_UNSIGNED) {
673
558
  let t1 = lexer.lex();
674
- if (t1 !== undefined && t1.type === idl_node_1.Type.TKN_LONG) {
675
- t0.type = idl_node_1.Type.SYN_UNSIGNED_LONG;
559
+ if (t1 !== undefined && t1.type === Type.TKN_LONG) {
560
+ t0.type = Type.SYN_UNSIGNED_LONG;
676
561
  return t0;
677
562
  }
678
563
  lexer.unlex(t1);
@@ -680,15 +565,14 @@ function unsigned_long_int() {
680
565
  lexer.unlex(t0);
681
566
  return undefined;
682
567
  }
683
- // 62
684
568
  function unsigned_longlong_int() {
685
569
  let t0 = lexer.lex();
686
- if (t0 !== undefined && t0.type === idl_node_1.Type.TKN_UNSIGNED) {
570
+ if (t0 !== undefined && t0.type === Type.TKN_UNSIGNED) {
687
571
  let t1 = lexer.lex();
688
- if (t1 !== undefined && t1.type === idl_node_1.Type.TKN_LONG) {
572
+ if (t1 !== undefined && t1.type === Type.TKN_LONG) {
689
573
  let t2 = lexer.lex();
690
- if (t2 !== undefined && t2.type === idl_node_1.Type.TKN_LONG) {
691
- t0.type = idl_node_1.Type.SYN_UNSIGNED_LONGLONG;
574
+ if (t2 !== undefined && t2.type === Type.TKN_LONG) {
575
+ t0.type = Type.SYN_UNSIGNED_LONGLONG;
692
576
  return t0;
693
577
  }
694
578
  lexer.unlex(t2);
@@ -698,51 +582,124 @@ function unsigned_longlong_int() {
698
582
  lexer.unlex(t0);
699
583
  return undefined;
700
584
  }
701
- // 63
702
585
  function char_type() {
703
586
  let t0 = lexer.lex();
704
- if (t0 !== undefined && t0.type == idl_node_1.Type.TKN_CHAR)
587
+ if (t0 !== undefined && t0.type == Type.TKN_CHAR)
705
588
  return t0;
706
589
  lexer.unlex(t0);
707
590
  return undefined;
708
591
  }
709
- // 64
710
592
  function wide_char_type() {
711
593
  let t0 = lexer.lex();
712
- if (t0 !== undefined && t0.type == idl_node_1.Type.TKN_WCHAR)
594
+ if (t0 !== undefined && t0.type == Type.TKN_WCHAR)
713
595
  return t0;
714
596
  lexer.unlex(t0);
715
597
  return undefined;
716
598
  }
717
- // 65
718
599
  function boolean_type() {
719
600
  let t0 = lexer.lex();
720
- if (t0 !== undefined && t0.type == idl_node_1.Type.TKN_BOOLEAN)
601
+ if (t0 !== undefined && t0.type == Type.TKN_BOOLEAN)
721
602
  return t0;
722
603
  lexer.unlex(t0);
723
604
  return undefined;
724
605
  }
725
- // 66
726
606
  function octet_type() {
727
607
  let t0 = lexer.lex();
728
- if (t0 !== undefined && t0.type == idl_node_1.Type.TKN_OCTET)
608
+ if (t0 !== undefined && t0.type == Type.TKN_OCTET)
729
609
  return t0;
730
610
  lexer.unlex(t0);
731
611
  return undefined;
732
612
  }
733
- // 67
734
613
  function any_type() {
614
+ const t0 = lexer.lex();
615
+ if (t0 !== undefined && t0.type == Type.TKN_ANY)
616
+ return t0;
617
+ lexer.unlex(t0);
618
+ return undefined;
619
+ }
620
+ function struct_type() {
621
+ const t0 = lexer.lex();
622
+ if (t0 === undefined || t0.type !== Type.TKN_STRUCT) {
623
+ lexer.unlex(t0);
624
+ return undefined;
625
+ }
626
+ const t1 = identifier();
627
+ if (t1 === undefined)
628
+ throw Error("expected identifier after 'struct'");
629
+ expect('{');
630
+ const t2 = member_list();
631
+ if (t2 === undefined)
632
+ throw Error("expected at least one member within 'struct'");
633
+ expect('}');
634
+ t2.type = t0.type;
635
+ t2.text = t1.text;
636
+ scoper.addType(t2.text, t0);
637
+ return t2;
638
+ }
639
+ function member_list() {
640
+ const t0 = member();
641
+ if (t0 === undefined)
642
+ return undefined;
643
+ const node = new Node(Type.SYN_MEMBER_LIST);
644
+ node.append(t0);
645
+ while (true) {
646
+ const t1 = member();
647
+ if (t1 === undefined)
648
+ break;
649
+ node.append(t1);
650
+ }
651
+ return node;
652
+ }
653
+ function member() {
654
+ const node = new Node(Type.SYN_MEMBER);
655
+ const t0 = type_spec();
656
+ if (t0 === undefined)
657
+ return undefined;
658
+ const t1 = declarators();
659
+ if (t1 === undefined)
660
+ throw Error(`expected declarators after type_spec ${t0.toString()}`);
661
+ expect(";");
662
+ node.append(t0);
663
+ node.append(t1);
664
+ return node;
665
+ }
666
+ function enum_type() {
735
667
  let t0 = lexer.lex();
736
- if (t0 !== undefined && t0.type == idl_node_1.Type.TKN_ANY)
668
+ if (t0 !== undefined && t0.type == Type.TKN_ENUM) {
669
+ const t1 = identifier();
670
+ if (t1 === undefined)
671
+ throw Error("expected identifier after 'enum'");
672
+ t0.text = t1.text;
673
+ expect("{");
674
+ const set = new Set();
675
+ while (true) {
676
+ let t2 = lexer.lex();
677
+ if (t2 === undefined)
678
+ throw Error("unexpected end of file");
679
+ if (t2.type !== Type.TKN_IDENTIFIER)
680
+ throw Error("expected identifier but got ${t2}");
681
+ if (set.has(t2.text)) {
682
+ throw Error(`Declaration of enumerator '${t2.text}' clashes with earlier declaration of enumerator '${t2.text}'`);
683
+ }
684
+ set.add(t2.text);
685
+ t0.append(t2);
686
+ let t3 = lexer.lex();
687
+ if (t3 === undefined)
688
+ throw Error("unexpected end of file");
689
+ if (t3.type !== Type.TKN_TEXT)
690
+ throw Error("expected ',' or '}' but got ${t2}");
691
+ if (t3.text === "}")
692
+ break;
693
+ }
694
+ scoper.addType(t0.text, t0);
737
695
  return t0;
696
+ }
738
697
  lexer.unlex(t0);
739
698
  return undefined;
740
699
  }
741
- // 80
742
700
  function sequence_type() {
743
701
  let t0 = lexer.lex();
744
- if (t0 !== undefined && t0.type === idl_node_1.Type.TKN_SEQUENCE) {
745
- // "sequence" "<" simple_type_spec "," positive_int_const ">"
702
+ if (t0 !== undefined && t0.type === Type.TKN_SEQUENCE) {
746
703
  expect("<");
747
704
  let t1 = simple_type_spec();
748
705
  if (t1 === undefined)
@@ -755,27 +712,22 @@ function sequence_type() {
755
712
  lexer.unlex(t0);
756
713
  return undefined;
757
714
  }
758
- // 81
759
715
  function string_type() {
760
716
  let t0 = lexer.lex();
761
- if (t0 !== undefined && t0.type === idl_node_1.Type.TKN_STRING) {
762
- // 'string' '<' <positive_int_const> '>'
717
+ if (t0 !== undefined && t0.type === Type.TKN_STRING) {
763
718
  return t0;
764
719
  }
765
720
  lexer.unlex(t0);
766
721
  return undefined;
767
722
  }
768
- // 82
769
723
  function wide_string_type() {
770
724
  let t0 = lexer.lex();
771
- if (t0 !== undefined && t0.type === idl_node_1.Type.TKN_WSTRING) {
772
- // 'wstring' '<' <positive_int_const> '>'
725
+ if (t0 !== undefined && t0.type === Type.TKN_WSTRING) {
773
726
  return t0;
774
727
  }
775
728
  lexer.unlex(t0);
776
729
  return undefined;
777
730
  }
778
- // 85
779
731
  function attr_dcl() {
780
732
  let t0;
781
733
  t0 = readonly_attr_spec();
@@ -783,77 +735,94 @@ function attr_dcl() {
783
735
  t0 = attr_spec();
784
736
  return t0;
785
737
  }
786
- // 87 (Operation Declaration)
738
+ function except_dcl() {
739
+ let t0 = lexer.lex();
740
+ if (t0 === undefined || t0.type != Type.TKN_EXCEPTION) {
741
+ lexer.unlex(t0);
742
+ return undefined;
743
+ }
744
+ let t1 = identifier();
745
+ if (t1 === undefined)
746
+ throw Error(`expected identifier after '${t0.toString()}'`);
747
+ t0.text = t1.text;
748
+ expect("{");
749
+ while (true) {
750
+ let t2 = member();
751
+ if (t2 === undefined)
752
+ break;
753
+ t0.append(t2);
754
+ }
755
+ expect("}");
756
+ scoper.addType(t0.text, t0);
757
+ return t0;
758
+ }
787
759
  function op_dcl() {
788
- let t0 = op_attribute(); // opt
789
- let t1 = op_type_spec();
760
+ const t0 = op_attribute();
761
+ const t1 = op_type_spec();
790
762
  if (t1 === undefined) {
791
763
  lexer.unlex(t0);
792
764
  return undefined;
793
765
  }
794
- let t2 = identifier();
766
+ const t2 = identifier();
795
767
  if (t2 === undefined) {
796
- throw Error("expected identifier");
768
+ throw Error(`expected identifier after '${t1.toString()}'`);
797
769
  }
798
- let t3 = parameter_dcls();
770
+ const t3 = parameter_dcls();
799
771
  if (t3 === undefined) {
800
- // throw Error("expected parameter declaration after "+t2.toString())
801
772
  lexer.unlex(t2);
802
773
  lexer.unlex(t1);
803
774
  lexer.unlex(t0);
804
775
  return undefined;
805
776
  }
806
- let node = new idl_node_1.Node(idl_node_1.Type.SYN_OPERATION_DECLARATION);
777
+ const t4 = raises_expr();
778
+ let node = new Node(Type.SYN_OPERATION_DECLARATION);
807
779
  node.append(t0);
808
780
  node.append(t1);
809
781
  node.append(t2);
810
782
  node.append(t3);
811
- node.append(undefined);
783
+ node.append(t4);
812
784
  node.append(undefined);
813
785
  return node;
814
786
  }
815
- // 88
816
787
  function op_attribute() {
817
788
  let t0 = lexer.lex();
818
789
  if (!t0)
819
790
  return undefined;
820
- if (t0.type !== idl_node_1.Type.TKN_ONEWAY) {
791
+ if (t0.type !== Type.TKN_ONEWAY) {
821
792
  lexer.unlex(t0);
822
793
  return undefined;
823
794
  }
824
795
  return t0;
825
796
  }
826
- // 89
827
797
  function op_type_spec() {
828
798
  let t0 = param_type_spec();
829
799
  if (t0 !== undefined)
830
800
  return t0;
831
801
  t0 = lexer.lex();
832
- if (t0 !== undefined && t0.type === idl_node_1.Type.TKN_VOID)
802
+ if (t0 !== undefined && t0.type === Type.TKN_VOID)
833
803
  return t0;
834
804
  lexer.unlex(t0);
835
805
  return undefined;
836
806
  }
837
- // 90
838
807
  function parameter_dcls() {
839
808
  let t0 = lexer.lex();
840
809
  if (!t0) {
841
810
  return undefined;
842
811
  }
843
- if (t0.type !== idl_node_1.Type.TKN_TEXT || t0.text !== '(') {
812
+ if (t0.type !== Type.TKN_TEXT || t0.text !== '(') {
844
813
  lexer.unlex(t0);
845
814
  return undefined;
846
815
  }
847
- let declarations = new idl_node_1.Node(idl_node_1.Type.SYN_PARAMETER_DECLARATIONS);
816
+ let declarations = new Node(Type.SYN_PARAMETER_DECLARATIONS);
848
817
  while (true) {
849
818
  let t1 = param_dcl();
850
819
  if (t1 !== undefined)
851
820
  declarations.append(t1);
852
821
  let t2 = lexer.lex();
853
- if (t2 !== undefined && t2.type === idl_node_1.Type.TKN_TEXT && t2.text === ')') {
822
+ if (t2 !== undefined && t2.type === Type.TKN_TEXT && t2.text === ')') {
854
823
  break;
855
824
  }
856
- if (t2 !== undefined && t2.type === idl_node_1.Type.TKN_TEXT && t2.text === ",") {
825
+ if (t2 !== undefined && t2.type === Type.TKN_TEXT && t2.text === ",") {
857
826
  continue;
858
827
  }
859
828
  if (t2 !== undefined)
@@ -863,7 +832,6 @@ function parameter_dcls() {
863
832
  }
864
833
  return declarations;
865
834
  }
866
- // 91
867
835
  function param_dcl() {
868
836
  let t0 = param_attribute();
869
837
  if (t0 === undefined)
@@ -880,54 +848,73 @@ function param_dcl() {
880
848
  if (t2 === undefined) {
881
849
  throw Error("Missing parameter name.");
882
850
  }
883
- let declaration = new idl_node_1.Node(idl_node_1.Type.SYN_PARAMETER_DECLARATION);
851
+ let declaration = new Node(Type.SYN_PARAMETER_DECLARATION);
884
852
  declaration.append(t0);
885
853
  declaration.append(t1);
886
854
  declaration.append(t2);
887
855
  return declaration;
888
856
  }
889
- // 92
890
857
  function param_attribute() {
891
858
  let t0 = lexer.lex();
892
859
  if (t0 === undefined)
893
860
  return undefined;
894
861
  switch (t0.type) {
895
- case idl_node_1.Type.TKN_IN:
896
- case idl_node_1.Type.TKN_OUT:
897
- case idl_node_1.Type.TKN_INOUT:
862
+ case Type.TKN_IN:
863
+ case Type.TKN_OUT:
864
+ case Type.TKN_INOUT:
898
865
  return t0;
899
866
  }
900
867
  lexer.unlex(t0);
901
868
  return undefined;
902
869
  }
903
- // 95
870
+ function raises_expr() {
871
+ let t0 = lexer.lex();
872
+ if (t0 === undefined || t0.type !== Type.TKN_RAISES) {
873
+ lexer.unlex(t0);
874
+ return undefined;
875
+ }
876
+ expect("(");
877
+ let t1 = scoped_name();
878
+ if (t1 === undefined)
879
+ throw Error(`expected exception name after 'raises('`);
880
+ if (t1.child[0] === undefined || t1.child[0].type !== Type.TKN_EXCEPTION)
881
+ throw Error(`expected ${t1.toString()} to be an exception`);
882
+ if (t1.type)
883
+ t0.append(t1);
884
+ while (true) {
885
+ let t2 = lexer.lex();
886
+ if (t2 === undefined || t2.type !== Type.TKN_TEXT || t0.text !== ",") {
887
+ lexer.unlex(t2);
888
+ break;
889
+ }
890
+ t1 = scoped_name();
891
+ if (t1 === undefined)
892
+ throw Error(`expected exception name after 'raises(..., '`);
893
+ if (t1.child[0] === undefined || t1.child[0].type !== Type.TKN_EXCEPTION)
894
+ throw Error(`expected ${t1.toString()} to be an exception`);
895
+ t0.append(t1);
896
+ }
897
+ expect(")");
898
+ return t0;
899
+ }
904
900
  function param_type_spec() {
905
901
  let t0;
906
902
  t0 = base_type_spec();
907
903
  if (t0 !== undefined)
908
904
  return t0;
909
- t0 = template_type_spec(); // not in the CORBA specs but MICO does this, usually an typedef would be required for this
905
+ t0 = template_type_spec();
910
906
  if (t0 !== undefined)
911
907
  return t0;
912
- /*
913
- t0 = string_type()
914
- if (t0 !== undefined)
915
- return t0
916
- t0 = wide_string_type()
917
- if (t0 !== undefined)
918
- return t0
919
- */
920
908
  t0 = scoped_name();
921
909
  if (t0)
922
910
  return t0;
923
911
  return undefined;
924
912
  }
925
- // 104
926
913
  function readonly_attr_spec() {
927
914
  let t0 = lexer.lex();
928
- if (t0 !== undefined && t0.type === idl_node_1.Type.TKN_READONLY) {
915
+ if (t0 !== undefined && t0.type === Type.TKN_READONLY) {
929
916
  let t1 = lexer.lex();
930
- if (t1 !== undefined && t1.type === idl_node_1.Type.TKN_ATTRIBUTE) {
917
+ if (t1 !== undefined && t1.type === Type.TKN_ATTRIBUTE) {
931
918
  let t2 = param_type_spec();
932
919
  if (t2 === undefined)
933
920
  throw Error("expected type specifier after 'readonly attribute'");
@@ -944,16 +931,15 @@ function readonly_attr_spec() {
944
931
  lexer.unlex(t0);
945
932
  return undefined;
946
933
  }
947
- // 105
948
934
  function readonly_attr_declarator() {
949
935
  let t0 = simple_declarator();
950
936
  if (t0 === undefined)
951
937
  return undefined;
952
- let node = new idl_node_1.Node(idl_node_1.Type.SYN_DECLARATORS);
938
+ let node = new Node(Type.SYN_DECLARATORS);
953
939
  while (true) {
954
940
  node.append(t0);
955
941
  let t1 = lexer.lex();
956
- if (t1 === undefined || t1.type !== idl_node_1.Type.TKN_TEXT || t1.text !== ",") {
942
+ if (t1 === undefined || t1.type !== Type.TKN_TEXT || t1.text !== ",") {
957
943
  lexer.unlex(t1);
958
944
  return node;
959
945
  }
@@ -962,10 +948,9 @@ function readonly_attr_declarator() {
962
948
  throw Error("expected another declarator after ','");
963
949
  }
964
950
  }
965
- // 106
966
951
  function attr_spec() {
967
952
  let t0 = lexer.lex();
968
- if (t0 !== undefined && t0.type === idl_node_1.Type.TKN_ATTRIBUTE) {
953
+ if (t0 !== undefined && t0.type === Type.TKN_ATTRIBUTE) {
969
954
  let t1 = param_type_spec();
970
955
  if (t1 === undefined)
971
956
  throw Error("expected type specifier after 'attribute'");
@@ -980,16 +965,15 @@ function attr_spec() {
980
965
  lexer.unlex(t0);
981
966
  return undefined;
982
967
  }
983
- // 107
984
968
  function attr_declarator() {
985
969
  let t0 = simple_declarator();
986
970
  if (t0 === undefined)
987
971
  return undefined;
988
- let node = new idl_node_1.Node(idl_node_1.Type.SYN_DECLARATORS);
972
+ let node = new Node(Type.SYN_DECLARATORS);
989
973
  while (true) {
990
974
  node.append(t0);
991
975
  let t1 = lexer.lex();
992
- if (t1 === undefined || t1.type !== idl_node_1.Type.TKN_TEXT || t1.text !== ",") {
976
+ if (t1 === undefined || t1.type !== Type.TKN_TEXT || t1.text !== ",") {
993
977
  lexer.unlex(t1);
994
978
  return node;
995
979
  }
@@ -1000,9 +984,101 @@ function attr_declarator() {
1000
984
  }
1001
985
  function identifier() {
1002
986
  let t0 = lexer.lex();
1003
- if (t0 !== undefined && t0.type === idl_node_1.Type.TKN_IDENTIFIER)
987
+ if (t0 !== undefined && t0.type === Type.TKN_IDENTIFIER)
1004
988
  return t0;
1005
989
  lexer.unlex(t0);
1006
990
  return undefined;
1007
991
  }
992
+ function expect(text, customMessage) {
993
+ let t0 = lexer.lex();
994
+ let errorMessage;
995
+ if (customMessage === undefined)
996
+ errorMessage = `expected '${text}' but got '${t0?.toString()}'`;
997
+ else
998
+ errorMessage = customMessage;
999
+ if (t0 === undefined)
1000
+ throw Error(errorMessage + " but found end of file");
1001
+ if (t0.type !== Type.TKN_TEXT || t0.text !== text) {
1002
+ throw Error(errorMessage);
1003
+ }
1004
+ }
1005
+ class Scope {
1006
+ constructor(node) {
1007
+ this.node = node;
1008
+ this.types = new Map();
1009
+ this.modules = new Map();
1010
+ }
1011
+ addType(name, type) {
1012
+ if (this.types.has(name))
1013
+ throw Error("duplicate typename '" + name + "'");
1014
+ this.types.set(name, type);
1015
+ type.typeParent = this.node;
1016
+ }
1017
+ getType(name) {
1018
+ return this.types.get(name);
1019
+ }
1020
+ }
1021
+ class ScopeManager {
1022
+ constructor() {
1023
+ this.stack = new Array();
1024
+ this.stack.push(new Scope(undefined));
1025
+ }
1026
+ getGlobalScope() {
1027
+ return this.stack[0];
1028
+ }
1029
+ getCurrentScope() {
1030
+ return this.stack[this.stack.length - 1];
1031
+ }
1032
+ addType(name, type) {
1033
+ this.getCurrentScope().addType(name, type);
1034
+ }
1035
+ getType(name) {
1036
+ for (let i = this.stack.length - 1; i >= 0; --i) {
1037
+ let type = this.stack[i].getType(name);
1038
+ if (type !== undefined)
1039
+ return type;
1040
+ }
1041
+ return undefined;
1042
+ }
1043
+ enterModule(node) {
1044
+ this.getCurrentScope().addType(node.text, node);
1045
+ this.stack.push(new Scope(node));
1046
+ }
1047
+ leaveModule(node) {
1048
+ this.stack.pop();
1049
+ }
1050
+ }
1051
+ function resolve_module(identifierToken, module) {
1052
+ const paamayimNekudotayim = lexer.lex();
1053
+ if (paamayimNekudotayim === undefined || paamayimNekudotayim.type !== Type.TKN_COLON_COLON)
1054
+ throw Error(`Expected :: after module identifier '${identifierToken.text}'`);
1055
+ const identifier = lexer.lex();
1056
+ if (identifier === undefined || identifier.type !== Type.TKN_IDENTIFIER)
1057
+ throw Error(`Expected identifier after ::'`);
1058
+ for (let child of module.child) {
1059
+ switch (child?.type) {
1060
+ case Type.TKN_MODULE:
1061
+ if (child.text === identifier.text) {
1062
+ identifierToken.append(child);
1063
+ resolve_module(identifierToken, child);
1064
+ return;
1065
+ }
1066
+ break;
1067
+ case Type.TKN_NATIVE:
1068
+ case Type.TKN_VALUETYPE:
1069
+ if (child.text === identifier.text) {
1070
+ identifierToken.append(child);
1071
+ return;
1072
+ }
1073
+ break;
1074
+ case Type.SYN_INTERFACE:
1075
+ if (child.child[0].child[1].text === identifier.text) {
1076
+ identifierToken.append(child);
1077
+ return;
1078
+ }
1079
+ break;
1080
+ }
1081
+ }
1082
+ throw Error(`failed to lookup ${identifier.text}`);
1083
+ }
1008
1084
  //# sourceMappingURL=idl-parser.js.map