paseo-plugin-genui 0.1.0 → 0.1.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.
- package/client/components/content.tsx +27 -11
- package/client/components/image-lightbox.tsx +110 -0
- package/client/components/inputs.tsx +1 -1
- package/client/components/media.tsx +2 -2
- package/client/live-ui.tsx +2 -2
- package/client/node-renderer.tsx +37 -19
- package/client/web.ts +22 -0
- package/package.json +1 -1
- package/server/data-source.ts +94 -40
- package/shared/core/data.ts +9 -1
- package/shared/core/define-class.ts +36 -0
- package/shared/core/diagnostics.ts +24 -13
- package/shared/core/evaluate.ts +561 -525
- package/shared/core/junit.ts +9 -1
- package/shared/core/lexer.ts +187 -177
- package/shared/core/parser.ts +280 -263
- package/shared/core/validate.ts +366 -356
- package/shared/genui.test.ts +61 -1
- package/shared/hermes-syntax.test.ts +41 -0
package/shared/core/junit.ts
CHANGED
|
@@ -7,9 +7,17 @@
|
|
|
7
7
|
// than its input, so the data loader's size limit bounds the work.
|
|
8
8
|
import { LIMITS } from "./catalog";
|
|
9
9
|
import type { Value } from "./types";
|
|
10
|
+
import { defineClass } from "./define-class";
|
|
10
11
|
|
|
11
12
|
/** A reason the file is not a readable JUnit report, already phrased for the user. */
|
|
12
|
-
export
|
|
13
|
+
export const JUnitError = defineClass(
|
|
14
|
+
function (this: Error, message: string): void {
|
|
15
|
+
this.message = message;
|
|
16
|
+
},
|
|
17
|
+
undefined,
|
|
18
|
+
Error,
|
|
19
|
+
);
|
|
20
|
+
export type JUnitError = InstanceType<typeof JUnitError>;
|
|
13
21
|
|
|
14
22
|
interface XmlElement {
|
|
15
23
|
readonly name: string;
|
package/shared/core/lexer.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DiagnosticList, Pos } from "./diagnostics";
|
|
2
|
+
import { defineClass } from "./define-class";
|
|
2
3
|
|
|
3
4
|
export type Token =
|
|
4
5
|
| (Pos & { readonly t: "num"; readonly value: number })
|
|
@@ -52,203 +53,212 @@ export function tokenize(source: string, diagnostics: DiagnosticList): Token[] {
|
|
|
52
53
|
return new Lexer(source, diagnostics).run(false);
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
private readonly diagnostics: DiagnosticList,
|
|
63
|
-
) {}
|
|
56
|
+
interface LexerFields {
|
|
57
|
+
i: number;
|
|
58
|
+
line: number;
|
|
59
|
+
column: number;
|
|
60
|
+
src: string;
|
|
61
|
+
diagnostics: DiagnosticList;
|
|
62
|
+
}
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
const Lexer = defineClass(
|
|
65
|
+
function (this: LexerFields, src: string, diagnostics: DiagnosticList): void {
|
|
66
|
+
this.src = src;
|
|
67
|
+
this.diagnostics = diagnostics;
|
|
68
|
+
this.i = 0;
|
|
69
|
+
this.line = 1;
|
|
70
|
+
this.column = 1;
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
advance(count = 1): void {
|
|
74
|
+
for (let n = 0; n < count; n++) {
|
|
75
|
+
if (this.src[this.i] === "\n") {
|
|
76
|
+
this.line++;
|
|
77
|
+
this.column = 1;
|
|
78
|
+
} else {
|
|
79
|
+
this.column++;
|
|
80
|
+
}
|
|
81
|
+
this.i++;
|
|
72
82
|
}
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
}
|
|
83
|
+
},
|
|
76
84
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
match(re: RegExp): string | null {
|
|
86
|
+
re.lastIndex = this.i;
|
|
87
|
+
const m = re.exec(this.src);
|
|
88
|
+
return m ? m[0] : null;
|
|
89
|
+
},
|
|
82
90
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
if (c === "\n") {
|
|
100
|
-
this.advance();
|
|
101
|
-
if (!inTemplate && depth === 0) out.push({ ...pos, t: "sep", value: "\n" });
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
if (c === ";") {
|
|
105
|
-
this.advance();
|
|
106
|
-
out.push({ ...pos, t: "sep", value: ";" });
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
if (inTemplate && c === "}" && depth === 0) {
|
|
110
|
-
out.push({ ...pos, t: "eof" });
|
|
111
|
-
this.advance();
|
|
112
|
-
return out;
|
|
113
|
-
}
|
|
114
|
-
const number = this.match(NUMBER);
|
|
115
|
-
if (number !== null) {
|
|
116
|
-
this.advance(number.length);
|
|
117
|
-
if (IDENT_CHAR.test(this.src[this.i] ?? "")) {
|
|
118
|
-
this.diagnostics.report(pos, `invalid number \`${number}${this.src[this.i]}\``);
|
|
91
|
+
/**
|
|
92
|
+
* Top level: tokens until end of input, separators at bracket depth 0.
|
|
93
|
+
* Inside a template `${`: tokens until the matching `}`, no separators.
|
|
94
|
+
*/
|
|
95
|
+
run(inTemplate: boolean): Token[] {
|
|
96
|
+
const out: Token[] = [];
|
|
97
|
+
let depth = 0;
|
|
98
|
+
for (;;) {
|
|
99
|
+
this.skipBlank();
|
|
100
|
+
const pos = { line: this.line, column: this.column };
|
|
101
|
+
const c = this.src[this.i];
|
|
102
|
+
if (c === undefined) {
|
|
103
|
+
if (inTemplate) this.diagnostics.report(pos, "unterminated template: `${` is missing its `}`");
|
|
104
|
+
out.push({ ...pos, t: "eof" });
|
|
105
|
+
return inTemplate ? out : joinContinuations(out);
|
|
119
106
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const ident = this.match(IDENT);
|
|
124
|
-
if (ident !== null) {
|
|
125
|
-
this.advance(ident.length);
|
|
126
|
-
out.push({ ...pos, t: "ident", value: ident });
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
if (c === "$") {
|
|
130
|
-
this.advance();
|
|
131
|
-
while (this.src[this.i] === " " || this.src[this.i] === "\t") this.advance();
|
|
132
|
-
const name = this.match(IDENT);
|
|
133
|
-
if (name === null) {
|
|
134
|
-
this.diagnostics.report(pos, "expected a state name after `$`, as in `$count`");
|
|
107
|
+
if (c === "\n") {
|
|
108
|
+
this.advance();
|
|
109
|
+
if (!inTemplate && depth === 0) out.push({ ...pos, t: "sep", value: "\n" });
|
|
135
110
|
continue;
|
|
136
111
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
112
|
+
if (c === ";") {
|
|
113
|
+
this.advance();
|
|
114
|
+
out.push({ ...pos, t: "sep", value: ";" });
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (inTemplate && c === "}" && depth === 0) {
|
|
118
|
+
out.push({ ...pos, t: "eof" });
|
|
119
|
+
this.advance();
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
const number = this.match(NUMBER);
|
|
123
|
+
if (number !== null) {
|
|
124
|
+
this.advance(number.length);
|
|
125
|
+
if (IDENT_CHAR.test(this.src[this.i] ?? "")) {
|
|
126
|
+
this.diagnostics.report(pos, `invalid number \`${number}${this.src[this.i]}\``);
|
|
127
|
+
}
|
|
128
|
+
out.push({ ...pos, t: "num", value: Number(number.replaceAll("_", "")) });
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const ident = this.match(IDENT);
|
|
132
|
+
if (ident !== null) {
|
|
133
|
+
this.advance(ident.length);
|
|
134
|
+
out.push({ ...pos, t: "ident", value: ident });
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (c === "$") {
|
|
138
|
+
this.advance();
|
|
139
|
+
while (this.src[this.i] === " " || this.src[this.i] === "\t") this.advance();
|
|
140
|
+
const name = this.match(IDENT);
|
|
141
|
+
if (name === null) {
|
|
142
|
+
this.diagnostics.report(pos, "expected a state name after `$`, as in `$count`");
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
this.advance(name.length);
|
|
146
|
+
out.push({ ...pos, t: "state", value: name });
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (c === '"' || c === "'") {
|
|
150
|
+
const value = this.string(c, pos);
|
|
151
|
+
if (value !== null) out.push({ ...pos, t: "str", value });
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (c === "`") {
|
|
155
|
+
out.push(this.template(pos));
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const punct = PUNCTUATION.find((p) => this.src.startsWith(p, this.i));
|
|
159
|
+
if (punct === undefined) {
|
|
160
|
+
this.diagnostics.report(pos, `unexpected character \`${c}\``);
|
|
161
|
+
this.advance();
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (punct === "(" || punct === "[" || punct === "{") depth++;
|
|
165
|
+
if ((punct === ")" || punct === "]" || punct === "}") && depth > 0) depth--;
|
|
166
|
+
this.advance(punct.length);
|
|
167
|
+
out.push({ ...pos, t: "punct", value: punct });
|
|
155
168
|
}
|
|
156
|
-
|
|
157
|
-
if ((punct === ")" || punct === "]" || punct === "}") && depth > 0) depth--;
|
|
158
|
-
this.advance(punct.length);
|
|
159
|
-
out.push({ ...pos, t: "punct", value: punct });
|
|
160
|
-
}
|
|
161
|
-
}
|
|
169
|
+
},
|
|
162
170
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
171
|
+
skipBlank(): void {
|
|
172
|
+
for (;;) {
|
|
173
|
+
const c = this.src[this.i];
|
|
174
|
+
if (c === " " || c === "\t" || c === "\r") {
|
|
175
|
+
this.advance();
|
|
176
|
+
} else if (c === "/" && this.src[this.i + 1] === "/") {
|
|
177
|
+
while (this.i < this.src.length && this.src[this.i] !== "\n") this.advance();
|
|
178
|
+
} else {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
172
181
|
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
182
|
+
},
|
|
175
183
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
this.advance();
|
|
180
|
-
const c = this.src[this.i];
|
|
181
|
-
if (c !== undefined && ESCAPES[c] !== undefined) {
|
|
184
|
+
/** Reads one escape after `\`; returns the decoded text or null after reporting. */
|
|
185
|
+
escape(): string | null {
|
|
186
|
+
const pos = { line: this.line, column: this.column };
|
|
182
187
|
this.advance();
|
|
183
|
-
return ESCAPES[c];
|
|
184
|
-
}
|
|
185
|
-
if (c === "u") {
|
|
186
|
-
const braced = this.src[this.i + 1] === "{";
|
|
187
|
-
const end = braced ? this.src.indexOf("}", this.i + 2) : this.i + 5;
|
|
188
|
-
const hex = braced ? this.src.slice(this.i + 2, end) : this.src.slice(this.i + 1, end);
|
|
189
|
-
const code = parseInt(hex, 16);
|
|
190
|
-
if (end > 0 && HEX.test(hex) && (braced || hex.length === 4) && code <= 0x10ffff) {
|
|
191
|
-
this.advance(end - this.i + (braced ? 1 : 0));
|
|
192
|
-
return String.fromCodePoint(code);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
this.diagnostics.report(pos, `unknown escape \`\\${c ?? ""}\`; use \\n \\t \\\\ \\" \\' \\$ or \\u{hex}`);
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
private string(quote: string, pos: Pos): string | null {
|
|
200
|
-
this.advance();
|
|
201
|
-
let value = "";
|
|
202
|
-
for (;;) {
|
|
203
188
|
const c = this.src[this.i];
|
|
204
|
-
if (c
|
|
205
|
-
this.diagnostics.report(pos, `unterminated string: close it with ${quote} on the same line`);
|
|
206
|
-
return null;
|
|
207
|
-
}
|
|
208
|
-
if (c === quote) {
|
|
189
|
+
if (c !== undefined && ESCAPES[c] !== undefined) {
|
|
209
190
|
this.advance();
|
|
210
|
-
return
|
|
191
|
+
return ESCAPES[c];
|
|
211
192
|
}
|
|
212
|
-
if (c === "
|
|
213
|
-
|
|
214
|
-
|
|
193
|
+
if (c === "u") {
|
|
194
|
+
const braced = this.src[this.i + 1] === "{";
|
|
195
|
+
const end = braced ? this.src.indexOf("}", this.i + 2) : this.i + 5;
|
|
196
|
+
const hex = braced ? this.src.slice(this.i + 2, end) : this.src.slice(this.i + 1, end);
|
|
197
|
+
const code = parseInt(hex, 16);
|
|
198
|
+
if (end > 0 && HEX.test(hex) && (braced || hex.length === 4) && code <= 0x10ffff) {
|
|
199
|
+
this.advance(end - this.i + (braced ? 1 : 0));
|
|
200
|
+
return String.fromCodePoint(code);
|
|
201
|
+
}
|
|
215
202
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
}
|
|
203
|
+
this.diagnostics.report(pos, `unknown escape \`\\${c ?? ""}\`; use \\n \\t \\\\ \\" \\' \\$ or \\u{hex}`);
|
|
204
|
+
return null;
|
|
205
|
+
},
|
|
220
206
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
207
|
+
string(quote: string, pos: Pos): string | null {
|
|
208
|
+
this.advance();
|
|
209
|
+
let value = "";
|
|
210
|
+
for (;;) {
|
|
211
|
+
const c = this.src[this.i];
|
|
212
|
+
if (c === undefined || c === "\n") {
|
|
213
|
+
this.diagnostics.report(pos, `unterminated string: close it with ${quote} on the same line`);
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
if (c === quote) {
|
|
217
|
+
this.advance();
|
|
218
|
+
return value;
|
|
219
|
+
}
|
|
220
|
+
if (c === "\\") {
|
|
221
|
+
value += this.escape() ?? "";
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
value += c;
|
|
234
225
|
this.advance();
|
|
235
|
-
quasis.push(text);
|
|
236
|
-
return { ...pos, t: "tpl", quasis, parts };
|
|
237
226
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
template(pos: Pos): Token {
|
|
230
|
+
this.advance();
|
|
231
|
+
const quasis: string[] = [];
|
|
232
|
+
const parts: Token[][] = [];
|
|
233
|
+
let text = "";
|
|
234
|
+
for (;;) {
|
|
235
|
+
const c = this.src[this.i];
|
|
236
|
+
if (c === undefined) {
|
|
237
|
+
this.diagnostics.report(pos, "unterminated template: close it with `");
|
|
238
|
+
quasis.push(text);
|
|
239
|
+
return { ...pos, t: "tpl", quasis, parts };
|
|
240
|
+
}
|
|
241
|
+
if (c === "`") {
|
|
242
|
+
this.advance();
|
|
243
|
+
quasis.push(text);
|
|
244
|
+
return { ...pos, t: "tpl", quasis, parts };
|
|
245
|
+
}
|
|
246
|
+
if (c === "\\") {
|
|
247
|
+
text += this.escape() ?? "";
|
|
248
|
+
} else if (c === "$" && this.src[this.i + 1] === "{") {
|
|
249
|
+
this.advance(2);
|
|
250
|
+
quasis.push(text);
|
|
251
|
+
text = "";
|
|
252
|
+
parts.push(this.run(true));
|
|
253
|
+
} else {
|
|
254
|
+
text += c;
|
|
255
|
+
this.advance();
|
|
256
|
+
}
|
|
248
257
|
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
);
|
|
261
|
+
type Lexer = InstanceType<typeof Lexer>;
|
|
252
262
|
|
|
253
263
|
/**
|
|
254
264
|
* Drops redundant separators, and newlines that sit between an operator and
|