@o-lang/olang 1.0.12 → 1.0.14
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/cli.js +1 -1
- package/package.json +1 -1
- package/src/parser.js +61 -30
- package/src/runtime.js +3 -6
package/cli.js
CHANGED
package/package.json
CHANGED
package/src/parser.js
CHANGED
|
@@ -106,41 +106,72 @@ function parse(code, fileName = null) {
|
|
|
106
106
|
continue;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
109
|
+
// ---------------------------
|
|
110
|
+
// Return statement (updated: auto-detect math)
|
|
111
|
+
// ---------------------------
|
|
112
|
+
const returnMatch = line.match(/^Return\s+(.+)$/i);
|
|
113
|
+
if (returnMatch) {
|
|
114
|
+
const returns = returnMatch[1].split(',').map(v => v.trim());
|
|
115
|
+
workflow.returnValues = returns;
|
|
116
|
+
|
|
117
|
+
// --- Check if any return vars come from math steps ---
|
|
118
|
+
for (const retVar of returns) {
|
|
119
|
+
const producedByMath = workflow.steps.some(
|
|
120
|
+
s => s.saveAs === retVar && s.type === 'calculate'
|
|
121
|
+
);
|
|
122
|
+
if (producedByMath) workflow.__requiresMath = true;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
i++;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
|
|
121
129
|
|
|
122
130
|
// ---------------------------
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
// Steps (updated: auto-detect math + saveAs)
|
|
132
|
+
// ---------------------------
|
|
133
|
+
const stepMatch = line.match(/^Step\s+(\d+)\s*:\s*(.+)$/i);
|
|
134
|
+
if (stepMatch) {
|
|
135
|
+
const stepNum = parseInt(stepMatch[1], 10);
|
|
136
|
+
const raw = stepMatch[2].trim();
|
|
137
|
+
|
|
138
|
+
// --- Detect math inside Step ---
|
|
139
|
+
let mathDetected = null;
|
|
140
|
+
let expr = '';
|
|
141
|
+
let saveVar = null;
|
|
142
|
+
|
|
143
|
+
const mathOps = [
|
|
144
|
+
{ re: /^Add\s+\{(.+?)\}\s+and\s+\{(.+?)\}\s+Save as\s+(.+)$/i, fn: 'add' },
|
|
145
|
+
{ re: /^Subtract\s+\{(.+?)\}\s+from\s+\{(.+?)\}\s+Save as\s+(.+)$/i, fn: 'subtract' },
|
|
146
|
+
{ re: /^Multiply\s+\{(.+?)\}\s+and\s+\{(.+?)\}\s+Save as\s+(.+)$/i, fn: 'multiply' },
|
|
147
|
+
{ re: /^Divide\s+\{(.+?)\}\s+by\s+\{(.+?)\}\s+Save as\s+(.+)$/i, fn: 'divide' }
|
|
148
|
+
];
|
|
149
|
+
|
|
150
|
+
for (const op of mathOps) {
|
|
151
|
+
const m = raw.match(op.re);
|
|
152
|
+
if (m) {
|
|
153
|
+
mathDetected = op.fn;
|
|
154
|
+
saveVar = m[3].trim();
|
|
155
|
+
if (op.fn === 'subtract') expr = `subtract({${m[2]}}, {${m[1]}})`;
|
|
156
|
+
else expr = `${op.fn}({${m[1]}}, {${m[2]}})`;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
134
160
|
|
|
135
|
-
|
|
161
|
+
if (mathDetected) workflow.__requiresMath = true;
|
|
136
162
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
163
|
+
workflow.steps.push({
|
|
164
|
+
type: mathDetected ? 'calculate' : 'action',
|
|
165
|
+
stepNumber: stepNum,
|
|
166
|
+
actionRaw: mathDetected ? null : raw,
|
|
167
|
+
expression: mathDetected ? expr : undefined,
|
|
168
|
+
saveAs: saveVar,
|
|
169
|
+
constraints: {}
|
|
170
|
+
});
|
|
140
171
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
172
|
+
i++;
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
144
175
|
|
|
145
176
|
const saveMatch = line.match(/^Save as\s+(.+)$/i);
|
|
146
177
|
if (saveMatch && workflow.steps.length > 0) {
|
package/src/runtime.js
CHANGED
|
@@ -144,17 +144,14 @@ class RuntimeAPI {
|
|
|
144
144
|
async executeStep(step, agentResolver) {
|
|
145
145
|
const stepType = step.type;
|
|
146
146
|
|
|
147
|
-
|
|
148
|
-
// Get resolver name from metadata, trim whitespace
|
|
147
|
+
const validateResolver = (resolver) => {
|
|
149
148
|
const resolverName = (resolver?.resolverName || resolver?.name || '').trim();
|
|
150
|
-
|
|
151
149
|
if (!resolverName) throw new Error('[O-Lang] Resolver missing name metadata');
|
|
152
150
|
|
|
153
|
-
// Normalize allowed resolver names for comparison
|
|
154
151
|
const allowed = Array.from(this.allowedResolvers || []).map(r => r.trim());
|
|
155
152
|
|
|
156
|
-
// Auto-inject builtInMathResolver if
|
|
157
|
-
if (
|
|
153
|
+
// Auto-inject builtInMathResolver if step type is 'calculate' and resolver is math
|
|
154
|
+
if (step.type === 'calculate' && resolverName === 'builtInMathResolver' && !allowed.includes('builtInMathResolver')) {
|
|
158
155
|
this.allowedResolvers.add('builtInMathResolver');
|
|
159
156
|
allowed.push('builtInMathResolver');
|
|
160
157
|
}
|