cariboujs 2.0.3 → 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 (82) hide show
  1. package/README.md +330 -324
  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 +846 -603
  21. package/c/CLexerBase.js +96 -0
  22. package/c/CParser.js +8798 -4776
  23. package/c/CParserBase.js +591 -0
  24. package/c/{CListener.js → CParserListener.js} +382 -112
  25. package/c/{CVisitor.js → CParserVisitor.js} +252 -72
  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/cql3/CqlLexer.js +708 -692
  34. package/cql3/CqlParser.js +3356 -2802
  35. package/cql3/CqlParserListener.js +36 -0
  36. package/cql3/CqlParserVisitor.js +24 -0
  37. package/csharp/v7/CSharpLexer.js +1339 -0
  38. package/csharp/v7/CSharpLexerBase.js +332 -0
  39. package/csharp/v7/CSharpParser.js +29239 -0
  40. package/csharp/v7/CSharpParserBase.js +48 -0
  41. package/csharp/v7/CSharpParserListener.js +2304 -0
  42. package/csharp/v7/CSharpParserVisitor.js +1540 -0
  43. package/csharp/v8-spec/CSharpLexer.js +1549 -0
  44. package/csharp/v8-spec/CSharpLexerBase.js +296 -0
  45. package/csharp/v8-spec/CSharpParser.js +45044 -0
  46. package/csharp/v8-spec/CSharpParserBase.js +569 -0
  47. package/csharp/v8-spec/CSharpParserListener.js +3582 -0
  48. package/csharp/v8-spec/CSharpParserVisitor.js +2392 -0
  49. package/geekcode/geekcodeLexer.js +232 -0
  50. package/geekcode/geekcodeListener.js +81 -0
  51. package/geekcode/geekcodeParser.js +1516 -0
  52. package/geekcode/geekcodeVisitor.js +58 -0
  53. package/kotlin/kotlin/KotlinLexer.js +1257 -1247
  54. package/kotlin/kotlin/KotlinParser.js +3991 -3425
  55. package/kotlin/kotlin/KotlinParserListener.js +36 -0
  56. package/kotlin/kotlin/KotlinParserVisitor.js +24 -0
  57. package/package.json +1 -1
  58. package/plantUML/PlantUMLLexer.js +215 -316
  59. package/plantUML/PlantUMLParser.js +1045 -2393
  60. package/plantUML/PlantUMLParserListener.js +171 -0
  61. package/plantUML/PlantUMLParserVisitor.js +118 -0
  62. package/sql/cockroachdb/CockroachDBLexer.js +3865 -0
  63. package/sql/cockroachdb/CockroachDBParser.js +123259 -0
  64. package/sql/cockroachdb/CockroachDBParserListener.js +7281 -0
  65. package/sql/cockroachdb/CockroachDBParserVisitor.js +4858 -0
  66. package/sql/plsql/PlSqlParser.js +27187 -42911
  67. package/sql/plsql/PlSqlParserBase.js +30 -0
  68. package/sql/plsql/PlSqlParserListener.js +0 -9
  69. package/sql/plsql/PlSqlParserVisitor.js +0 -6
  70. package/sql/snowflake/SnowflakeLexer.js +5675 -5497
  71. package/sql/snowflake/SnowflakeParser.js +27230 -22653
  72. package/sql/snowflake/SnowflakeParserListener.js +278 -8
  73. package/sql/snowflake/SnowflakeParserVisitor.js +184 -4
  74. package/sql/sqlite/SQLiteParser.js +1115 -1115
  75. package/sql/sqlite/SQLiteParserListener.js +9 -9
  76. package/sql/sqlite/SQLiteParserVisitor.js +6 -6
  77. package/sysml-v2/SysMLv2Lexer.js +1047 -0
  78. package/sysml-v2/SysMLv2Parser.js +51339 -0
  79. package/sysml-v2/SysMLv2ParserListener.js +4464 -0
  80. package/sysml-v2/SysMLv2ParserVisitor.js +2980 -0
  81. package/plantUML/PlantUMLListener.js +0 -279
  82. package/plantUML/PlantUMLVisitor.js +0 -190
