cariboujs 2.0.4 → 2.0.6

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 (109) hide show
  1. package/README.md +13 -3
  2. package/ada/ada2012/AdaLexer.js +486 -316
  3. package/ada/ada2012/AdaLexerBase.js +25 -0
  4. package/ada/ada2012/AdaParser.js +4547 -3823
  5. package/ada/ada2012/AdaParserBase.js +682 -0
  6. package/ada/ada2012/AdaParserListener.js +36 -0
  7. package/ada/ada2012/AdaParserVisitor.js +24 -0
  8. package/ada/ada2012/Symbol.js +20 -0
  9. package/ada/ada2012/SymbolTable.js +144 -0
  10. package/ada/ada2012/TypeClassification.js +15 -0
  11. package/ada/ada2022/AdaLexer.js +699 -0
  12. package/ada/ada2022/AdaLexerBase.js +25 -0
  13. package/ada/ada2022/AdaParser.js +37818 -0
  14. package/ada/ada2022/AdaParserBase.js +686 -0
  15. package/ada/ada2022/AdaParserListener.js +3024 -0
  16. package/ada/ada2022/AdaParserVisitor.js +2020 -0
  17. package/ada/ada2022/Symbol.js +20 -0
  18. package/ada/ada2022/SymbolTable.js +144 -0
  19. package/ada/ada2022/TypeClassification.js +15 -0
  20. package/c/CLexer.js +918 -0
  21. package/c/CLexerBase.js +96 -0
  22. package/c/CParser.js +14878 -0
  23. package/c/CParserBase.js +617 -0
  24. package/c/CParserListener.js +1062 -0
  25. package/c/CParserVisitor.js +712 -0
  26. package/c/ErrorListener.js +50 -0
  27. package/c/Symbol.js +28 -0
  28. package/c/SymbolTable.js +220 -0
  29. package/c/TypeClassification.js +21 -0
  30. package/cpp/CPP14Parser.js +630 -619
  31. package/cpp/CPP14ParserListener.js +56 -56
  32. package/cpp/CPP14ParserVisitor.js +28 -28
  33. package/csharp/v7/CSharpLexer.js +1339 -0
  34. package/csharp/v7/CSharpLexerBase.js +332 -0
  35. package/csharp/v7/CSharpParser.js +29239 -0
  36. package/csharp/v7/CSharpParserBase.js +48 -0
  37. package/csharp/v7/CSharpParserListener.js +2304 -0
  38. package/csharp/v7/CSharpParserVisitor.js +1540 -0
  39. package/csharp/v8-spec/CSharpLexer.js +1549 -0
  40. package/csharp/v8-spec/CSharpLexerBase.js +296 -0
  41. package/csharp/v8-spec/CSharpParser.js +45055 -0
  42. package/csharp/v8-spec/CSharpParserBase.js +587 -0
  43. package/csharp/v8-spec/CSharpParserListener.js +3582 -0
  44. package/csharp/v8-spec/CSharpParserVisitor.js +2392 -0
  45. package/cypher/CypherParser.js +1171 -780
  46. package/cypher/CypherParserListener.js +27 -0
  47. package/cypher/CypherParserVisitor.js +18 -0
  48. package/geekcode/geekcodeLexer.js +232 -0
  49. package/geekcode/geekcodeListener.js +81 -0
  50. package/geekcode/geekcodeParser.js +1516 -0
  51. package/geekcode/geekcodeVisitor.js +58 -0
  52. package/gql/GQLLexer.js +2203 -0
  53. package/gql/GQLListener.js +5499 -0
  54. package/gql/GQLParser.js +58653 -0
  55. package/gql/GQLVisitor.js +3670 -0
  56. package/kotlin/kotlin/KotlinLexer.js +1257 -1247
  57. package/kotlin/kotlin/KotlinParser.js +3991 -3425
  58. package/kotlin/kotlin/KotlinParserListener.js +36 -0
  59. package/kotlin/kotlin/KotlinParserVisitor.js +24 -0
  60. package/maml/MAMLLexer.js +116 -0
  61. package/maml/MAMLListener.js +72 -0
  62. package/maml/MAMLParser.js +935 -0
  63. package/maml/MAMLVisitor.js +52 -0
  64. package/odin/odinLexer.js +739 -0
  65. package/odin/odinListener.js +882 -0
  66. package/odin/odinParser.js +12189 -0
  67. package/odin/odinVisitor.js +592 -0
  68. package/package.json +1 -1
  69. package/plantUML/PlantUMLLexer.js +215 -316
  70. package/plantUML/PlantUMLParser.js +1045 -2393
  71. package/plantUML/PlantUMLParserListener.js +171 -0
  72. package/plantUML/PlantUMLParserVisitor.js +118 -0
  73. package/sql/mysql/Oracle/MySQLLexer.js +3689 -3668
  74. package/sql/mysql/Oracle/MySQLParser.js +4383 -4399
  75. package/sql/plsql/PlSqlLexer.js +13604 -13587
  76. package/sql/plsql/PlSqlParser.js +51622 -64188
  77. package/sql/plsql/PlSqlParserBase.js +30 -0
  78. package/sql/plsql/PlSqlParserListener.js +36 -9
  79. package/sql/plsql/PlSqlParserVisitor.js +24 -6
  80. package/sql/postgresql/PostgreSQLParser.js +91 -91
  81. package/sql/snowflake/SnowflakeLexer.js +5675 -5497
  82. package/sql/snowflake/SnowflakeParser.js +27252 -22655
  83. package/sql/snowflake/SnowflakeParserListener.js +278 -8
  84. package/sql/snowflake/SnowflakeParserVisitor.js +184 -4
  85. package/sql/sqlite/SQLiteParser.js +2638 -2301
  86. package/sql/sqlite/SQLiteParserListener.js +9 -9
  87. package/sql/sqlite/SQLiteParserVisitor.js +6 -6
  88. package/sysml-v2/SysMLv2Lexer.js +1047 -0
  89. package/sysml-v2/SysMLv2Parser.js +51339 -0
  90. package/sysml-v2/SysMLv2ParserListener.js +4464 -0
  91. package/sysml-v2/SysMLv2ParserVisitor.js +2980 -0
  92. package/turtle/TURTLELexer.js +155 -156
  93. package/vba/vba7_1/vbaLexer.js +1689 -0
  94. package/vba/vba7_1/vbaParser.js +42797 -0
  95. package/vba/vba7_1/vbaParserListener.js +3267 -0
  96. package/vba/vba7_1/vbaParserVisitor.js +2182 -0
  97. package/vhdl/vhdl2008/vhdl2008Listener.js +9 -0
  98. package/vhdl/vhdl2008/vhdl2008Parser.js +2840 -2705
  99. package/vhdl/vhdl2008/vhdl2008Visitor.js +6 -0
  100. package/wkt/wktLexer.js +177 -148
  101. package/wkt/wktListener.js +123 -60
  102. package/wkt/wktParser.js +1802 -1125
  103. package/wkt/wktVisitor.js +72 -30
  104. package/plantUML/PlantUMLListener.js +0 -279
  105. package/plantUML/PlantUMLVisitor.js +0 -190
  106. /package/scala/{ScalaLexer.js → scala2/ScalaLexer.js} +0 -0
  107. /package/scala/{ScalaListener.js → scala2/ScalaListener.js} +0 -0
  108. /package/scala/{ScalaParser.js → scala2/ScalaParser.js} +0 -0
  109. /package/scala/{ScalaVisitor.js → scala2/ScalaVisitor.js} +0 -0
