textbringer-tree-sitter 1.2.0 → 1.2.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.
data/samples/sample.js ADDED
@@ -0,0 +1,266 @@
1
+ // Line comment
2
+ /* Block comment */
3
+ /** JSDoc comment */
4
+
5
+ // --- Variables & Constants ---
6
+ const PI = 3.14159;
7
+ let count = 0;
8
+ var legacy = "old style";
9
+
10
+ // --- Strings ---
11
+ const simple = "double quoted";
12
+ const single = 'single quoted';
13
+ const template = `Hello, ${count + 1} world!`;
14
+ const multiline = `
15
+ Multi-line
16
+ template string
17
+ `;
18
+ const escaped = "tab\tnewline\nnull\0";
19
+ const regex = /pattern[a-z]+/gi;
20
+
21
+ // --- Numbers ---
22
+ const integer = 42;
23
+ const float = 3.14;
24
+ const negative = -17;
25
+ const hex = 0xFF;
26
+ const octal = 0o77;
27
+ const binary = 0b1010;
28
+ const bigint = 9007199254740991n;
29
+ const scientific = 1.5e10;
30
+ const separator = 1_000_000;
31
+
32
+ // --- Booleans & Special ---
33
+ const yes = true;
34
+ const no = false;
35
+ const nothing = null;
36
+ const notDefined = undefined;
37
+
38
+ // --- Functions ---
39
+ function greet(name) {
40
+ return `Hello, ${name}!`;
41
+ }
42
+
43
+ function* fibonacci() {
44
+ let a = 0, b = 1;
45
+ while (true) {
46
+ yield a;
47
+ [a, b] = [b, a + b];
48
+ }
49
+ }
50
+
51
+ async function fetchData(url) {
52
+ const response = await fetch(url);
53
+ return await response.json();
54
+ }
55
+
56
+ const arrow = (x) => x * 2;
57
+ const arrowMultiline = (a, b) => {
58
+ const sum = a + b;
59
+ return sum;
60
+ };
61
+
62
+ // --- Classes ---
63
+ class Animal {
64
+ #name;
65
+ static count = 0;
66
+
67
+ constructor(name) {
68
+ this.#name = name;
69
+ Animal.count++;
70
+ }
71
+
72
+ get name() {
73
+ return this.#name;
74
+ }
75
+
76
+ set name(value) {
77
+ this.#name = value;
78
+ }
79
+
80
+ speak() {
81
+ return `${this.#name} makes a sound`;
82
+ }
83
+
84
+ toString() {
85
+ return `Animal(${this.#name})`;
86
+ }
87
+ }
88
+
89
+ class Dog extends Animal {
90
+ #breed;
91
+
92
+ constructor(name, breed) {
93
+ super(name);
94
+ this.#breed = breed;
95
+ }
96
+
97
+ speak() {
98
+ return `${this.name} barks!`;
99
+ }
100
+ }
101
+
102
+ // --- Objects & Arrays ---
103
+ const obj = {
104
+ key: "value",
105
+ nested: {
106
+ a: 1,
107
+ b: [2, 3, 4],
108
+ },
109
+ method() {
110
+ return this.key;
111
+ },
112
+ get computed() {
113
+ return this.key.toUpperCase();
114
+ },
115
+ };
116
+
117
+ const arr = [1, 2, 3, ...obj.nested.b];
118
+ const { key, nested: { a } } = obj;
119
+ const [first, ...rest] = arr;
120
+
121
+ // --- Control flow ---
122
+ if (count > 0) {
123
+ console.log("positive");
124
+ } else if (count < 0) {
125
+ console.log("negative");
126
+ } else {
127
+ console.log("zero");
128
+ }
129
+
130
+ switch (count) {
131
+ case 0:
132
+ console.log("zero");
133
+ break;
134
+ case 1:
135
+ console.log("one");
136
+ break;
137
+ default:
138
+ console.log("other");
139
+ break;
140
+ }
141
+
142
+ // --- Loops ---
143
+ for (let i = 0; i < 10; i++) {
144
+ if (i === 5) break;
145
+ if (i === 3) continue;
146
+ }
147
+
148
+ for (const item of arr) {
149
+ console.log(item);
150
+ }
151
+
152
+ for (const key in obj) {
153
+ console.log(key, obj[key]);
154
+ }
155
+
156
+ let j = 10;
157
+ while (j > 0) {
158
+ j--;
159
+ }
160
+
161
+ do {
162
+ j++;
163
+ } while (j < 5);
164
+
165
+ // --- Operators ---
166
+ const sum = 1 + 2;
167
+ const diff = 5 - 3;
168
+ const prod = 4 * 2;
169
+ const quot = 10 / 3;
170
+ const mod = 10 % 3;
171
+ const exp = 2 ** 8;
172
+ const logic = true && false || !null;
173
+ const nullCoalesce = nothing ?? "default";
174
+ const optionalChain = obj?.nested?.a;
175
+ const ternary = count > 0 ? "yes" : "no";
176
+ const typeCheck = typeof count;
177
+ const instanceCheck = obj instanceof Object;
178
+ void 0;
179
+ delete obj.key;
180
+
181
+ // --- Exception handling ---
182
+ try {
183
+ throw new Error("oops");
184
+ } catch (err) {
185
+ console.error(err.message);
186
+ } finally {
187
+ console.log("cleanup");
188
+ }
189
+
190
+ // --- Promises ---
191
+ const promise = new Promise((resolve, reject) => {
192
+ setTimeout(() => resolve("done"), 1000);
193
+ });
194
+
195
+ promise
196
+ .then(result => console.log(result))
197
+ .catch(err => console.error(err))
198
+ .finally(() => console.log("finished"));
199
+
200
+ // --- Modules ---
201
+ import { readFile } from 'fs';
202
+ import * as path from 'path';
203
+ import defaultExport from 'module';
204
+
205
+ export const exported = "value";
206
+ export default class ExportedClass {}
207
+ export { greet, arrow as doubler };
208
+
209
+ // --- Destructuring & Spread ---
210
+ const cloned = { ...obj, extra: true };
211
+ const merged = [...arr, 5, 6];
212
+
213
+ // --- Optional chaining & nullish ---
214
+ const safe = obj?.nested?.missing ?? "fallback";
215
+
216
+ // --- Tagged template ---
217
+ function tag(strings, ...values) {
218
+ return strings.join("") + values.join("");
219
+ }
220
+ const tagged = tag`Hello ${count} world`;
221
+
222
+ // --- Symbol ---
223
+ const sym = Symbol("unique");
224
+ const iter = Symbol.iterator;
225
+
226
+ // --- WeakRef & FinalizationRegistry ---
227
+ const ref = new WeakRef(obj);
228
+ const registry = new FinalizationRegistry(value => {
229
+ console.log(`Collected: ${value}`);
230
+ });
231
+
232
+ // --- Async iteration ---
233
+ async function* asyncGenerator() {
234
+ yield 1;
235
+ yield 2;
236
+ yield 3;
237
+ }
238
+
239
+ // --- Labeled statement ---
240
+ outer:
241
+ for (let i = 0; i < 3; i++) {
242
+ for (let j = 0; j < 3; j++) {
243
+ if (j === 1) continue outer;
244
+ if (i === 2) break outer;
245
+ }
246
+ }
247
+
248
+ // --- with (deprecated but valid) ---
249
+ with (Math) {
250
+ const r = random();
251
+ }
252
+
253
+ // --- debugger ---
254
+ debugger;
255
+
256
+ // --- arguments ---
257
+ function oldStyle() {
258
+ return arguments.length;
259
+ }
260
+
261
+ // --- new.target ---
262
+ function Constructable() {
263
+ if (new.target) {
264
+ this.created = true;
265
+ }
266
+ }
@@ -0,0 +1,68 @@
1
+ {
2
+ "string_value": "Hello, World!",
3
+ "escaped_string": "tab\there\nnewline\\backslash\"quote",
4
+ "unicode_string": "\u0048\u0065\u006C\u006C\u006F",
5
+ "empty_string": "",
6
+ "integer": 42,
7
+ "negative_integer": -17,
8
+ "float": 3.14159,
9
+ "negative_float": -2.71828,
10
+ "scientific": 1.5e10,
11
+ "scientific_negative": -3.14e-2,
12
+ "zero": 0,
13
+ "boolean_true": true,
14
+ "boolean_false": false,
15
+ "null_value": null,
16
+ "empty_object": {},
17
+ "empty_array": [],
18
+ "nested_object": {
19
+ "name": "Alice",
20
+ "age": 30,
21
+ "active": true,
22
+ "address": {
23
+ "street": "123 Main St",
24
+ "city": "Anytown",
25
+ "zip": "12345",
26
+ "coordinates": {
27
+ "lat": 40.7128,
28
+ "lng": -74.0060
29
+ }
30
+ }
31
+ },
32
+ "array_of_strings": ["apple", "banana", "cherry"],
33
+ "array_of_numbers": [1, 2, 3, 4, 5],
34
+ "array_of_booleans": [true, false, true],
35
+ "array_of_objects": [
36
+ {"id": 1, "name": "First"},
37
+ {"id": 2, "name": "Second"},
38
+ {"id": 3, "name": "Third"}
39
+ ],
40
+ "mixed_array": [
41
+ "string",
42
+ 42,
43
+ 3.14,
44
+ true,
45
+ false,
46
+ null,
47
+ {"key": "value"},
48
+ [1, 2, 3]
49
+ ],
50
+ "deeply_nested": {
51
+ "level1": {
52
+ "level2": {
53
+ "level3": {
54
+ "level4": {
55
+ "value": "deep"
56
+ }
57
+ }
58
+ }
59
+ }
60
+ },
61
+ "special_characters": {
62
+ "solidus": "path/to/file",
63
+ "backslash": "C:\\Users\\test",
64
+ "quotes": "She said \"hello\"",
65
+ "control_chars": "line1\nline2\ttab\rreturn",
66
+ "null_byte": "before\u0000after"
67
+ }
68
+ }
@@ -0,0 +1,276 @@
1
+ { Block comment style 1 }
2
+ (* Block comment style 2 *)
3
+ // Line comment
4
+
5
+ program SampleProgram;
6
+
7
+ uses
8
+ SysUtils, Classes, Math;
9
+
10
+ const
11
+ MaxSize = 100;
12
+ Pi = 3.14159;
13
+ Greeting: string = 'Hello, World!';
14
+ NilValue = nil;
15
+
16
+ type
17
+ // --- Enum ---
18
+ TColor = (Red, Green, Blue);
19
+
20
+ // --- Set ---
21
+ TColorSet = set of TColor;
22
+
23
+ // --- Record ---
24
+ TPoint = record
25
+ X: Double;
26
+ Y: Double;
27
+ end;
28
+
29
+ // --- Class ---
30
+ TAnimal = class
31
+ private
32
+ FName: string;
33
+ FAge: Integer;
34
+ protected
35
+ procedure SetName(const Value: string);
36
+ public
37
+ constructor Create(const AName: string; AAge: Integer);
38
+ destructor Destroy; override;
39
+ function Speak: string; virtual; abstract;
40
+ property Name: string read FName write SetName;
41
+ property Age: Integer read FAge;
42
+ end;
43
+
44
+ // --- Inherited class ---
45
+ TDog = class(TAnimal)
46
+ public
47
+ function Speak: string; override;
48
+ end;
49
+
50
+ // --- Interface ---
51
+ IGreetable = interface
52
+ function Greet: string;
53
+ end;
54
+
55
+ // --- Generic class ---
56
+ TContainer<T> = class
57
+ private
58
+ FItems: array of T;
59
+ FCount: Integer;
60
+ public
61
+ procedure Add(const Item: T);
62
+ function Get(Index: Integer): T;
63
+ property Count: Integer read FCount;
64
+ end;
65
+
66
+ // --- Array type ---
67
+ TIntArray = array[0..MaxSize - 1] of Integer;
68
+ TMatrix = array of array of Double;
69
+
70
+ // --- Pointer type ---
71
+ PPoint = ^TPoint;
72
+
73
+ // --- Function type ---
74
+ TCompareFunc = function(A, B: Integer): Integer;
75
+
76
+ var
77
+ GlobalVar: Integer;
78
+ Colors: TColorSet;
79
+
80
+ // --- TAnimal implementation ---
81
+ constructor TAnimal.Create(const AName: string; AAge: Integer);
82
+ begin
83
+ inherited Create;
84
+ FName := AName;
85
+ FAge := AAge;
86
+ end;
87
+
88
+ destructor TAnimal.Destroy;
89
+ begin
90
+ inherited Destroy;
91
+ end;
92
+
93
+ procedure TAnimal.SetName(const Value: string);
94
+ begin
95
+ FName := Value;
96
+ end;
97
+
98
+ // --- TDog implementation ---
99
+ function TDog.Speak: string;
100
+ begin
101
+ Result := 'Woof!';
102
+ end;
103
+
104
+ // --- Generic implementation ---
105
+ procedure TContainer<T>.Add(const Item: T);
106
+ begin
107
+ SetLength(FItems, FCount + 1);
108
+ FItems[FCount] := Item;
109
+ Inc(FCount);
110
+ end;
111
+
112
+ function TContainer<T>.Get(Index: Integer): T;
113
+ begin
114
+ Result := FItems[Index];
115
+ end;
116
+
117
+ // --- Standalone functions ---
118
+ function Add(A, B: Integer): Integer;
119
+ begin
120
+ Result := A + B;
121
+ end;
122
+
123
+ procedure Greet(const Name: string);
124
+ begin
125
+ WriteLn('Hello, ', Name, '!');
126
+ end;
127
+
128
+ function Factorial(N: Integer): Integer;
129
+ begin
130
+ if N <= 1 then
131
+ Result := 1
132
+ else
133
+ Result := N * Factorial(N - 1);
134
+ end;
135
+
136
+ // --- Inline function ---
137
+ function Max(A, B: Integer): Integer; inline;
138
+ begin
139
+ if A > B then
140
+ Result := A
141
+ else
142
+ Result := B;
143
+ end;
144
+
145
+ // --- Main program ---
146
+ var
147
+ I, J, Sum: Integer;
148
+ F: Double;
149
+ S: string;
150
+ Dog: TDog;
151
+ Point: TPoint;
152
+ Arr: TIntArray;
153
+ DynArr: array of Integer;
154
+ begin
155
+ // --- Strings ---
156
+ S := 'Single quoted string';
157
+ WriteLn(S);
158
+
159
+ // --- Numbers ---
160
+ I := 42;
161
+ F := 3.14;
162
+ J := $FF; // Hex
163
+ Sum := %1010; // Binary
164
+
165
+ // --- Boolean ---
166
+ if True then
167
+ WriteLn('true')
168
+ else if False then
169
+ WriteLn('false');
170
+
171
+ // --- Control flow: if/else ---
172
+ if I > 0 then
173
+ WriteLn('positive')
174
+ else if I < 0 then
175
+ WriteLn('negative')
176
+ else
177
+ WriteLn('zero');
178
+
179
+ // --- Case ---
180
+ case I of
181
+ 0: WriteLn('zero');
182
+ 1..10: WriteLn('small');
183
+ 11..100: WriteLn('medium');
184
+ else
185
+ WriteLn('large');
186
+ end;
187
+
188
+ // --- For loop ---
189
+ Sum := 0;
190
+ for I := 1 to 10 do
191
+ Sum := Sum + I;
192
+
193
+ for I := 10 downto 1 do
194
+ WriteLn(I);
195
+
196
+ // --- While loop ---
197
+ I := 0;
198
+ while I < 10 do
199
+ begin
200
+ Inc(I);
201
+ if I = 5 then
202
+ Break;
203
+ if I = 3 then
204
+ Continue;
205
+ end;
206
+
207
+ // --- Repeat/Until ---
208
+ I := 0;
209
+ repeat
210
+ Inc(I);
211
+ until I >= 10;
212
+
213
+ // --- With statement ---
214
+ Point.X := 1.0;
215
+ Point.Y := 2.0;
216
+ with Point do
217
+ WriteLn('X=', X:0:2, ' Y=', Y:0:2);
218
+
219
+ // --- Operators ---
220
+ Sum := 1 + 2;
221
+ Sum := 5 - 3;
222
+ Sum := 4 * 2;
223
+ F := 10 / 3;
224
+ Sum := 10 div 3;
225
+ Sum := 10 mod 3;
226
+ Sum := 1 shl 4;
227
+ Sum := 16 shr 2;
228
+
229
+ if (I > 0) and (J > 0) then
230
+ WriteLn('both positive');
231
+ if (I > 0) or (J > 0) then
232
+ WriteLn('at least one positive');
233
+ if not (I = 0) then
234
+ WriteLn('not zero');
235
+
236
+ // --- Object creation ---
237
+ Dog := TDog.Create('Rex', 5);
238
+ try
239
+ WriteLn(Dog.Name, ': ', Dog.Speak);
240
+ Dog.Name := 'Max';
241
+ finally
242
+ Dog.Free;
243
+ end;
244
+
245
+ // --- Exception handling ---
246
+ try
247
+ raise Exception.Create('Something went wrong');
248
+ except
249
+ on E: Exception do
250
+ WriteLn('Error: ', E.Message);
251
+ end;
252
+
253
+ // --- Dynamic array ---
254
+ SetLength(DynArr, 5);
255
+ for I := 0 to High(DynArr) do
256
+ DynArr[I] := I * I;
257
+
258
+ // --- Set operations ---
259
+ Colors := [Red, Green];
260
+ if Blue in Colors then
261
+ WriteLn('has blue');
262
+ Colors := Colors + [Blue];
263
+ Colors := Colors - [Red];
264
+
265
+ // --- Goto (rare but valid) ---
266
+ goto 999;
267
+ WriteLn('skipped');
268
+ 999:
269
+ WriteLn('jumped here');
270
+
271
+ // --- Exit ---
272
+ if I = 0 then
273
+ Exit;
274
+
275
+ WriteLn('Done!');
276
+ end.