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,50 @@
1
+ import antlr4 from 'antlr4';
2
+ import CLexer from './CLexer.js';
3
+ import * as fs from 'fs';
4
+
5
+ export class ErrorListener extends antlr4.error.ErrorListener {
6
+ constructor(quiet, tee, out) {
7
+ super();
8
+ this.had_error = false;
9
+ this._quiet = quiet;
10
+ this._tee = tee;
11
+ this._out = out;
12
+ }
13
+
14
+ syntaxError(recognizer, offendingSymbol, line, column, msg, e) {
15
+ let fileName = "<unknown>";
16
+ let lineAdjusted = line;
17
+
18
+ if (recognizer instanceof antlr4.Parser) {
19
+ const ts2 = recognizer._input;
20
+ const ind = offendingSymbol.tokenIndex;
21
+ for (let j = ind; j >= 0; j--) {
22
+ const t = ts2.get(j);
23
+ if (t === null) break;
24
+ if (t.type === CLexer.LineDirective) {
25
+ const txt = t.text;
26
+ const parts = txt.split(/\s+/);
27
+ if (parts.length >= 3) {
28
+ const dirLine = parseInt(parts[1], 10);
29
+ if (!isNaN(dirLine)) {
30
+ const lineDirective = t.line;
31
+ const lineDiff = line - lineDirective;
32
+ lineAdjusted = lineDiff + dirLine - 1;
33
+ fileName = parts[2].trim();
34
+ }
35
+ }
36
+ break;
37
+ }
38
+ }
39
+ }
40
+ this.had_error = true;
41
+ if (this._tee && this._out !== null) {
42
+ fs.writeSync(this._out, fileName + " line " + lineAdjusted + ", .p " + line + ":" + column + " " + msg + "\n");
43
+ }
44
+ if (!this._quiet) {
45
+ console.error(fileName + " line " + lineAdjusted + ", .p " + line + ":" + column + " " + msg);
46
+ }
47
+ }
48
+ }
49
+
50
+ export default ErrorListener;
package/c/Symbol.js ADDED
@@ -0,0 +1,28 @@
1
+ import { TypeClassification, TypeClassificationNames } from "./TypeClassification.js";
2
+
3
+ export class Symbol {
4
+ constructor() {
5
+ this.name = "";
6
+ this.classification = new Set();
7
+ this.members = new Map();
8
+ this.parent = null;
9
+ this.predefined = false;
10
+ this.definedFile = "";
11
+ this.definedLine = 0;
12
+ this.definedColumn = 0;
13
+ }
14
+
15
+ toString() {
16
+ let result = this.name;
17
+ const classificationStr = Array.from(this.classification)
18
+ .map(c => TypeClassificationNames[c] || String(c))
19
+ .join(", ");
20
+ result += " (with classification " + classificationStr + ")";
21
+ if (this.definedFile && this.definedFile.length > 0) {
22
+ result += " defined at " + this.definedFile + ":" + this.definedLine + ":" + this.definedColumn;
23
+ }
24
+ return result;
25
+ }
26
+ }
27
+
28
+ export default Symbol;
@@ -0,0 +1,220 @@
1
+ import { Symbol } from "./Symbol.js";
2
+ import { TypeClassification } from "./TypeClassification.js";
3
+
4
+ export class SymbolTable {
5
+ constructor() {
6
+ this.scopeStack = [];
7
+ this.blockCounter = 0;
8
+
9
+ const globalScope = this._createSymbol("global", TypeClassification.Global_);
10
+ this.scopeStack.push(globalScope);
11
+
12
+ this.define(this._createSymbol("auto", TypeClassification.StorageClassSpecifier_));
13
+ this.define(this._createSymbol("constexpr", TypeClassification.StorageClassSpecifier_));
14
+ this.define(this._createSymbol("extern", TypeClassification.StorageClassSpecifier_));
15
+ this.define(this._createSymbol("register", TypeClassification.StorageClassSpecifier_));
16
+ this.define(this._createSymbol("static", TypeClassification.StorageClassSpecifier_));
17
+ this.define(this._createSymbol("thread_local", TypeClassification.StorageClassSpecifier_));
18
+ this.define(this._createSymbol("_Thread_local", TypeClassification.StorageClassSpecifier_));
19
+ this.define(this._createSymbol("typedef", TypeClassification.StorageClassSpecifier_));
20
+
21
+ this.define(this._createSymbol("enum", TypeClassification.EnumSpecifier_));
22
+
23
+ this.define(this._createSymbol("struct", TypeClassification.StorageClassSpecifier_));
24
+ this.define(this._createSymbol("union", TypeClassification.StorageClassSpecifier_));
25
+
26
+ this.define(this._createSymbol("const", TypeClassification.TypeQualifier_));
27
+ this.define(this._createSymbol("restrict", TypeClassification.TypeQualifier_));
28
+ this.define(this._createSymbol("volatile", TypeClassification.TypeQualifier_));
29
+ this.define(this._createSymbolMulti("_Atomic", TypeClassification.TypeQualifier_, TypeClassification.AtomicTypeSpecifier_));
30
+
31
+ this.define(this._createSymbol("void", TypeClassification.TypeSpecifier_));
32
+ this.define(this._createSymbol("char", TypeClassification.TypeSpecifier_));
33
+ this.define(this._createSymbol("short", TypeClassification.TypeSpecifier_));
34
+ this.define(this._createSymbol("int", TypeClassification.TypeSpecifier_));
35
+ this.define(this._createSymbol("long", TypeClassification.TypeSpecifier_));
36
+ this.define(this._createSymbol("float", TypeClassification.TypeSpecifier_));
37
+ this.define(this._createSymbol("double", TypeClassification.TypeSpecifier_));
38
+ this.define(this._createSymbol("signed", TypeClassification.TypeSpecifier_));
39
+ this.define(this._createSymbol("__signed__", TypeClassification.TypeSpecifier_));
40
+ this.define(this._createSymbol("unsigned", TypeClassification.TypeSpecifier_));
41
+ this.define(this._createSymbol("_BitInt", TypeClassification.TypeSpecifier_));
42
+ this.define(this._createSymbol("bool", TypeClassification.TypeSpecifier_));
43
+ this.define(this._createSymbol("_Bool", TypeClassification.TypeSpecifier_));
44
+ this.define(this._createSymbol("_Complex", TypeClassification.TypeSpecifier_));
45
+ this.define(this._createSymbol("_Decimal32", TypeClassification.TypeSpecifier_));
46
+ this.define(this._createSymbol("_Decimal64", TypeClassification.TypeSpecifier_));
47
+ this.define(this._createSymbol("_Decimal128", TypeClassification.TypeSpecifier_));
48
+ this.define(this._createSymbol("__m128", TypeClassification.TypeSpecifier_));
49
+ this.define(this._createSymbol("__m128d", TypeClassification.TypeSpecifier_));
50
+ this.define(this._createSymbol("__m128i", TypeClassification.TypeSpecifier_));
51
+ this.define(this._createSymbol("__extension__", TypeClassification.TypeSpecifier_));
52
+
53
+ this.define(this._createSymbol("__builtin_va_list", TypeClassification.TypeSpecifier_));
54
+ this.define(this._createSymbol("__builtin_has_attribute", TypeClassification.TypeSpecifier_));
55
+ this.define(this._createSymbol("__builtin_speculation_safe_value", TypeClassification.TypeSpecifier_));
56
+ this.define(this._createSymbol("__builtin_types_compatible_p", TypeClassification.TypeSpecifier_));
57
+ this.define(this._createSymbol("__builtin_choose_expr", TypeClassification.TypeSpecifier_));
58
+ this.define(this._createSymbol("__builtin_tgmath", TypeClassification.TypeSpecifier_));
59
+ this.define(this._createSymbol("__builtin_constant_p", TypeClassification.TypeSpecifier_));
60
+ this.define(this._createSymbol("__builtin_is_constant_evaluated", TypeClassification.TypeSpecifier_));
61
+ this.define(this._createSymbol("__builtin_bit_cast", TypeClassification.TypeSpecifier_));
62
+ this.define(this._createSymbol("__builtin_expect", TypeClassification.TypeSpecifier_));
63
+ this.define(this._createSymbol("__builtin_expect_with_probability", TypeClassification.TypeSpecifier_));
64
+ this.define(this._createSymbol("__builtin_trap", TypeClassification.TypeSpecifier_));
65
+ this.define(this._createSymbol("__builtin_assoc_barrier", TypeClassification.TypeSpecifier_));
66
+ this.define(this._createSymbol("__builtin_assume_aligned", TypeClassification.TypeSpecifier_));
67
+ this.define(this._createSymbol("__builtin_LINE", TypeClassification.TypeSpecifier_));
68
+ this.define(this._createSymbol("__builtin_FUNCTION", TypeClassification.TypeSpecifier_));
69
+ this.define(this._createSymbol("__builtin_FILE", TypeClassification.TypeSpecifier_));
70
+ this.define(this._createSymbol("__builtin___clear_cache", TypeClassification.TypeSpecifier_));
71
+ this.define(this._createSymbol("__builtin_prefetch", TypeClassification.Function_));
72
+ this.define(this._createSymbol("__builtin_classify_type", TypeClassification.TypeSpecifier_));
73
+ this.define(this._createSymbol("__builtin_extend_pointer", TypeClassification.TypeSpecifier_));
74
+ this.define(this._createSymbol("__builtin_goacc_parlevel_id", TypeClassification.TypeSpecifier_));
75
+ this.define(this._createSymbol("__builtin_goacc_parlevel_size", TypeClassification.TypeSpecifier_));
76
+
77
+ this.define(this._createSymbol("inline", TypeClassification.FunctionSpecifier_));
78
+ this.define(this._createSymbol("_Noreturn", TypeClassification.FunctionSpecifier_));
79
+ this.define(this._createSymbol("__inline__", TypeClassification.FunctionSpecifier_));
80
+
81
+ this.define(this._createSymbol("__cdecl", TypeClassification.FunctionSpecifier_));
82
+ this.define(this._createSymbol("__clrcall", TypeClassification.FunctionSpecifier_));
83
+ this.define(this._createSymbol("__stdcall", TypeClassification.FunctionSpecifier_));
84
+ this.define(this._createSymbol("__fastcall", TypeClassification.FunctionSpecifier_));
85
+ this.define(this._createSymbol("__thiscall", TypeClassification.FunctionSpecifier_));
86
+ this.define(this._createSymbol("__vectorcall", TypeClassification.FunctionSpecifier_));
87
+
88
+ this.define(this._createSymbol("_purecall", TypeClassification.TypeSpecifier_));
89
+ this.define(this._createSymbol("_purecall_handler", TypeClassification.TypeSpecifier_));
90
+ this.define(this._createSymbol("_onexit_t", TypeClassification.TypeSpecifier_));
91
+ this.define(this._createSymbol("_locale_t", TypeClassification.TypeSpecifier_));
92
+ this.define(this._createSymbol("_invalid_parameter_handler", TypeClassification.TypeSpecifier_));
93
+ this.define(this._createSymbol("__inline", TypeClassification.TypeSpecifier_));
94
+
95
+ this.define(this._createSymbol("__int8", TypeClassification.TypeSpecifier_));
96
+ this.define(this._createSymbol("__int16", TypeClassification.TypeSpecifier_));
97
+ this.define(this._createSymbol("__int32", TypeClassification.TypeSpecifier_));
98
+ this.define(this._createSymbol("__int64", TypeClassification.TypeSpecifier_));
99
+ this.define(this._createSymbol("__int128", TypeClassification.TypeSpecifier_));
100
+ this.define(this._createSymbol("_Float16", TypeClassification.TypeSpecifier_));
101
+ this.define(this._createSymbol("_Float32", TypeClassification.TypeSpecifier_));
102
+ this.define(this._createSymbol("_Float64", TypeClassification.TypeSpecifier_));
103
+ this.define(this._createSymbol("_Float128", TypeClassification.TypeSpecifier_));
104
+ this.define(this._createSymbol("_Float16x", TypeClassification.TypeSpecifier_));
105
+ this.define(this._createSymbol("_Float32x", TypeClassification.TypeSpecifier_));
106
+ this.define(this._createSymbol("_Float64x", TypeClassification.TypeSpecifier_));
107
+ this.define(this._createSymbol("_Float128x", TypeClassification.TypeSpecifier_));
108
+ this.define(this._createSymbol("__v8hf", TypeClassification.TypeSpecifier_));
109
+ this.define(this._createSymbol("__bf16", TypeClassification.TypeSpecifier_));
110
+ this.define(this._createSymbol("__v16bf", TypeClassification.TypeSpecifier_));
111
+
112
+ this.define(this._createSymbol("__declspec", TypeClassification.FunctionSpecifier_));
113
+ this.define(this._createSymbol("__attribute__", TypeClassification.FunctionSpecifier_));
114
+
115
+ this.define(this._createSymbol("alignas", TypeClassification.AlignmentSpecifier_));
116
+ this.define(this._createSymbol("align", TypeClassification.AlignmentSpecifier_));
117
+ }
118
+
119
+ _createSymbol(name, classification) {
120
+ const symbol = new Symbol();
121
+ symbol.name = name;
122
+ symbol.classification = new Set([classification]);
123
+ symbol.predefined = true;
124
+ return symbol;
125
+ }
126
+
127
+ _createSymbolMulti(name, ...classifications) {
128
+ const symbol = new Symbol();
129
+ symbol.name = name;
130
+ symbol.classification = new Set(classifications);
131
+ symbol.predefined = true;
132
+ return symbol;
133
+ }
134
+
135
+ enterScope(newScope) {
136
+ const current = this.scopeStack[this.scopeStack.length - 1];
137
+ if (newScope === current) return;
138
+ this.scopeStack.push(newScope);
139
+ }
140
+
141
+ exitScope() {
142
+ this.scopeStack.pop();
143
+ if (this.scopeStack.length === 0) {
144
+ throw new Error("Cannot exit global scope");
145
+ }
146
+ }
147
+
148
+ currentScope() {
149
+ if (this.scopeStack.length === 0) return null;
150
+ return this.scopeStack[this.scopeStack.length - 1];
151
+ }
152
+
153
+ define(symbol) {
154
+ const currentScope = this.currentScope();
155
+ if (!currentScope) return false;
156
+ return this.defineInScope(currentScope, symbol);
157
+ }
158
+
159
+ defineInScope(currentScope, symbol) {
160
+ if (currentScope.members.has(symbol.name)) {
161
+ return false;
162
+ }
163
+ symbol.parent = currentScope;
164
+ currentScope.members.set(symbol.name, symbol);
165
+ return true;
166
+ }
167
+
168
+ resolve(name, startScope = null) {
169
+ if (startScope === null) {
170
+ for (let i = this.scopeStack.length - 1; i >= 0; i--) {
171
+ const scope = this.scopeStack[i];
172
+ const symbol = scope.members.get(name);
173
+ if (symbol) {
174
+ return symbol;
175
+ }
176
+ }
177
+ return null;
178
+ } else {
179
+ return startScope.members.get(name) || null;
180
+ }
181
+ }
182
+
183
+ pushBlockScope() {
184
+ const blockScope = new Symbol();
185
+ blockScope.name = "block" + (++this.blockCounter);
186
+ blockScope.classification = new Set([TypeClassification.Block_]);
187
+ blockScope.predefined = true;
188
+ this.enterScope(blockScope);
189
+ return blockScope;
190
+ }
191
+
192
+ popBlockScope() {
193
+ this.exitScope();
194
+ }
195
+
196
+ toString() {
197
+ let result = "";
198
+ if (this.scopeStack.length > 0) {
199
+ result = this._toStringHelper(this.scopeStack[0], 0);
200
+ }
201
+ return result;
202
+ }
203
+
204
+ _toStringHelper(scope, depth) {
205
+ let result = "";
206
+ const indent = " ".repeat(depth);
207
+ for (const [key, sym] of scope.members) {
208
+ if (!sym.predefined) {
209
+ result += indent + sym.toString() + "\n";
210
+ }
211
+ if (sym.classification.has(TypeClassification.Block_) ||
212
+ sym.classification.has(TypeClassification.Function_)) {
213
+ result += this._toStringHelper(sym, depth + 1);
214
+ }
215
+ }
216
+ return result;
217
+ }
218
+ }
219
+
220
+ export default SymbolTable;
@@ -0,0 +1,21 @@
1
+ const TypeClassification = Object.freeze({
2
+ Global_: 0,
3
+ Block_: 1,
4
+ Function_: 2,
5
+ Variable_: 3,
6
+ TypeSpecifier_: 4,
7
+ StorageClassSpecifier_: 5,
8
+ TypeQualifier_: 6,
9
+ FunctionSpecifier_: 7,
10
+ AlignmentSpecifier_: 8,
11
+ AtomicTypeSpecifier_: 9,
12
+ EnumSpecifier_: 10
13
+ });
14
+
15
+ // Reverse mapping for toString
16
+ const TypeClassificationNames = Object.freeze(
17
+ Object.fromEntries(Object.entries(TypeClassification).map(([k, v]) => [v, k]))
18
+ );
19
+
20
+ export { TypeClassification, TypeClassificationNames };
21
+ export default TypeClassification;