juxscript 1.1.58 → 1.1.59
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.
- package/lib/utils/codeparser.d.ts.map +1 -1
- package/lib/utils/codeparser.js +74 -12
- package/lib/utils/codeparser.ts +68 -13
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codeparser.d.ts","sourceRoot":"","sources":["codeparser.ts"],"names":[],"mappings":"AA2DA,MAAM,WAAW,UAAU;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,iBAAS,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOxC;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAqB,GAAG,UAAU,EAAE,CAQrF;
|
|
1
|
+
{"version":3,"file":"codeparser.d.ts","sourceRoot":"","sources":["codeparser.ts"],"names":[],"mappings":"AA2DA,MAAM,WAAW,UAAU;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,iBAAS,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOxC;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAqB,GAAG,UAAU,EAAE,CAQrF;AAwOD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAEnE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAkG9C;;;;;;;AAED,wBAKE"}
|
package/lib/utils/codeparser.js
CHANGED
|
@@ -105,6 +105,50 @@ function isDelimiter(char) {
|
|
|
105
105
|
function isOperator(char) {
|
|
106
106
|
return '+-*/%=<>!&|^~?'.includes(char);
|
|
107
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Check if character starts a multi-char operator
|
|
110
|
+
*/
|
|
111
|
+
function consumeOperator(line, i) {
|
|
112
|
+
const char = line[i];
|
|
113
|
+
const next = line[i + 1];
|
|
114
|
+
const next2 = line[i + 2];
|
|
115
|
+
// Three-char operators
|
|
116
|
+
if (char === '=' && next === '=' && next2 === '=')
|
|
117
|
+
return '===';
|
|
118
|
+
if (char === '!' && next === '=' && next2 === '=')
|
|
119
|
+
return '!==';
|
|
120
|
+
if (char === '>' && next === '>' && next2 === '>')
|
|
121
|
+
return '>>>';
|
|
122
|
+
// Two-char operators
|
|
123
|
+
if (char === '=' && next === '=')
|
|
124
|
+
return '==';
|
|
125
|
+
if (char === '!' && next === '=')
|
|
126
|
+
return '!=';
|
|
127
|
+
if (char === '<' && next === '=')
|
|
128
|
+
return '<=';
|
|
129
|
+
if (char === '>' && next === '=')
|
|
130
|
+
return '>=';
|
|
131
|
+
if (char === '&' && next === '&')
|
|
132
|
+
return '&&';
|
|
133
|
+
if (char === '|' && next === '|')
|
|
134
|
+
return '||';
|
|
135
|
+
if (char === '+' && next === '+')
|
|
136
|
+
return '++';
|
|
137
|
+
if (char === '-' && next === '-')
|
|
138
|
+
return '--';
|
|
139
|
+
if (char === '=' && next === '>')
|
|
140
|
+
return '=>';
|
|
141
|
+
if (char === '>' && next === '>')
|
|
142
|
+
return '>>';
|
|
143
|
+
if (char === '<' && next === '<')
|
|
144
|
+
return '<<';
|
|
145
|
+
if (char === '*' && next === '*')
|
|
146
|
+
return '**';
|
|
147
|
+
if (char === '.' && next === '.' && next2 === '.')
|
|
148
|
+
return '...';
|
|
149
|
+
// Single-char operator
|
|
150
|
+
return char;
|
|
151
|
+
}
|
|
108
152
|
/**
|
|
109
153
|
* Tokenize a single line character-by-character with semantic categories
|
|
110
154
|
*/
|
|
@@ -147,13 +191,30 @@ function tokenizeLine(line) {
|
|
|
147
191
|
}
|
|
148
192
|
// String literals (single, double, backtick)
|
|
149
193
|
if (char === '"' || char === "'" || char === '`') {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
194
|
+
let j = i + 1;
|
|
195
|
+
let escaped = false;
|
|
196
|
+
// Find matching quote
|
|
197
|
+
while (j < len) {
|
|
198
|
+
if (escaped) {
|
|
199
|
+
escaped = false;
|
|
200
|
+
j++;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (line[j] === '\\') {
|
|
204
|
+
escaped = true;
|
|
205
|
+
j++;
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
if (line[j] === char) {
|
|
209
|
+
j++;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
j++;
|
|
156
213
|
}
|
|
214
|
+
const str = line.slice(i, j);
|
|
215
|
+
result += `<span class="token-string">${escapeHtml(str)}</span>`;
|
|
216
|
+
i = j;
|
|
217
|
+
continue;
|
|
157
218
|
}
|
|
158
219
|
// Word (identifier or keyword)
|
|
159
220
|
if (/[a-zA-Z_$]/.test(char)) {
|
|
@@ -176,6 +237,13 @@ function tokenizeLine(line) {
|
|
|
176
237
|
i += num.length;
|
|
177
238
|
continue;
|
|
178
239
|
}
|
|
240
|
+
// Operators (multi-char)
|
|
241
|
+
if (isOperator(char)) {
|
|
242
|
+
const op = consumeOperator(line, i);
|
|
243
|
+
result += `<span class="token-operator">${escapeHtml(op)}</span>`;
|
|
244
|
+
i += op.length;
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
179
247
|
// Structural punctuation (braces, brackets, parens)
|
|
180
248
|
if (isStructural(char)) {
|
|
181
249
|
result += `<span class="token-structural">${escapeHtml(char)}</span>`;
|
|
@@ -188,12 +256,6 @@ function tokenizeLine(line) {
|
|
|
188
256
|
i++;
|
|
189
257
|
continue;
|
|
190
258
|
}
|
|
191
|
-
// Operators
|
|
192
|
-
if (isOperator(char)) {
|
|
193
|
-
result += `<span class="token-operator">${escapeHtml(char)}</span>`;
|
|
194
|
-
i++;
|
|
195
|
-
continue;
|
|
196
|
-
}
|
|
197
259
|
// Everything else - just escape and append
|
|
198
260
|
result += escapeHtml(char);
|
|
199
261
|
i++;
|
package/lib/utils/codeparser.ts
CHANGED
|
@@ -121,6 +121,38 @@ function isOperator(char: string): boolean {
|
|
|
121
121
|
return '+-*/%=<>!&|^~?'.includes(char);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Check if character starts a multi-char operator
|
|
126
|
+
*/
|
|
127
|
+
function consumeOperator(line: string, i: number): string {
|
|
128
|
+
const char = line[i];
|
|
129
|
+
const next = line[i + 1];
|
|
130
|
+
const next2 = line[i + 2];
|
|
131
|
+
|
|
132
|
+
// Three-char operators
|
|
133
|
+
if (char === '=' && next === '=' && next2 === '=') return '===';
|
|
134
|
+
if (char === '!' && next === '=' && next2 === '=') return '!==';
|
|
135
|
+
if (char === '>' && next === '>' && next2 === '>') return '>>>';
|
|
136
|
+
|
|
137
|
+
// Two-char operators
|
|
138
|
+
if (char === '=' && next === '=') return '==';
|
|
139
|
+
if (char === '!' && next === '=') return '!=';
|
|
140
|
+
if (char === '<' && next === '=') return '<=';
|
|
141
|
+
if (char === '>' && next === '=') return '>=';
|
|
142
|
+
if (char === '&' && next === '&') return '&&';
|
|
143
|
+
if (char === '|' && next === '|') return '||';
|
|
144
|
+
if (char === '+' && next === '+') return '++';
|
|
145
|
+
if (char === '-' && next === '-') return '--';
|
|
146
|
+
if (char === '=' && next === '>') return '=>';
|
|
147
|
+
if (char === '>' && next === '>') return '>>';
|
|
148
|
+
if (char === '<' && next === '<') return '<<';
|
|
149
|
+
if (char === '*' && next === '*') return '**';
|
|
150
|
+
if (char === '.' && next === '.' && next2 === '.') return '...';
|
|
151
|
+
|
|
152
|
+
// Single-char operator
|
|
153
|
+
return char;
|
|
154
|
+
}
|
|
155
|
+
|
|
124
156
|
/**
|
|
125
157
|
* Tokenize a single line character-by-character with semantic categories
|
|
126
158
|
*/
|
|
@@ -167,13 +199,35 @@ function tokenizeLine(line: string): string {
|
|
|
167
199
|
|
|
168
200
|
// String literals (single, double, backtick)
|
|
169
201
|
if (char === '"' || char === "'" || char === '`') {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
202
|
+
let j = i + 1;
|
|
203
|
+
let escaped = false;
|
|
204
|
+
|
|
205
|
+
// Find matching quote
|
|
206
|
+
while (j < len) {
|
|
207
|
+
if (escaped) {
|
|
208
|
+
escaped = false;
|
|
209
|
+
j++;
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (line[j] === '\\') {
|
|
214
|
+
escaped = true;
|
|
215
|
+
j++;
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (line[j] === char) {
|
|
220
|
+
j++;
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
j++;
|
|
176
225
|
}
|
|
226
|
+
|
|
227
|
+
const str = line.slice(i, j);
|
|
228
|
+
result += `<span class="token-string">${escapeHtml(str)}</span>`;
|
|
229
|
+
i = j;
|
|
230
|
+
continue;
|
|
177
231
|
}
|
|
178
232
|
|
|
179
233
|
// Word (identifier or keyword)
|
|
@@ -200,6 +254,14 @@ function tokenizeLine(line: string): string {
|
|
|
200
254
|
continue;
|
|
201
255
|
}
|
|
202
256
|
|
|
257
|
+
// Operators (multi-char)
|
|
258
|
+
if (isOperator(char)) {
|
|
259
|
+
const op = consumeOperator(line, i);
|
|
260
|
+
result += `<span class="token-operator">${escapeHtml(op)}</span>`;
|
|
261
|
+
i += op.length;
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
|
|
203
265
|
// Structural punctuation (braces, brackets, parens)
|
|
204
266
|
if (isStructural(char)) {
|
|
205
267
|
result += `<span class="token-structural">${escapeHtml(char)}</span>`;
|
|
@@ -214,13 +276,6 @@ function tokenizeLine(line: string): string {
|
|
|
214
276
|
continue;
|
|
215
277
|
}
|
|
216
278
|
|
|
217
|
-
// Operators
|
|
218
|
-
if (isOperator(char)) {
|
|
219
|
-
result += `<span class="token-operator">${escapeHtml(char)}</span>`;
|
|
220
|
-
i++;
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
279
|
// Everything else - just escape and append
|
|
225
280
|
result += escapeHtml(char);
|
|
226
281
|
i++;
|