@@ -0,0 +1,682 @@
1
+ import antlr4 from 'antlr4';
2
+ import fs from 'fs';
3
+ import pathModule from 'path';
4
+ import AdaLexer from './AdaLexer.js';
5
+ import AdaParser from './AdaParser.js';
6
+ import Symbol from './Symbol.js';
7
+ import SymbolTable from './SymbolTable.js';
8
+ import TypeClassification from './TypeClassification.js';
9
+
10
+ const ALL_SEMANTIC_FUNCTIONS = ["IsAggregate", "IsTypeName"];
11
+
12
+ function parseNoSemantics(args) {
13
+ var result = new Set();
14
+ if (!args) return result;
15
+ for (var a of args) {
16
+ if (a.toLowerCase().startsWith("--no-semantics")) {
17
+ var eqIndex = a.indexOf('=');
18
+ if (eqIndex === -1) {
19
+ for (var func of ALL_SEMANTIC_FUNCTIONS) {
20
+ result.add(func);
21
+ }
22
+ } else {
23
+ var value = a.substring(eqIndex + 1);
24
+ var funcs = value.split(',');
25
+ for (var f of funcs) {
26
+ result.add(f.trim());
27
+ }
28
+ }
29
+ }
30
+ }
31
+ return result;
32
+ }
33
+
34
+ class SimpleTokenSource {
35
+ constructor(tokens) {
36
+ this.tokens = tokens;
37
+ this.pos = 0;
38
+ }
39
+ nextToken() {
40
+ if (this.pos >= this.tokens.length) {
41
+ return this.tokens[this.tokens.length - 1];
42
+ }
43
+ return this.tokens[this.pos++];
44
+ }
45
+ getSourceName() { return "pragma"; }
46
+ }
47
+
48
+ export default class AdaParserBase extends antlr4.Parser {
49
+ constructor(input) {
50
+ super(input);
51
+ this._st = new SymbolTable();
52
+ this._expectedTypeStack = [];
53
+ this._debug = false;
54
+ this._outputSymbolTable = false;
55
+ this._outputAppliedOccurrences = false;
56
+ this._noSemantics = new Set();
57
+ this._searchPaths = [];
58
+ this._currentFile = "";
59
+ this._initOptions();
60
+ }
61
+
62
+ _initOptions() {
63
+ var args = (typeof process !== 'undefined' && process.argv) ? process.argv : [];
64
+ this._noSemantics = parseNoSemantics(args);
65
+ this._debug = args.some(a => a.toLowerCase().indexOf("--debug") >= 0);
66
+ this._outputSymbolTable = args.some(a => a.toLowerCase().indexOf("--output-symbol-table") >= 0);
67
+ this._outputAppliedOccurrences = args.some(a => a.toLowerCase().indexOf("--output-applied-occurrences") >= 0);
68
+ for (var a of args) {
69
+ if (a.toLowerCase().startsWith("--i") && a.length > 3) {
70
+ this._searchPaths.push(a.substring(3));
71
+ }
72
+ }
73
+ }
74
+
75
+ IsAggregate() {
76
+ if (this._noSemantics.has("IsAggregate")) return true;
77
+ var stream = this._input;
78
+ var lt1 = stream.LT(1);
79
+ if (lt1.type !== AdaLexer.LP) {
80
+ if (this._debug) process.stderr.write("IsAggregate: LT(1) is not LP, returning false\n");
81
+ return false;
82
+ }
83
+ // Structural scan from LT(2), tracking paren depth
84
+ var depth = 0;
85
+ for (var i = 2; ; i++) {
86
+ var t = stream.LT(i);
87
+ if (t === null || t.type === antlr4.Token.EOF) break;
88
+ if (t.type === AdaLexer.LP) {
89
+ depth++;
90
+ } else if (t.type === AdaLexer.RP) {
91
+ if (depth === 0) {
92
+ // Reached closing paren without indicators -- fall through to type context
93
+ break;
94
+ }
95
+ depth--;
96
+ } else if (depth === 0) {
97
+ if (t.type === AdaLexer.COMMA) {
98
+ if (this._debug) process.stderr.write("IsAggregate: found COMMA at depth 0, returning true\n");
99
+ return true;
100
+ }
101
+ if (t.type === AdaLexer.ARROW) {
102
+ if (this._debug) process.stderr.write("IsAggregate: found ARROW at depth 0, returning true\n");
103
+ return true;
104
+ }
105
+ if (t.type === AdaLexer.WITH) {
106
+ if (this._debug) process.stderr.write("IsAggregate: found WITH at depth 0, returning true\n");
107
+ return true;
108
+ }
109
+ if (t.type === AdaLexer.NULL_) {
110
+ var next = stream.LT(i + 1);
111
+ if (next !== null && next.type === AdaLexer.RECORD) {
112
+ if (this._debug) process.stderr.write("IsAggregate: found NULL RECORD at depth 0, returning true\n");
113
+ return true;
114
+ }
115
+ }
116
+ }
117
+ }
118
+ // Type-context check
119
+ if (this._expectedTypeStack.length > 0) {
120
+ var expected = this._expectedTypeStack[this._expectedTypeStack.length - 1];
121
+ if (expected !== null && expected.isComposite) {
122
+ if (this._debug) process.stderr.write("IsAggregate: expected type is composite, returning true\n");
123
+ return true;
124
+ }
125
+ }
126
+ if (this._debug) process.stderr.write("IsAggregate: no aggregate indicators, returning false\n");
127
+ return false;
128
+ }
129
+
130
+ IsTypeName() {
131
+ if (this._noSemantics.has("IsTypeName")) return true;
132
+ var stream = this._input;
133
+ var lt1 = stream.LT(1);
134
+ if (lt1.type !== AdaLexer.IDENTIFIER_) {
135
+ if (this._debug) process.stderr.write("IsTypeName: LT(1) is not IDENTIFIER_, returning false\n");
136
+ return false;
137
+ }
138
+ // Collect dotted name — but for lookup use just first component
139
+ var firstName = lt1.text;
140
+ var resolved = this._st.resolve(firstName);
141
+ if (resolved !== null && resolved.classification.has(TypeClassification.TypeName_)) {
142
+ if (this._debug) process.stderr.write("IsTypeName: " + firstName + " resolved as TypeName_, returning true\n");
143
+ return true;
144
+ }
145
+ if (this._debug) process.stderr.write("IsTypeName: " + firstName + " not a type name, returning false\n");
146
+ return false;
147
+ }
148
+
149
+ EnterDeclaration() {
150
+ if (this._debug) process.stderr.write("EnterDeclaration\n");
151
+ var context = this._ctx;
152
+ for (; context !== null; context = context.parentCtx) {
153
+ if (context instanceof AdaParser.Full_type_declarationContext) {
154
+ var defId = context.defining_identifier();
155
+ if (defId !== null) {
156
+ var name = defId.getText();
157
+ var isComposite = false;
158
+ var typeDef = context.type_definition();
159
+ if (typeDef !== null) {
160
+ isComposite = typeDef.record_type_definition() !== null
161
+ || typeDef.array_type_definition() !== null;
162
+ }
163
+ this._defineSymbol(name, TypeClassification.TypeName_, defId.start, isComposite);
164
+ }
165
+ return;
166
+ }
167
+ if (context instanceof AdaParser.Subtype_declarationContext) {
168
+ var defId = context.defining_identifier();
169
+ if (defId !== null) {
170
+ var name = defId.getText();
171
+ var isComposite = false;
172
+ var si = context.subtype_indication();
173
+ if (si !== null) {
174
+ var sm = si.subtype_mark();
175
+ if (sm !== null) {
176
+ var baseSym = this._st.resolve(sm.getText());
177
+ if (baseSym !== null) isComposite = baseSym.isComposite;
178
+ }
179
+ }
180
+ this._defineSymbol(name, TypeClassification.TypeName_, defId.start, isComposite);
181
+ }
182
+ return;
183
+ }
184
+ if (context instanceof AdaParser.Object_declarationContext) {
185
+ var defIdList = context.defining_identifier_list();
186
+ if (defIdList !== null) {
187
+ var defIds = defIdList.defining_identifier();
188
+ for (var di of defIds) {
189
+ this._defineSymbol(di.getText(), TypeClassification.ObjectName_, di.start);
190
+ }
191
+ }
192
+ return;
193
+ }
194
+ if (context instanceof AdaParser.Number_declarationContext) {
195
+ var defIdList = context.defining_identifier_list();
196
+ if (defIdList !== null) {
197
+ var defIds = defIdList.defining_identifier();
198
+ for (var di of defIds) {
199
+ this._defineSymbol(di.getText(), TypeClassification.ObjectName_, di.start);
200
+ }
201
+ }
202
+ return;
203
+ }
204
+ if (context instanceof AdaParser.Subprogram_declarationContext) {
205
+ this._defineSubprogramFromSpec(context.subprogram_specification());
206
+ return;
207
+ }
208
+ if (context instanceof AdaParser.Subprogram_bodyContext) {
209
+ this._defineSubprogramFromSpec(context.subprogram_specification());
210
+ return;
211
+ }
212
+ if (context instanceof AdaParser.Package_declarationContext) {
213
+ var pkgSpec = context.package_specification();
214
+ if (pkgSpec !== null) {
215
+ var dpun = pkgSpec.defining_program_unit_name();
216
+ if (dpun !== null) {
217
+ var defId = dpun.defining_identifier();
218
+ if (defId !== null)
219
+ this._defineSymbol(defId.getText(), TypeClassification.PackageName_, defId.start);
220
+ }
221
+ }
222
+ return;
223
+ }
224
+ if (context instanceof AdaParser.Package_bodyContext) {
225
+ var dpun = context.defining_program_unit_name();
226
+ if (dpun !== null) {
227
+ var defId = dpun.defining_identifier();
228
+ if (defId !== null)
229
+ this._defineSymbol(defId.getText(), TypeClassification.PackageName_, defId.start);
230
+ }
231
+ return;
232
+ }
233
+ if (context instanceof AdaParser.Exception_declarationContext) {
234
+ var defIdList = context.defining_identifier_list();
235
+ if (defIdList !== null) {
236
+ var defIds = defIdList.defining_identifier();
237
+ for (var di of defIds) {
238
+ this._defineSymbol(di.getText(), TypeClassification.ExceptionName_, di.start);
239
+ }
240
+ }
241
+ return;
242
+ }
243
+ if (context instanceof AdaParser.Task_type_declarationContext) {
244
+ var defId = context.defining_identifier();
245
+ if (defId !== null)
246
+ this._defineSymbol(defId.getText(), TypeClassification.TypeName_, defId.start);
247
+ return;
248
+ }
249
+ if (context instanceof AdaParser.Single_task_declarationContext) {
250
+ var defId = context.defining_identifier();
251
+ if (defId !== null)
252
+ this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
253
+ return;
254
+ }
255
+ if (context instanceof AdaParser.Protected_type_declarationContext) {
256
+ var defId = context.defining_identifier();
257
+ if (defId !== null)
258
+ this._defineSymbol(defId.getText(), TypeClassification.TypeName_, defId.start);
259
+ return;
260
+ }
261
+ if (context instanceof AdaParser.Single_protected_declarationContext) {
262
+ var defId = context.defining_identifier();
263
+ if (defId !== null)
264
+ this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
265
+ return;
266
+ }
267
+ if (context instanceof AdaParser.Entry_declarationContext) {
268
+ var defId = context.defining_identifier();
269
+ if (defId !== null)
270
+ this._defineSymbol(defId.getText(), TypeClassification.SubprogramName_, defId.start);
271
+ return;
272
+ }
273
+ if (context instanceof AdaParser.Component_declarationContext) {
274
+ var defIdList = context.defining_identifier_list();
275
+ if (defIdList !== null) {
276
+ var defIds = defIdList.defining_identifier();
277
+ for (var di of defIds) {
278
+ this._defineSymbol(di.getText(), TypeClassification.ComponentName_, di.start);
279
+ }
280
+ }
281
+ return;
282
+ }
283
+ if (context instanceof AdaParser.Incomplete_type_declarationContext) {
284
+ var defId = context.defining_identifier();
285
+ if (defId !== null)
286
+ this._defineSymbol(defId.getText(), TypeClassification.TypeName_, defId.start);
287
+ return;
288
+ }
289
+ if (context instanceof AdaParser.Private_type_declarationContext) {
290
+ var defId = context.defining_identifier();
291
+ if (defId !== null)
292
+ this._defineSymbol(defId.getText(), TypeClassification.TypeName_, defId.start);
293
+ return;
294
+ }
295
+ if (context instanceof AdaParser.Private_extension_declarationContext) {
296
+ var defId = context.defining_identifier();
297
+ if (defId !== null)
298
+ this._defineSymbol(defId.getText(), TypeClassification.TypeName_, defId.start, true);
299
+ return;
300
+ }
301
+ if (context instanceof AdaParser.Generic_instantiationContext) {
302
+ var dpuns = context.defining_program_unit_name();
303
+ if (dpuns !== null && dpuns.length > 0) {
304
+ var dpun = dpuns[0];
305
+ var defId = dpun.defining_identifier();
306
+ if (defId !== null) {
307
+ var tc = TypeClassification.PackageName_;
308
+ if (context.PROCEDURE() !== null) tc = TypeClassification.SubprogramName_;
309
+ else if (context.FUNCTION() !== null) tc = TypeClassification.SubprogramName_;
310
+ this._defineSymbol(defId.getText(), tc, defId.start);
311
+ }
312
+ }
313
+ var dds = context.defining_designator();
314
+ if (dds !== null && dds.length > 0) {
315
+ var dd = dds[0];
316
+ var dpun = dd.defining_program_unit_name();
317
+ if (dpun !== null) {
318
+ var defId = dpun.defining_identifier();
319
+ if (defId !== null)
320
+ this._defineSymbol(defId.getText(), TypeClassification.SubprogramName_, defId.start);
321
+ }
322
+ }
323
+ return;
324
+ }
325
+ if (context instanceof AdaParser.Object_renaming_declarationContext) {
326
+ var defId = context.defining_identifier();
327
+ if (defId !== null)
328
+ this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
329
+ return;
330
+ }
331
+ if (context instanceof AdaParser.Exception_renaming_declarationContext) {
332
+ var defId = context.defining_identifier();
333
+ if (defId !== null)
334
+ this._defineSymbol(defId.getText(), TypeClassification.ExceptionName_, defId.start);
335
+ return;
336
+ }
337
+ if (context instanceof AdaParser.Package_renaming_declarationContext) {
338
+ var dpun = context.defining_program_unit_name();
339
+ if (dpun !== null) {
340
+ var defId = dpun.defining_identifier();
341
+ if (defId !== null)
342
+ this._defineSymbol(defId.getText(), TypeClassification.PackageName_, defId.start);
343
+ }
344
+ return;
345
+ }
346
+ if (context instanceof AdaParser.Formal_complete_type_declarationContext) {
347
+ var defId = context.defining_identifier();
348
+ if (defId !== null)
349
+ this._defineSymbol(defId.getText(), TypeClassification.TypeName_, defId.start);
350
+ return;
351
+ }
352
+ if (context instanceof AdaParser.Formal_incomplete_type_declarationContext) {
353
+ var defId = context.defining_identifier();
354
+ if (defId !== null)
355
+ this._defineSymbol(defId.getText(), TypeClassification.TypeName_, defId.start);
356
+ return;
357
+ }
358
+ if (context instanceof AdaParser.Formal_object_declarationContext) {
359
+ var defIdList = context.defining_identifier_list();
360
+ if (defIdList !== null) {
361
+ var defIds = defIdList.defining_identifier();
362
+ for (var di of defIds) {
363
+ this._defineSymbol(di.getText(), TypeClassification.ObjectName_, di.start);
364
+ }
365
+ }
366
+ return;
367
+ }
368
+ if (context instanceof AdaParser.Formal_package_declarationContext) {
369
+ var defId = context.defining_identifier();
370
+ if (defId !== null)
371
+ this._defineSymbol(defId.getText(), TypeClassification.PackageName_, defId.start);
372
+ return;
373
+ }
374
+ if (context instanceof AdaParser.Parameter_specificationContext) {
375
+ var defIdList = context.defining_identifier_list();
376
+ if (defIdList !== null) {
377
+ var defIds = defIdList.defining_identifier();
378
+ for (var di of defIds) {
379
+ this._defineSymbol(di.getText(), TypeClassification.ObjectName_, di.start);
380
+ }
381
+ }
382
+ return;
383
+ }
384
+ if (context instanceof AdaParser.Loop_parameter_specificationContext) {
385
+ var defId = context.defining_identifier();
386
+ if (defId !== null)
387
+ this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
388
+ return;
389
+ }
390
+ if (context instanceof AdaParser.Iterator_specificationContext) {
391
+ var defId = context.defining_identifier();
392
+ if (defId !== null)
393
+ this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
394
+ return;
395
+ }
396
+ if (context instanceof AdaParser.Enumeration_literal_specificationContext) {
397
+ var defId = context.defining_identifier();
398
+ if (defId !== null)
399
+ this._defineSymbol(defId.getText(), TypeClassification.EnumerationLiteral_, defId.start);
400
+ return;
401
+ }
402
+ if (context instanceof AdaParser.Choice_parameter_specificationContext) {
403
+ var defId = context.defining_identifier();
404
+ if (defId !== null)
405
+ this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
406
+ return;
407
+ }
408
+ if (context instanceof AdaParser.Entry_index_specificationContext) {
409
+ var defId = context.defining_identifier();
410
+ if (defId !== null)
411
+ this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
412
+ return;
413
+ }
414
+ if (context instanceof AdaParser.Extended_return_object_declarationContext) {
415
+ var defId = context.defining_identifier();
416
+ if (defId !== null)
417
+ this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
418
+ return;
419
+ }
420
+ if (context instanceof AdaParser.Entry_bodyContext) {
421
+ var defId = context.defining_identifier();
422
+ if (defId !== null)
423
+ this._defineSymbol(defId.getText(), TypeClassification.SubprogramName_, defId.start);
424
+ return;
425
+ }
426
+ if (context instanceof AdaParser.Task_bodyContext) {
427
+ var defId = context.defining_identifier();
428
+ if (defId !== null)
429
+ this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
430
+ return;
431
+ }
432
+ if (context instanceof AdaParser.Protected_bodyContext) {
433
+ var defId = context.defining_identifier();
434
+ if (defId !== null)
435
+ this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
436
+ return;
437
+ }
438
+ if (context instanceof AdaParser.Discriminant_specificationContext) {
439
+ var defIdList = context.defining_identifier_list();
440
+ if (defIdList !== null) {
441
+ var defIds = defIdList.defining_identifier();
442
+ for (var di of defIds) {
443
+ this._defineSymbol(di.getText(), TypeClassification.ObjectName_, di.start);
444
+ }
445
+ }
446
+ return;
447
+ }
448
+ }
449
+ }
450
+
451
+ _defineSubprogramFromSpec(spec) {
452
+ if (spec === null) return;
453
+ var procSpec = spec.procedure_specification();
454
+ if (procSpec !== null) {
455
+ var dpun = procSpec.defining_program_unit_name();
456
+ if (dpun !== null) {
457
+ var defId = dpun.defining_identifier();
458
+ if (defId !== null)
459
+ this._defineSymbol(defId.getText(), TypeClassification.SubprogramName_, defId.start);
460
+ }
461
+ return;
462
+ }
463
+ var funcSpec = spec.function_specification();
464
+ if (funcSpec !== null) {
465
+ var dd = funcSpec.defining_designator();
466
+ if (dd !== null) {
467
+ var dpun = dd.defining_program_unit_name();
468
+ if (dpun !== null) {
469
+ var defId = dpun.defining_identifier();
470
+ if (defId !== null)
471
+ this._defineSymbol(defId.getText(), TypeClassification.SubprogramName_, defId.start);
472
+ }
473
+ }
474
+ }
475
+ }
476
+
477
+ _defineSymbol(name, classification, token, isComposite) {
478
+ var s = new Symbol();
479
+ s.name = name;
480
+ s.classification = new Set([classification]);
481
+ s.isComposite = isComposite || false;
482
+ s.definedFile = (token && token.source && token.source[0]) ? token.source[0].sourceName || "" : "";
483
+ s.definedLine = token ? token.line || 0 : 0;
484
+ s.definedColumn = token ? token.column || 0 : 0;
485
+ this._st.define(s);
486
+ if (this._debug) process.stderr.write("Defined symbol: " + s.toString() + "\n");
487
+ }
488
+
489
+ EnterScope() {
490
+ if (this._debug) process.stderr.write("EnterScope\n");
491
+ this._st.pushBlockScope();
492
+ }
493
+
494
+ ExitScope() {
495
+ if (this._debug) process.stderr.write("ExitScope\n");
496
+ this._st.popBlockScope();
497
+ }
498
+
499
+ PushExpectedType() {
500
+ this._expectedTypeStack.push(null);
501
+ }
502
+
503
+ PopExpectedType() {
504
+ if (this._expectedTypeStack.length > 0) {
505
+ this._expectedTypeStack.pop();
506
+ if (this._debug) process.stderr.write("PopExpectedType\n");
507
+ }
508
+ }
509
+
510
+ OutputSymbolTable() {
511
+ if (this._outputSymbolTable) {
512
+ process.stderr.write(this._st.toString());
513
+ }
514
+ }
515
+
516
+ ImportWithClause() {
517
+ if (this._noSemantics.has("IsTypeName") && this._noSemantics.has("IsAggregate")) return;
518
+
519
+ // Auto-detect current file from the token stream if not already set
520
+ if (!this._currentFile) {
521
+ var stream = this._input;
522
+ var sourceName = stream && stream.tokenSource && stream.tokenSource.inputStream ? stream.tokenSource.inputStream.name : null;
523
+ if (sourceName && sourceName !== "unknown" && fs.existsSync(sourceName)) {
524
+ this._currentFile = pathModule.resolve(sourceName);
525
+ }
526
+ }
527
+
528
+ var context = this._ctx;
529
+ var names = null;
530
+ if (context instanceof AdaParser.Nonlimited_with_clauseContext) {
531
+ names = context.name();
532
+ } else if (context instanceof AdaParser.Limited_with_clauseContext) {
533
+ names = context.name();
534
+ }
535
+ if (!names || names.length === 0) return;
536
+
537
+ for (var ni = 0; ni < names.length; ni++) {
538
+ var nameCtx = names[ni];
539
+ var packageName = nameCtx.getText();
540
+ if (this._debug) process.stderr.write("ImportWithClause: processing 'with " + packageName + "'\n");
541
+
542
+ var fileName = this._packageNameToFileName(packageName);
543
+ var cacheKey = packageName.toLowerCase();
544
+
545
+ if (AdaParserBase._packageCache.has(cacheKey)) {
546
+ if (this._debug) process.stderr.write("ImportWithClause: using cached symbols for " + packageName + "\n");
547
+ var cachedSymbols = AdaParserBase._packageCache.get(cacheKey);
548
+ for (var ci = 0; ci < cachedSymbols.length; ci++) {
549
+ var sym = cachedSymbols[ci];
550
+ var copy = new Symbol();
551
+ copy.name = sym.name;
552
+ copy.classification = new Set(sym.classification);
553
+ copy.isComposite = sym.isComposite;
554
+ copy.definedFile = sym.definedFile;
555
+ copy.definedLine = sym.definedLine;
556
+ copy.definedColumn = sym.definedColumn;
557
+ this._st.define(copy);
558
+ }
559
+ continue;
560
+ }
561
+
562
+ var adsPath = this._findAdsFile(fileName);
563
+ if (adsPath === null) {
564
+ if (this._debug) process.stderr.write("ImportWithClause: could not find " + fileName + "\n");
565
+ continue;
566
+ }
567
+
568
+ var fullPath = pathModule.resolve(adsPath).toLowerCase();
569
+ if (AdaParserBase._parsingInProgress.has(fullPath)) {
570
+ if (this._debug) process.stderr.write("ImportWithClause: skipping " + fileName + " (cycle detected)\n");
571
+ continue;
572
+ }
573
+
574
+ var symbols = this._parseAdsFile(adsPath);
575
+ if (symbols !== null) {
576
+ AdaParserBase._packageCache.set(cacheKey, symbols);
577
+ for (var si = 0; si < symbols.length; si++) {
578
+ var sym = symbols[si];
579
+ var copy = new Symbol();
580
+ copy.name = sym.name;
581
+ copy.classification = new Set(sym.classification);
582
+ copy.isComposite = sym.isComposite;
583
+ copy.definedFile = sym.definedFile;
584
+ copy.definedLine = sym.definedLine;
585
+ copy.definedColumn = sym.definedColumn;
586
+ this._st.define(copy);
587
+ if (this._debug) process.stderr.write("ImportWithClause: imported symbol " + sym.name + " from " + packageName + "\n");
588
+ }
589
+ }
590
+ }
591
+ }
592
+
593
+ _packageNameToFileName(packageName) {
594
+ return packageName.toLowerCase().replace(/\./g, '-') + ".ads";
595
+ }
596
+
597
+ _findAdsFile(fileName) {
598
+ if (this._currentFile) {
599
+ var dir = pathModule.dirname(this._currentFile);
600
+ var candidate = pathModule.join(dir, fileName);
601
+ if (fs.existsSync(candidate)) return candidate;
602
+ }
603
+ for (var i = 0; i < this._searchPaths.length; i++) {
604
+ var candidate = pathModule.join(this._searchPaths[i], fileName);
605
+ if (fs.existsSync(candidate)) return candidate;
606
+ }
607
+ return null;
608
+ }
609
+
610
+ _parseAdsFile(adsPath) {
611
+ var fullPath = pathModule.resolve(adsPath).toLowerCase();
612
+ AdaParserBase._parsingInProgress.add(fullPath);
613
+ try {
614
+ if (this._debug) process.stderr.write("ImportWithClause: parsing " + adsPath + "\n");
615
+ var input = new antlr4.CharStream(fs.readFileSync(adsPath, 'utf-8'));
616
+ var lexer = new AdaLexer(input);
617
+ lexer.removeErrorListeners();
618
+ var tokenStream = new antlr4.CommonTokenStream(lexer);
619
+ var parser = new AdaParser(tokenStream);
620
+ parser.removeErrorListeners();
621
+ parser._currentFile = pathModule.resolve(adsPath);
622
+ parser.compilation();
623
+ return parser._st.getExportedSymbols();
624
+ } catch (ex) {
625
+ if (this._debug) process.stderr.write("ImportWithClause: error parsing " + adsPath + ": " + ex.message + "\n");
626
+ return null;
627
+ } finally {
628
+ AdaParserBase._parsingInProgress.delete(fullPath);
629
+ }
630
+ }
631
+
632
+ ParsePragmas() {
633
+ var stream = this._input;
634
+ stream.fill();
635
+ var allTokens = stream.tokens;
636
+ var PRAGMA_CHANNEL = 2;
637
+ var currentPragma = null;
638
+ var pragmas = [];
639
+ for (var i = 0; i < allTokens.length; i++) {
640
+ var token = allTokens[i];
641
+ if (token.channel !== PRAGMA_CHANNEL) continue;
642
+ if (token.type === AdaLexer.PRAGMA) {
643
+ currentPragma = [token];
644
+ } else if (currentPragma !== null) {
645
+ currentPragma.push(token);
646
+ if (token.type === AdaLexer.SEMI) {
647
+ pragmas.push(currentPragma);
648
+ currentPragma = null;
649
+ }
650
+ }
651
+ }
652
+ for (var j = 0; j < pragmas.length; j++) {
653
+ var pragmaTokens = pragmas[j];
654
+ var defaultChannelTokens = [];
655
+ for (var k = 0; k < pragmaTokens.length; k++) {
656
+ var t = pragmaTokens[k];
657
+ var ct = new antlr4.CommonToken(t.source, t.type, antlr4.Token.DEFAULT_CHANNEL, t.start, t.stop);
658
+ ct.text = t.text;
659
+ ct.line = t.line;
660
+ ct.column = t.column;
661
+ ct.tokenIndex = t.tokenIndex;
662
+ defaultChannelTokens.push(ct);
663
+ }
664
+ var eof = new antlr4.CommonToken([null, null], antlr4.Token.EOF, antlr4.Token.DEFAULT_CHANNEL, -1, -1);
665
+ defaultChannelTokens.push(eof);
666
+ var tokenSource = new SimpleTokenSource(defaultChannelTokens);
667
+ var tokenStream = new antlr4.CommonTokenStream(tokenSource);
668
+ var parser = new AdaParser(tokenStream);
669
+ parser.removeErrorListeners();
670
+ var listeners = this._listeners;
671
+ if (listeners) {
672
+ for (var l = 0; l < listeners.length; l++) {
673
+ parser.addErrorListener(listeners[l]);
674
+ }
675
+ }
676
+ parser.pragmaRule();
677
+ }
678
+ }
679
+ }
680
+
681
+ AdaParserBase._packageCache = new Map();
682
+ AdaParserBase._parsingInProgress = new Set();