cariboujs 2.0.4 → 2.0.5

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 (74) hide show
  1. package/README.md +8 -2
  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 +919 -0
  21. package/c/CLexerBase.js +96 -0
  22. package/c/CParser.js +14878 -0
  23. package/c/CParserBase.js +591 -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 +215 -0
  29. package/c/TypeClassification.js +21 -0
  30. package/cpp/CPP14Parser.js +215 -215
  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 +45044 -0
  42. package/csharp/v8-spec/CSharpParserBase.js +569 -0
  43. package/csharp/v8-spec/CSharpParserListener.js +3582 -0
  44. package/csharp/v8-spec/CSharpParserVisitor.js +2392 -0
  45. package/geekcode/geekcodeLexer.js +232 -0
  46. package/geekcode/geekcodeListener.js +81 -0
  47. package/geekcode/geekcodeParser.js +1516 -0
  48. package/geekcode/geekcodeVisitor.js +58 -0
  49. package/kotlin/kotlin/KotlinLexer.js +1257 -1247
  50. package/kotlin/kotlin/KotlinParser.js +3991 -3425
  51. package/kotlin/kotlin/KotlinParserListener.js +36 -0
  52. package/kotlin/kotlin/KotlinParserVisitor.js +24 -0
  53. package/package.json +1 -1
  54. package/plantUML/PlantUMLLexer.js +215 -316
  55. package/plantUML/PlantUMLParser.js +1045 -2393
  56. package/plantUML/PlantUMLParserListener.js +171 -0
  57. package/plantUML/PlantUMLParserVisitor.js +118 -0
  58. package/sql/plsql/PlSqlParser.js +27973 -43771
  59. package/sql/plsql/PlSqlParserBase.js +30 -0
  60. package/sql/plsql/PlSqlParserListener.js +0 -9
  61. package/sql/plsql/PlSqlParserVisitor.js +0 -6
  62. package/sql/snowflake/SnowflakeLexer.js +5675 -5497
  63. package/sql/snowflake/SnowflakeParser.js +27230 -22653
  64. package/sql/snowflake/SnowflakeParserListener.js +278 -8
  65. package/sql/snowflake/SnowflakeParserVisitor.js +184 -4
  66. package/sql/sqlite/SQLiteParser.js +1115 -1115
  67. package/sql/sqlite/SQLiteParserListener.js +9 -9
  68. package/sql/sqlite/SQLiteParserVisitor.js +6 -6
  69. package/sysml-v2/SysMLv2Lexer.js +1047 -0
  70. package/sysml-v2/SysMLv2Parser.js +51339 -0
  71. package/sysml-v2/SysMLv2ParserListener.js +4464 -0
  72. package/sysml-v2/SysMLv2ParserVisitor.js +2980 -0
  73. package/plantUML/PlantUMLListener.js +0 -279
  74. package/plantUML/PlantUMLVisitor.js +0 -190