@@ -0,0 +1,296 @@
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
+
8
+ // Preprocessor state
9
+ this._pending = [];
10
+ this._symbols = new Set();
11
+ this._condition = [];
12
+ this._taken = [];
13
+
14
+ // Expression evaluator cursor
15
+ this._expr = [];
16
+ this._epos = 0;
17
+
18
+ this._initPreprocessor();
19
+ }
20
+
21
+ // -------------------------------------------------------------------------
22
+ // Mode-stack helpers
23
+ // -------------------------------------------------------------------------
24
+
25
+ PeekMode() {
26
+ const stack = this._modeStack;
27
+ return (stack && stack.length > 0) ? stack[stack.length - 1] : this.DEFAULT_MODE;
28
+ }
29
+
30
+ popMode() {
31
+ if (!this._modeStack || this._modeStack.length === 0) {
32
+ console.error("unbalanced ()/{}/[]");
33
+ return this.DEFAULT_MODE;
34
+ }
35
+ return super.popMode();
36
+ }
37
+
38
+ PeekModeIs(mode) {
39
+ return this.PeekMode() === mode;
40
+ }
41
+
42
+ LookAheadIs(pos, value) {
43
+ return this.inputStream.LA(pos) === value;
44
+ }
45
+
46
+ LookAheadIsNot(pos, value) {
47
+ return this.inputStream.LA(pos) !== value;
48
+ }
49
+
50
+ LookAheadIsRBrace1() { return this.inputStream.LA(1) === 125; }
51
+ LookAheadIsNotLBrace2() { return this.inputStream.LA(2) !== 123; }
52
+ PeekModeIsIrsCont() { return this.PeekModeIs(CSharpLexer.IRS_CONT); }
53
+ PeekModeIsIvsCont() { return this.PeekModeIs(CSharpLexer.IVS_CONT); }
54
+
55
+ WrapToken() {
56
+ this.text = "\u3014" + this.text.replace(/\u3015/g, "\u3015\u3015") + "\u3015";
57
+ }
58
+
59
+ // -------------------------------------------------------------------------
60
+ // Preprocessor initialisation
61
+ // -------------------------------------------------------------------------
62
+ _initPreprocessor() {
63
+ for (const arg of process.argv) {
64
+ if (arg.startsWith("--D")) {
65
+ for (const sym of arg.substring(3).split(';')) {
66
+ if (sym.length > 0) this._symbols.add(sym);
67
+ }
68
+ }
69
+ }
70
+ }
71
+
72
+ _isActive() {
73
+ return this._condition.length === 0
74
+ || this._condition[this._condition.length - 1];
75
+ }
76
+
77
+ // -------------------------------------------------------------------------
78
+ // nextToken override — intercepts DIRECTIVE-channel tokens
79
+ // -------------------------------------------------------------------------
80
+ nextToken() {
81
+ if (this._pending.length > 0) return this._pending.shift();
82
+
83
+ const tok = super.nextToken();
84
+
85
+ if (tok.channel === CSharpLexer.DIRECTIVE) {
86
+ let skipped = null;
87
+ switch (tok.type) {
88
+ case CSharpLexer.DEFINE: this._handleDefine(); break;
89
+ case CSharpLexer.UNDEF: this._handleUndef(); break;
90
+ case CSharpLexer.KW_IF: skipped = this._handleIf(); break;
91
+ case CSharpLexer.ELIF: skipped = this._handleElif(); break;
92
+ case CSharpLexer.KW_ELSE: skipped = this._handleElse(); break;
93
+ case CSharpLexer.ENDIF: this._handleEndif(); break;
94
+ }
95
+ if (skipped !== null) this._pending.push(skipped);
96
+ }
97
+
98
+ return tok;
99
+ }
100
+
101
+ // -------------------------------------------------------------------------
102
+ // Directive handlers
103
+ // -------------------------------------------------------------------------
104
+ _handleDefine() {
105
+ const line = this._collectLine();
106
+ const sym = this._symbolFromLine(line);
107
+ if (this._isActive() && sym !== null) this._symbols.add(sym);
108
+ }
109
+
110
+ _handleUndef() {
111
+ const line = this._collectLine();
112
+ const sym = this._symbolFromLine(line);
113
+ if (this._isActive() && sym !== null) this._symbols.delete(sym);
114
+ }
115
+
116
+ _handleIf() {
117
+ const line = this._collectLine();
118
+ const outer = this._isActive();
119
+ const result = outer && this._evaluate(line);
120
+ this._condition.push(result);
121
+ this._taken.push(result);
122
+ return result ? null : this._skipFalseBlock();
123
+ }
124
+
125
+ _handleElif() {
126
+ const line = this._collectLine();
127
+ const alreadyTaken = this._taken.length > 0 ? this._taken.pop() : false;
128
+ if (this._condition.length > 0) this._condition.pop();
129
+ const outer = this._isActive();
130
+ const result = !alreadyTaken && outer && this._evaluate(line);
131
+ this._condition.push(result);
132
+ this._taken.push(alreadyTaken || result);
133
+ return result ? null : this._skipFalseBlock();
134
+ }
135
+
136
+ _handleElse() {
137
+ this._collectLine();
138
+ const alreadyTaken = this._taken.length > 0 ? this._taken.pop() : false;
139
+ if (this._condition.length > 0) this._condition.pop();
140
+ const outer = this._isActive();
141
+ const result = !alreadyTaken && outer;
142
+ this._condition.push(result);
143
+ this._taken.push(true);
144
+ return result ? null : this._skipFalseBlock();
145
+ }
146
+
147
+ _handleEndif() {
148
+ this._collectLine();
149
+ if (this._condition.length > 0) this._condition.pop();
150
+ if (this._taken.length > 0) this._taken.pop();
151
+ }
152
+
153
+ // -------------------------------------------------------------------------
154
+ // _collectLine — drain DIRECTIVE_MODE tokens up to DIRECTIVE_NEW_LINE
155
+ // -------------------------------------------------------------------------
156
+ _collectLine() {
157
+ const tokens = [];
158
+ let t;
159
+ do {
160
+ t = super.nextToken();
161
+ if (t.channel !== antlr4.Lexer.HIDDEN)
162
+ tokens.push(t);
163
+ } while (t.type !== CSharpLexer.DIRECTIVE_NEW_LINE && t.type !== antlr4.Token.EOF);
164
+ return tokens;
165
+ }
166
+
167
+ _symbolFromLine(line) {
168
+ for (const t of line)
169
+ if (t.type === CSharpLexer.CONDITIONAL_SYMBOL) return t.text;
170
+ return null;
171
+ }
172
+
173
+ // -------------------------------------------------------------------------
174
+ // _skipFalseBlock — scan char stream, return SKIPPED_SECTION on HIDDEN channel
175
+ // -------------------------------------------------------------------------
176
+ _skipFalseBlock() {
177
+ let text = "";
178
+ const stream = this.inputStream;
179
+ let depth = 1;
180
+ let atLineStart = true;
181
+ const startLine = this.line;
182
+
183
+ while (true) {
184
+ const c = stream.LA(1);
185
+ if (c === antlr4.Token.EOF) break;
186
+
187
+ if (c === 0x0D || c === 0x0A || c === 0x85 || c === 0x2028 || c === 0x2029) {
188
+ stream.consume();
189
+ text += String.fromCodePoint(c);
190
+ if (c === 0x0D && stream.LA(1) === 0x0A) {
191
+ stream.consume();
192
+ text += '\n';
193
+ }
194
+ atLineStart = true;
195
+ continue;
196
+ }
197
+
198
+ if (atLineStart && (c === 0x20 || c === 0x09)) {
199
+ stream.consume();
200
+ text += String.fromCodePoint(c);
201
+ continue;
202
+ }
203
+
204
+ if (atLineStart && c === 0x23 /* '#' */) {
205
+ const kw = this._peekKeyword();
206
+ if (kw === "if") {
207
+ depth++;
208
+ } else if (kw === "endif") {
209
+ if (--depth === 0) break;
210
+ } else if ((kw === "else" || kw === "elif") && depth === 1) {
211
+ break;
212
+ }
213
+ }
214
+
215
+ atLineStart = false;
216
+ stream.consume();
217
+ text += String.fromCodePoint(c);
218
+ }
219
+
220
+ const tok = new antlr4.CommonToken([this, this.inputStream], CSharpLexer.SKIPPED_SECTION,
221
+ antlr4.Lexer.HIDDEN, -1, -1);
222
+ tok.text = text;
223
+ tok.line = startLine;
224
+ return tok;
225
+ }
226
+
227
+ _peekKeyword() {
228
+ let i = 2; // LA(1) is '#'
229
+ while (this.inputStream.LA(i) === 0x20 || this.inputStream.LA(i) === 0x09) i++;
230
+ let kw = "";
231
+ let c;
232
+ while ((c = this.inputStream.LA(i)) !== -1
233
+ && ((c >= 0x61 && c <= 0x7A) || (c >= 0x41 && c <= 0x5A))) {
234
+ kw += String.fromCodePoint(c);
235
+ i++;
236
+ }
237
+ return kw;
238
+ }
239
+
240
+ // -------------------------------------------------------------------------
241
+ // Recursive-descent expression evaluator
242
+ // -------------------------------------------------------------------------
243
+ _evaluate(tokens) {
244
+ this._expr = tokens;
245
+ this._epos = 0;
246
+ return this._parseOr();
247
+ }
248
+
249
+ _peekType() {
250
+ if (this._epos < this._expr.length) {
251
+ const t = this._expr[this._epos].type;
252
+ if (t !== CSharpLexer.DIRECTIVE_NEW_LINE && t !== antlr4.Token.EOF) return t;
253
+ }
254
+ return -1;
255
+ }
256
+
257
+ _eConsume() { return this._expr[this._epos++]; }
258
+
259
+ _parseOr() {
260
+ let v = this._parseAnd();
261
+ while (this._peekType() === CSharpLexer.TK_OR_OR) { this._eConsume(); v = this._parseAnd() || v; }
262
+ return v;
263
+ }
264
+
265
+ _parseAnd() {
266
+ let v = this._parseEq();
267
+ while (this._peekType() === CSharpLexer.TK_AND_AND) { this._eConsume(); v = this._parseEq() && v; }
268
+ return v;
269
+ }
270
+
271
+ _parseEq() {
272
+ const v = this._parseUnary();
273
+ if (this._peekType() === CSharpLexer.TK_EQ_EQ) { this._eConsume(); return v === this._parseUnary(); }
274
+ if (this._peekType() === CSharpLexer.TK_NOT_EQ) { this._eConsume(); return v !== this._parseUnary(); }
275
+ return v;
276
+ }
277
+
278
+ _parseUnary() {
279
+ if (this._peekType() === CSharpLexer.TK_NOT) { this._eConsume(); return !this._parseUnary(); }
280
+ return this._parsePrimary();
281
+ }
282
+
283
+ _parsePrimary() {
284
+ const t = this._peekType();
285
+ if (t === CSharpLexer.TRUE) { this._eConsume(); return true; }
286
+ if (t === CSharpLexer.FALSE) { this._eConsume(); return false; }
287
+ if (t === CSharpLexer.CONDITIONAL_SYMBOL) { return this._symbols.has(this._eConsume().text ?? ""); }
288
+ if (t === CSharpLexer.TK_LPAREN) {
289
+ this._eConsume();
290
+ const v = this._parseOr();
291
+ if (this._peekType() === CSharpLexer.TK_RPAREN) this._eConsume();
292
+ return v;
293
+ }
294
+ return false;
295
+ }
296
+ }