@shapeshift-labs/frontier-lang-parser 0.3.57 → 0.3.58
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/dist/index.js +1 -9
- package/dist/type-expressions.js +33 -0
- package/dist/type-variants.js +1 -1
- package/dist/view.js +3 -10
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ import { parseResourceGraphBlock } from './resource-graph.js';
|
|
|
16
16
|
import { parseRuntimeCapabilityBlock } from './runtime-capability.js';
|
|
17
17
|
import { parseNativeSourceBlock } from './source-evidence.js';
|
|
18
18
|
import { parseTargetProjectionMetadata } from './target-projection.js';
|
|
19
|
+
import { parseOptionalTypeExpression, parseTypeExpression } from './type-expressions.js';
|
|
19
20
|
import { readVariantPayloadFields } from './type-variants.js';
|
|
20
21
|
import { parseViewBlock } from './view.js';
|
|
21
22
|
import { FrontierSourceBlockKinds, readFrontierSourceBlocks } from './source-syntax-report.js';
|
|
@@ -280,15 +281,6 @@ function parseSemantic(text) {
|
|
|
280
281
|
if (latticeId) return { kind: 'lattice', latticeId };
|
|
281
282
|
return undefined;
|
|
282
283
|
}
|
|
283
|
-
function parseOptionalTypeExpression(value) { return value ? parseTypeExpression(value.trim()) : undefined; }
|
|
284
|
-
function parseTypeExpression(value) {
|
|
285
|
-
const text = value.trim();
|
|
286
|
-
if (/^Set<.+>$/.test(text)) return { kind: 'set', item: parseTypeExpression(text.slice(4, -1)) };
|
|
287
|
-
if (/^List<.+>$/.test(text)) return { kind: 'list', item: parseTypeExpression(text.slice(5, -1)) };
|
|
288
|
-
const map = /^Map<(.+),\s*(.+)>$/.exec(text);
|
|
289
|
-
if (map) return { kind: 'map', key: parseTypeExpression(map[1]), value: parseTypeExpression(map[2]) };
|
|
290
|
-
return text;
|
|
291
|
-
}
|
|
292
284
|
function readTypeParameters(header) {
|
|
293
285
|
return /<([^>]+)>/.exec(header)?.[1]?.split(',').map((item) => item.trim()).filter(Boolean);
|
|
294
286
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { splitTopLevelCommaList } from './type-variants.js';
|
|
2
|
+
|
|
3
|
+
export function parseOptionalTypeExpression(value) {
|
|
4
|
+
return value ? parseTypeExpression(value.trim()) : undefined;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function parseTypeExpression(value) {
|
|
8
|
+
const text = value.trim();
|
|
9
|
+
const application = readTypeApplication(text);
|
|
10
|
+
if (!application) return text;
|
|
11
|
+
const args = splitTopLevelCommaList(application.body);
|
|
12
|
+
if (args.some((arg) => !arg)) return text;
|
|
13
|
+
const parsedArgs = args.map(parseTypeExpression);
|
|
14
|
+
if (application.name === 'Set' && parsedArgs.length === 1) return { kind: 'set', item: parsedArgs[0] };
|
|
15
|
+
if (application.name === 'List' && parsedArgs.length === 1) return { kind: 'list', item: parsedArgs[0] };
|
|
16
|
+
if (application.name === 'Map' && parsedArgs.length === 2) return { kind: 'map', key: parsedArgs[0], value: parsedArgs[1] };
|
|
17
|
+
return { kind: 'ref', name: application.name, args: parsedArgs };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function readTypeApplication(text) {
|
|
21
|
+
const match = /^([A-Za-z_$][\w$]*)</.exec(text);
|
|
22
|
+
if (!match || !text.endsWith('>')) return undefined;
|
|
23
|
+
let depth = 0;
|
|
24
|
+
for (let index = match[1].length; index < text.length; index++) {
|
|
25
|
+
const char = text[index];
|
|
26
|
+
if (char === '<') depth++;
|
|
27
|
+
if (char === '>') depth--;
|
|
28
|
+
if (depth < 0) return undefined;
|
|
29
|
+
if (depth === 0 && index !== text.length - 1) return undefined;
|
|
30
|
+
}
|
|
31
|
+
if (depth !== 0) return undefined;
|
|
32
|
+
return { name: match[1], body: text.slice(match[1].length + 1, -1).trim() };
|
|
33
|
+
}
|
package/dist/type-variants.js
CHANGED
package/dist/view.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { viewNode } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
2
|
import { readFrontierNestedBlocks } from './source-syntax-report.js';
|
|
3
|
+
import { parseOptionalTypeExpression, parseTypeExpression } from './type-expressions.js';
|
|
3
4
|
|
|
4
5
|
export function parseViewBlock(block) {
|
|
5
6
|
const name = nameFrom(block.header);
|
|
@@ -30,7 +31,7 @@ function readViewEvents(body) {
|
|
|
30
31
|
const events = [];
|
|
31
32
|
const re = /^\s*event\s+([A-Za-z_$][\w$.-]*)(?:\s+@id\(\s*["']([^"']+)["']\s*\))?([^\n]*)$/gm;
|
|
32
33
|
let match;
|
|
33
|
-
while ((match = re.exec(body))) events.push({ id: match[2] ?? `view_event_${match[1]}`, name: match[1], action: readInlineWord('action', match[3]), input: parseOptionalTypeExpression(
|
|
34
|
+
while ((match = re.exec(body))) events.push({ id: match[2] ?? `view_event_${match[1]}`, name: match[1], action: readInlineWord('action', match[3]), input: parseOptionalTypeExpression(readInlineType('input', match[3])) });
|
|
34
35
|
return events;
|
|
35
36
|
}
|
|
36
37
|
|
|
@@ -95,15 +96,7 @@ function readList(label, body) { const line = new RegExp('^\\s*' + label + '\\s+
|
|
|
95
96
|
function readLine(label, body) { return new RegExp('^\\s*' + label + '\\s+([^\\n]+)', 'm').exec(body)?.[1]?.trim(); }
|
|
96
97
|
function readQuotedLine(label, body) { return new RegExp(`^\\s*${label}\\s+["']([^"']+)["']`, 'm').exec(body)?.[1]; }
|
|
97
98
|
function readInlineWord(label, text = '') { return new RegExp('(?:^|\\s)' + label + '\\s+([^\\s,]+)').exec(text)?.[1]?.trim(); }
|
|
99
|
+
function readInlineType(label, text = '') { return new RegExp('(?:^|\\s)' + label + '\\s+(.+)$').exec(text)?.[1]?.trim(); }
|
|
98
100
|
function readRenderValue(value) { const quoted = /^["']([^"']+)["']$/.exec(value.trim()); return quoted ? { value: quoted[1] } : { expression: value.trim() }; }
|
|
99
101
|
function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined)); }
|
|
100
102
|
function uniqueStrings(values) { const result = []; for (const value of values) if (value && !result.includes(value)) result.push(value); return result.length ? result : undefined; }
|
|
101
|
-
function parseOptionalTypeExpression(value) { return value ? parseTypeExpression(value.trim()) : undefined; }
|
|
102
|
-
function parseTypeExpression(value) {
|
|
103
|
-
const text = value.trim();
|
|
104
|
-
if (/^Set<.+>$/.test(text)) return { kind: 'set', item: parseTypeExpression(text.slice(4, -1)) };
|
|
105
|
-
if (/^List<.+>$/.test(text)) return { kind: 'list', item: parseTypeExpression(text.slice(5, -1)) };
|
|
106
|
-
const map = /^Map<(.+),\s*(.+)>$/.exec(text);
|
|
107
|
-
if (map) return { kind: 'map', key: parseTypeExpression(map[1]), value: parseTypeExpression(map[2]) };
|
|
108
|
-
return text;
|
|
109
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshift-labs/frontier-lang-parser",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.58",
|
|
4
4
|
"description": "Parser for the first Frontier Lang .frontier syntax slice.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build": "node scripts/build.mjs",
|
|
25
|
-
"test": "npm run build && node test/smoke.mjs && node test/type-variant-payload-smoke.mjs && node test/action-body-smoke.mjs && node test/action-structured-literals-smoke.mjs && node test/action-return-smoke.mjs && node test/action-else-smoke.mjs && node test/action-match-smoke.mjs && node test/action-for-in-smoke.mjs && node test/action-repeat-smoke.mjs && node test/action-call-smoke.mjs && node test/target-projection-aggregate-smoke.mjs && node test/conversion-constraint-fields-smoke.mjs && node test/conversion-evidence-smoke.mjs && node test/package-canvas-surface-smoke.mjs && node test/view-render-graph-smoke.mjs && node test/resource-graph-smoke.mjs && node test/interlingua-smoke.mjs && node test/dialect-registry-smoke.mjs",
|
|
25
|
+
"test": "npm run build && node test/smoke.mjs && node test/type-variant-payload-smoke.mjs && node test/type-generic-ref-smoke.mjs && node test/action-body-smoke.mjs && node test/action-structured-literals-smoke.mjs && node test/action-return-smoke.mjs && node test/action-else-smoke.mjs && node test/action-match-smoke.mjs && node test/action-for-in-smoke.mjs && node test/action-repeat-smoke.mjs && node test/action-call-smoke.mjs && node test/target-projection-aggregate-smoke.mjs && node test/conversion-constraint-fields-smoke.mjs && node test/conversion-evidence-smoke.mjs && node test/package-canvas-surface-smoke.mjs && node test/view-render-graph-smoke.mjs && node test/resource-graph-smoke.mjs && node test/interlingua-smoke.mjs && node test/dialect-registry-smoke.mjs",
|
|
26
26
|
"typecheck": "node ./node_modules/typescript/bin/tsc --noEmit -p test/tsconfig.json",
|
|
27
27
|
"fuzz": "npm run build && node fuzz/smoke.mjs",
|
|
28
28
|
"bench": "npm run build && node bench/smoke.mjs",
|