@@ -0,0 +1,332 @@
1
+ import antlr4 from 'antlr4';
2
+ import CSharpLexer from './CSharpLexer.js';
3
+
4
+ export default class CSharpLexerBase extends antlr4.Lexer {
5
+ constructor(input) {
6
+ super(input);
7
+ this.interpolatedStringLevel = 0;
8
+ this.interpolatedVerbatiums = [];
9
+ this.curlyLevels = [];
10
+ this.verbatium = false;
11
+
12
+ // Preprocessor state
13
+ this._pending = [];
14
+ this._symbols = new Set();
15
+ this._condition = [];
16
+ this._taken = [];
17
+
18
+ // Expression evaluator cursor
19
+ this._expr = [];
20
+ this._epos = 0;
21
+
22
+ this._initPreprocessor();
23
+ }
24
+
25
+ OnInterpolatedRegularStringStart() {
26
+ this.interpolatedStringLevel++;
27
+ this.interpolatedVerbatiums.push(false);
28
+ this.verbatium = false;
29
+ }
30
+
31
+ OnInterpolatedVerbatiumStringStart() {
32
+ this.interpolatedStringLevel++;
33
+ this.interpolatedVerbatiums.push(true);
34
+ this.verbatium = true;
35
+ }
36
+
37
+ OnOpenBrace() {
38
+ if (this.interpolatedStringLevel > 0) {
39
+ this.curlyLevels[this.curlyLevels.length - 1]++;
40
+ }
41
+ }
42
+
43
+ OnCloseBrace() {
44
+ if (this.interpolatedStringLevel > 0) {
45
+ this.curlyLevels[this.curlyLevels.length - 1]--;
46
+ if (this.curlyLevels[this.curlyLevels.length - 1] === 0) {
47
+ this.curlyLevels.pop();
48
+ this.skip();
49
+ this.popMode();
50
+ }
51
+ }
52
+ }
53
+
54
+ OnColon() {
55
+ if (this.interpolatedStringLevel > 0) {
56
+ let ind = 1;
57
+ let switchToFormatString = true;
58
+ while (this.inputStream.LA(ind) !== 0x7D /* } */) {
59
+ const ch = this.inputStream.LA(ind);
60
+ if (ch === 0x3A /* : */ || ch === 0x29 /* ) */) {
61
+ switchToFormatString = false;
62
+ break;
63
+ }
64
+ ind++;
65
+ }
66
+ if (switchToFormatString) {
67
+ this.setMode(CSharpLexer.INTERPOLATION_FORMAT);
68
+ }
69
+ }
70
+ }
71
+
72
+ OpenBraceInside() {
73
+ this.curlyLevels.push(1);
74
+ }
75
+
76
+ OnDoubleQuoteInside() {
77
+ this.interpolatedStringLevel--;
78
+ this.interpolatedVerbatiums.pop();
79
+ this.verbatium = this.interpolatedVerbatiums.length > 0
80
+ && this.interpolatedVerbatiums[this.interpolatedVerbatiums.length - 1];
81
+ }
82
+
83
+ OnCloseBraceInside() {
84
+ this.curlyLevels.pop();
85
+ }
86
+
87
+ IsRegularCharInside() {
88
+ return !this.verbatium;
89
+ }
90
+
91
+ IsVerbatiumDoubleQuoteInside() {
92
+ return this.verbatium;
93
+ }
94
+
95
+ // -------------------------------------------------------------------------
96
+ // Preprocessor initialisation
97
+ // -------------------------------------------------------------------------
98
+ _initPreprocessor() {
99
+ for (const arg of process.argv) {
100
+ if (arg.startsWith("--D")) {
101
+ for (const sym of arg.substring(3).split(';')) {
102
+ if (sym.length > 0) this._symbols.add(sym);
103
+ }
104
+ }
105
+ }
106
+ }
107
+
108
+ _isActive() {
109
+ return this._condition.length === 0
110
+ || this._condition[this._condition.length - 1];
111
+ }
112
+
113
+ // -------------------------------------------------------------------------
114
+ // nextToken override — intercepts DIRECTIVE-channel tokens
115
+ // -------------------------------------------------------------------------
116
+ nextToken() {
117
+ if (this._pending.length > 0) return this._pending.shift();
118
+
119
+ const tok = super.nextToken();
120
+
121
+ if (tok.channel === CSharpLexer.DIRECTIVE) {
122
+ let skipped = null;
123
+ switch (tok.type) {
124
+ case CSharpLexer.DEFINE: this._handleDefine(); break;
125
+ case CSharpLexer.UNDEF: this._handleUndef(); break;
126
+ case CSharpLexer.IF: skipped = this._handleIf(); break;
127
+ case CSharpLexer.ELIF: skipped = this._handleElif(); break;
128
+ case CSharpLexer.ELSE: skipped = this._handleElse(); break;
129
+ case CSharpLexer.ENDIF: this._handleEndif(); break;
130
+ }
131
+ if (skipped !== null) this._pending.push(skipped);
132
+ }
133
+
134
+ return tok;
135
+ }
136
+
137
+ // -------------------------------------------------------------------------
138
+ // Directive handlers
139
+ // -------------------------------------------------------------------------
140
+ _handleDefine() {
141
+ const line = this._collectLine();
142
+ const sym = this._symbolFromLine(line);
143
+ if (this._isActive() && sym !== null) this._symbols.add(sym);
144
+ }
145
+
146
+ _handleUndef() {
147
+ const line = this._collectLine();
148
+ const sym = this._symbolFromLine(line);
149
+ if (this._isActive() && sym !== null) this._symbols.delete(sym);
150
+ }
151
+
152
+ _handleIf() {
153
+ const line = this._collectLine();
154
+ const outer = this._isActive();
155
+ const result = outer && this._evaluate(line);
156
+ this._condition.push(result);
157
+ this._taken.push(result);
158
+ return result ? null : this._skipFalseBlock();
159
+ }
160
+
161
+ _handleElif() {
162
+ const line = this._collectLine();
163
+ const alreadyTaken = this._taken.length > 0 ? this._taken.pop() : false;
164
+ if (this._condition.length > 0) this._condition.pop();
165
+ const outer = this._isActive();
166
+ const result = !alreadyTaken && outer && this._evaluate(line);
167
+ this._condition.push(result);
168
+ this._taken.push(alreadyTaken || result);
169
+ return result ? null : this._skipFalseBlock();
170
+ }
171
+
172
+ _handleElse() {
173
+ this._collectLine();
174
+ const alreadyTaken = this._taken.length > 0 ? this._taken.pop() : false;
175
+ if (this._condition.length > 0) this._condition.pop();
176
+ const outer = this._isActive();
177
+ const result = !alreadyTaken && outer;
178
+ this._condition.push(result);
179
+ this._taken.push(true);
180
+ return result ? null : this._skipFalseBlock();
181
+ }
182
+
183
+ _handleEndif() {
184
+ this._collectLine();
185
+ if (this._condition.length > 0) this._condition.pop();
186
+ if (this._taken.length > 0) this._taken.pop();
187
+ }
188
+
189
+ // -------------------------------------------------------------------------
190
+ // _collectLine — drain DIRECTIVE_MODE tokens up to DIRECTIVE_NEW_LINE
191
+ // -------------------------------------------------------------------------
192
+ _collectLine() {
193
+ const tokens = [];
194
+ let t;
195
+ do {
196
+ t = super.nextToken();
197
+ if (t.channel !== antlr4.Lexer.HIDDEN && t.channel !== CSharpLexer.COMMENTS_CHANNEL)
198
+ tokens.push(t);
199
+ } while (t.type !== CSharpLexer.DIRECTIVE_NEW_LINE && t.type !== antlr4.Token.EOF);
200
+ return tokens;
201
+ }
202
+
203
+ _symbolFromLine(line) {
204
+ for (const t of line)
205
+ if (t.type === CSharpLexer.CONDITIONAL_SYMBOL) return t.text;
206
+ return null;
207
+ }
208
+
209
+ // -------------------------------------------------------------------------
210
+ // _skipFalseBlock — scan char stream, return SKIPPED_SECTION on HIDDEN channel
211
+ // -------------------------------------------------------------------------
212
+ _skipFalseBlock() {
213
+ let text = "";
214
+ const stream = this.inputStream;
215
+ let depth = 1;
216
+ let atLineStart = true;
217
+ const startLine = this.line;
218
+
219
+ while (true) {
220
+ const c = stream.LA(1);
221
+ if (c === antlr4.Token.EOF) break;
222
+
223
+ if (c === 0x0D || c === 0x0A || c === 0x85 || c === 0x2028 || c === 0x2029) {
224
+ stream.consume();
225
+ text += String.fromCodePoint(c);
226
+ if (c === 0x0D && stream.LA(1) === 0x0A) {
227
+ stream.consume();
228
+ text += '\n';
229
+ }
230
+ atLineStart = true;
231
+ continue;
232
+ }
233
+
234
+ if (atLineStart && (c === 0x20 || c === 0x09)) {
235
+ stream.consume();
236
+ text += String.fromCodePoint(c);
237
+ continue;
238
+ }
239
+
240
+ if (atLineStart && c === 0x23 /* '#' */) {
241
+ const kw = this._peekKeyword();
242
+ if (kw === "if") {
243
+ depth++;
244
+ } else if (kw === "endif") {
245
+ if (--depth === 0) break;
246
+ } else if ((kw === "else" || kw === "elif") && depth === 1) {
247
+ break;
248
+ }
249
+ }
250
+
251
+ atLineStart = false;
252
+ stream.consume();
253
+ text += String.fromCodePoint(c);
254
+ }
255
+
256
+ const tok = new antlr4.CommonToken([this, this.inputStream], CSharpLexer.SKIPPED_SECTION,
257
+ antlr4.Lexer.HIDDEN, -1, -1);
258
+ tok.text = text;
259
+ tok.line = startLine;
260
+ return tok;
261
+ }
262
+
263
+ _peekKeyword() {
264
+ let i = 2; // LA(1) is '#'
265
+ while (this.inputStream.LA(i) === 0x20 || this.inputStream.LA(i) === 0x09) i++;
266
+ let kw = "";
267
+ let c;
268
+ while ((c = this.inputStream.LA(i)) !== -1
269
+ && ((c >= 0x61 && c <= 0x7A) || (c >= 0x41 && c <= 0x5A))) {
270
+ kw += String.fromCodePoint(c);
271
+ i++;
272
+ }
273
+ return kw;
274
+ }
275
+
276
+ // -------------------------------------------------------------------------
277
+ // Recursive-descent expression evaluator
278
+ // -------------------------------------------------------------------------
279
+ _evaluate(tokens) {
280
+ this._expr = tokens;
281
+ this._epos = 0;
282
+ return this._parseOr();
283
+ }
284
+
285
+ _peekType() {
286
+ if (this._epos < this._expr.length) {
287
+ const t = this._expr[this._epos].type;
288
+ if (t !== CSharpLexer.DIRECTIVE_NEW_LINE && t !== antlr4.Token.EOF) return t;
289
+ }
290
+ return -1;
291
+ }
292
+
293
+ _eConsume() { return this._expr[this._epos++]; }
294
+
295
+ _parseOr() {
296
+ let v = this._parseAnd();
297
+ while (this._peekType() === CSharpLexer.OP_OR) { this._eConsume(); v = this._parseAnd() || v; }
298
+ return v;
299
+ }
300
+
301
+ _parseAnd() {
302
+ let v = this._parseEq();
303
+ while (this._peekType() === CSharpLexer.OP_AND) { this._eConsume(); v = this._parseEq() && v; }
304
+ return v;
305
+ }
306
+
307
+ _parseEq() {
308
+ const v = this._parseUnary();
309
+ if (this._peekType() === CSharpLexer.OP_EQ) { this._eConsume(); return v === this._parseUnary(); }
310
+ if (this._peekType() === CSharpLexer.OP_NE) { this._eConsume(); return v !== this._parseUnary(); }
311
+ return v;
312
+ }
313
+
314
+ _parseUnary() {
315
+ if (this._peekType() === CSharpLexer.BANG) { this._eConsume(); return !this._parseUnary(); }
316
+ return this._parsePrimary();
317
+ }
318
+
319
+ _parsePrimary() {
320
+ const t = this._peekType();
321
+ if (t === CSharpLexer.TRUE) { this._eConsume(); return true; }
322
+ if (t === CSharpLexer.FALSE) { this._eConsume(); return false; }
323
+ if (t === CSharpLexer.CONDITIONAL_SYMBOL) { return this._symbols.has(this._eConsume().text ?? ""); }
324
+ if (t === CSharpLexer.OPEN_PARENS) {
325
+ this._eConsume();
326
+ const v = this._parseOr();
327
+ if (this._peekType() === CSharpLexer.CLOSE_PARENS) this._eConsume();
328
+ return v;
329
+ }
330
+ return false;
331
+ }
332
+ }