@shapeshift-labs/frontier-lang-parser 0.3.48 → 0.3.49
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/action-body.js +26 -4
- package/dist/action-syntax-children.js +29 -5
- package/package.json +2 -2
package/dist/action-body.js
CHANGED
|
@@ -111,14 +111,36 @@ function parseActionBodyLine(line, index) {
|
|
|
111
111
|
return compactRecord({ kind: 'let', id: idFrom(rest, `action_body_let_${name}`), name, valueType, comparisonType, callType, value });
|
|
112
112
|
}
|
|
113
113
|
if (rowKind === 'return') {
|
|
114
|
-
const
|
|
115
|
-
const value = valueText ? readActionValue(valueText) : undefined;
|
|
116
|
-
if (valueText && !value) return undefined;
|
|
117
|
-
return compactRecord({
|
|
114
|
+
const details = readReturnDetails(rawName, rest);
|
|
115
|
+
const value = details.valueText ? readActionValue(details.valueText, details) : undefined;
|
|
116
|
+
if (details.valueText && !value) return undefined;
|
|
117
|
+
return compactRecord({
|
|
118
|
+
kind: 'return',
|
|
119
|
+
id: idFrom(rest, `action_body_return_${index}`),
|
|
120
|
+
valueType: details.valueType,
|
|
121
|
+
comparisonType: details.comparisonType,
|
|
122
|
+
callType: details.callType,
|
|
123
|
+
value
|
|
124
|
+
});
|
|
118
125
|
}
|
|
119
126
|
return undefined;
|
|
120
127
|
}
|
|
121
128
|
|
|
129
|
+
function readReturnDetails(rawName, rest) {
|
|
130
|
+
const text = stripIds(rawName?.startsWith('@') ? rest : `${rawName ?? ''}${rest ?? ''}`).trim();
|
|
131
|
+
const explicitValue = /\bvalue\s+/.test(text);
|
|
132
|
+
const valueType = readInlineType(text);
|
|
133
|
+
const comparisonType = readInlineComparisonType(text);
|
|
134
|
+
const callType = readInlineCallType(text);
|
|
135
|
+
const valueText = explicitValue ? readInlineValue('value', text) : text;
|
|
136
|
+
return {
|
|
137
|
+
valueText,
|
|
138
|
+
valueType,
|
|
139
|
+
comparisonType,
|
|
140
|
+
callType
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
122
144
|
function skipWhitespaceAndComments(source, offset) {
|
|
123
145
|
let index = offset;
|
|
124
146
|
while (index < source.length) {
|
|
@@ -104,8 +104,12 @@ function validateActionRow(rowKind, rawName, rest, header) {
|
|
|
104
104
|
return input ? validateActionExpressionText(input) : { ok: true };
|
|
105
105
|
}
|
|
106
106
|
if (rowKind === 'return') {
|
|
107
|
-
const
|
|
108
|
-
|
|
107
|
+
const details = readReturnDetails(rawName, rest);
|
|
108
|
+
if (!details.valueText) return { ok: true };
|
|
109
|
+
const parsed = parseActionValue(details.valueText, details);
|
|
110
|
+
if (parsed.ok) return { ok: true };
|
|
111
|
+
if (isActionExpressionAdmissionReason(parsed.reason)) return { ok: false, reason: parsed.reason };
|
|
112
|
+
return { ok: false, reason: 'unsupported-action-return-value' };
|
|
109
113
|
}
|
|
110
114
|
if (rowKind === 'let') {
|
|
111
115
|
if (!rawName || rawName.startsWith('@') || !/^[A-Za-z_$][\w$-]*$/.test(rawName)) {
|
|
@@ -148,9 +152,15 @@ function readIfCondition(header) {
|
|
|
148
152
|
return explicit ? explicit[1].trim() : text;
|
|
149
153
|
}
|
|
150
154
|
|
|
151
|
-
function
|
|
152
|
-
|
|
153
|
-
|
|
155
|
+
function readReturnDetails(rawName, rest) {
|
|
156
|
+
const text = stripIds(rawName?.startsWith('@') ? rest : `${rawName ?? ''}${rest ?? ''}`).trim();
|
|
157
|
+
const explicitValue = /\bvalue\s+/.test(text);
|
|
158
|
+
return {
|
|
159
|
+
valueText: explicitValue ? readInlineValue('value', text) : text,
|
|
160
|
+
valueType: readInlineType(text),
|
|
161
|
+
comparisonType: readInlineComparisonType(text),
|
|
162
|
+
callType: readInlineCallType(text)
|
|
163
|
+
};
|
|
154
164
|
}
|
|
155
165
|
|
|
156
166
|
function stripIds(text) {
|
|
@@ -162,6 +172,20 @@ function validateActionExpressionText(text, options = {}) {
|
|
|
162
172
|
return parsed.ok ? { ok: true } : { ok: false, reason: parsed.reason };
|
|
163
173
|
}
|
|
164
174
|
|
|
175
|
+
function isActionExpressionAdmissionReason(reason) {
|
|
176
|
+
return reason === 'missing-action-expression-type'
|
|
177
|
+
|| reason === 'unsupported-action-expression-type'
|
|
178
|
+
|| reason === 'missing-action-comparison-type'
|
|
179
|
+
|| reason === 'unsupported-action-comparison-type'
|
|
180
|
+
|| reason === 'missing-action-call-type'
|
|
181
|
+
|| reason === 'unsupported-action-call-type'
|
|
182
|
+
|| reason === 'unsupported-action-call-callee'
|
|
183
|
+
|| reason === 'unsupported-action-call-argument'
|
|
184
|
+
|| reason === 'unsupported-action-expression-ref'
|
|
185
|
+
|| reason === 'malformed-action-expression'
|
|
186
|
+
|| reason === 'missing-action-expression';
|
|
187
|
+
}
|
|
188
|
+
|
|
165
189
|
function readNestedBodyBlocks(kind, source) {
|
|
166
190
|
const blocks = [];
|
|
167
191
|
const header = new RegExp('\\b' + kind.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '(?:\\s+([^{}\\n]+?))?\\s*\\{', 'g');
|
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.49",
|
|
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/action-body-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/action-body-smoke.mjs && node test/action-return-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",
|