dirac-lang 0.1.97 → 0.1.99

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.
@@ -77,6 +77,21 @@ function validateParameterType(paramName, value, expectedType) {
77
77
  }
78
78
  return { valid: true };
79
79
  }
80
+ function validateAttributeValue(attrName, value) {
81
+ if (value.includes("<variable")) {
82
+ return {
83
+ valid: false,
84
+ error: `Attribute '${attrName}' contains <variable> tag - use \${varname} syntax in attributes instead`
85
+ };
86
+ }
87
+ if (/<[a-zA-Z]/.test(value) && !value.includes("${")) {
88
+ return {
89
+ valid: false,
90
+ warning: `Attribute '${attrName}' appears to contain XML tags - attribute values should use \${} syntax for variables`
91
+ };
92
+ }
93
+ return { valid: true };
94
+ }
80
95
  async function validateNestedTags(session, element, options = {}) {
81
96
  const results = [];
82
97
  for (const child of element.children) {
@@ -94,7 +109,7 @@ async function validateNestedTags(session, element, options = {}) {
94
109
  async function validateTag(session, element, options = {}) {
95
110
  const { autocorrect = false, similarityCutoff = SIMILARITY_CUTOFF, deepValidation = false } = options;
96
111
  console.error(`[VALIDATE] Tag: <${element.tag}>, autocorrect: ${autocorrect}, attributes:`, Object.keys(element.attributes));
97
- const { getAvailableSubroutines } = await import("./session-IH5LO7FS.js");
112
+ const { getAvailableSubroutines } = await import("./session-6WX5O74B.js");
98
113
  const subroutines = getAvailableSubroutines(session);
99
114
  const allowed = new Set(subroutines.map((s) => s.name));
100
115
  const tagName = element.tag;
@@ -107,7 +122,8 @@ async function validateTag(session, element, options = {}) {
107
122
  warnings: [],
108
123
  attributeCorrections: {},
109
124
  typeErrors: [],
110
- nestedValidation: []
125
+ nestedValidation: [],
126
+ scopeValidation: void 0
111
127
  };
112
128
  if (allowed.has(tagName)) {
113
129
  console.error(`[VALIDATE] Tag <${tagName}> is valid`);
@@ -160,8 +176,16 @@ async function validateTag(session, element, options = {}) {
160
176
  }
161
177
  for (const attr in element.attributes) {
162
178
  const param = sub.parameters.find((p) => p.name === attr);
179
+ const attrValue = element.attributes[attr];
180
+ const attrValueCheck = validateAttributeValue(attr, attrValue);
181
+ if (!attrValueCheck.valid && attrValueCheck.error) {
182
+ result.errors.push(attrValueCheck.error);
183
+ }
184
+ if (attrValueCheck.warning) {
185
+ result.warnings.push(attrValueCheck.warning);
186
+ }
163
187
  if (param && param.type) {
164
- const typeCheck = validateParameterType(attr, element.attributes[attr], param.type);
188
+ const typeCheck = validateParameterType(attr, attrValue, param.type);
165
189
  if (!typeCheck.valid && typeCheck.error) {
166
190
  result.typeErrors.push(typeCheck.error);
167
191
  result.errors.push(typeCheck.error);
@@ -176,6 +200,22 @@ async function validateTag(session, element, options = {}) {
176
200
  result.warnings.push(`Nested tag <${nestedResult.originalTag}>: ${nestedResult.errors.join(", ")}`);
177
201
  }
178
202
  }
203
+ const { validateSubroutineScope } = await import("./scope-validator-TVQIOEAI.js");
204
+ result.scopeValidation = validateSubroutineScope(element);
205
+ console.error(`[VALIDATE] Scope validation for <subroutine name="${element.attributes.name}">:`, {
206
+ errors: result.scopeValidation.errors.length,
207
+ warnings: result.scopeValidation.warnings.length,
208
+ undefinedParams: result.scopeValidation.undefinedParameters,
209
+ undefinedVars: result.scopeValidation.undefinedVariables,
210
+ unusedParams: result.scopeValidation.unusedParameters,
211
+ unusedVars: result.scopeValidation.unusedVariables
212
+ });
213
+ if (result.scopeValidation.warnings.length > 0) {
214
+ result.warnings.push(...result.scopeValidation.warnings.map((w) => `Scope: ${w}`));
215
+ }
216
+ if (result.scopeValidation.errors.length > 0) {
217
+ result.errors.push(...result.scopeValidation.errors.map((e) => `Scope: ${e}`));
218
+ }
179
219
  }
180
220
  }
181
221
  result.valid = result.errors.length === 0;
@@ -230,6 +270,49 @@ async function validateDiracCode(session, ast, options = {}) {
230
270
  const results = [];
231
271
  const errorMessages = [];
232
272
  const typeErrors = [];
273
+ const localSubroutineNames = /* @__PURE__ */ new Set();
274
+ const localSubroutineElements = /* @__PURE__ */ new Map();
275
+ function extractLocalSubroutines(element) {
276
+ if (element.tag === "subroutine" && element.attributes.name) {
277
+ localSubroutineNames.add(element.attributes.name);
278
+ localSubroutineElements.set(element.attributes.name, element);
279
+ }
280
+ for (const child of element.children) {
281
+ extractLocalSubroutines(child);
282
+ }
283
+ }
284
+ extractLocalSubroutines(ast);
285
+ if (localSubroutineNames.size > 0) {
286
+ console.error(`[VALIDATE] Found ${localSubroutineNames.size} local subroutine definitions:`, Array.from(localSubroutineNames));
287
+ }
288
+ const tempSubroutines = [];
289
+ for (const subName of localSubroutineNames) {
290
+ const subElement = localSubroutineElements.get(subName);
291
+ const parameters = [];
292
+ for (const attr in subElement.attributes) {
293
+ if (attr.startsWith("param-")) {
294
+ const paramName = attr.slice(6);
295
+ const paramSpec = subElement.attributes[attr];
296
+ const parts = paramSpec.split(":");
297
+ parameters.push({
298
+ name: paramName,
299
+ type: parts[0] || "string",
300
+ required: parts[1] === "required",
301
+ description: parts[2] || "",
302
+ example: parts[3] || ""
303
+ });
304
+ }
305
+ }
306
+ console.error(`[VALIDATE] Temp subroutine '${subName}' has ${parameters.length} parameters:`, parameters.map((p) => p.name));
307
+ const tempSub = {
308
+ name: subName,
309
+ element: subElement,
310
+ boundary: session.variables.length,
311
+ parameters
312
+ };
313
+ session.subroutines.push(tempSub);
314
+ tempSubroutines.push(tempSub);
315
+ }
233
316
  async function validateElement(element) {
234
317
  if (element.tag && element.tag !== "dirac" && element.tag !== "DIRAC-ROOT" && element.tag.trim() !== "") {
235
318
  const result = await validateTag(session, element, options);
@@ -246,6 +329,12 @@ async function validateDiracCode(session, ast, options = {}) {
246
329
  }
247
330
  }
248
331
  await validateElement(ast);
332
+ for (const tempSub of tempSubroutines) {
333
+ const index = session.subroutines.indexOf(tempSub);
334
+ if (index > -1) {
335
+ session.subroutines.splice(index, 1);
336
+ }
337
+ }
249
338
  return {
250
339
  valid: errorMessages.length === 0,
251
340
  results,
@@ -256,26 +345,28 @@ async function validateDiracCode(session, ast, options = {}) {
256
345
  function applyCorrectedTags(ast, results) {
257
346
  let resultIndex = 0;
258
347
  function correctElement(element) {
259
- if (element.tag && element.tag !== "dirac" && element.tag !== "DIRAC-ROOT" && element.tag.trim() !== "") {
348
+ const shouldProcess = element.tag && element.tag !== "dirac" && element.tag !== "DIRAC-ROOT" && element.tag.trim() !== "";
349
+ if (shouldProcess && resultIndex < results.length) {
260
350
  const result = results[resultIndex++];
261
- if (result) {
262
- if (result.corrected && result.tagName !== element.tag) {
263
- console.error(`[APPLY-CORRECTION] Tag: ${element.tag} \u2192 ${result.tagName}`);
264
- element = { ...element, tag: result.tagName };
265
- }
266
- if (result.attributeCorrections && Object.keys(result.attributeCorrections).length > 0) {
267
- console.error(`[APPLY-CORRECTION] Attributes on <${element.tag}>:`, result.attributeCorrections);
268
- const newAttributes = {};
269
- for (const [oldAttr, value] of Object.entries(element.attributes)) {
270
- const newAttr = result.attributeCorrections[oldAttr] || oldAttr;
271
- if (newAttr !== oldAttr) {
272
- console.error(`[APPLY-CORRECTION] ${oldAttr}="${value}" \u2192 ${newAttr}="${value}"`);
273
- }
274
- newAttributes[newAttr] = value;
351
+ console.error(`[APPLY-CORRECTION] Processing <${element.tag}> with result #${resultIndex - 1} for <${result.originalTag}>, corrected: ${result.corrected}`);
352
+ if (result.corrected && result.tagName !== element.tag) {
353
+ console.error(`[APPLY-CORRECTION] Tag: ${element.tag} \u2192 ${result.tagName}`);
354
+ element = { ...element, tag: result.tagName };
355
+ }
356
+ if (result.attributeCorrections && Object.keys(result.attributeCorrections).length > 0) {
357
+ console.error(`[APPLY-CORRECTION] Attributes on <${element.tag}>:`, result.attributeCorrections);
358
+ const newAttributes = {};
359
+ for (const [oldAttr, value] of Object.entries(element.attributes)) {
360
+ const newAttr = result.attributeCorrections[oldAttr] || oldAttr;
361
+ if (newAttr !== oldAttr) {
362
+ console.error(`[APPLY-CORRECTION] ${oldAttr}="${value}" \u2192 ${newAttr}="${value}"`);
275
363
  }
276
- element = { ...element, attributes: newAttributes };
364
+ newAttributes[newAttr] = value;
277
365
  }
366
+ element = { ...element, attributes: newAttributes };
278
367
  }
368
+ } else if (shouldProcess) {
369
+ console.error(`[APPLY-CORRECTION] WARNING: No result for <${element.tag}> at index ${resultIndex} (total results: ${results.length})`);
279
370
  }
280
371
  return {
281
372
  ...element,
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-4TBIVB4X.js";
4
- import "./chunk-ECAW4X46.js";
5
- import "./chunk-SLGJRZ3P.js";
3
+ } from "./chunk-3VCKPUTQ.js";
4
+ import "./chunk-53QJQ2CC.js";
6
5
  import {
7
6
  DiracParser
8
7
  } from "./chunk-HRHAMPOB.js";
8
+ import "./chunk-EAM7IZWA.js";
9
9
  import {
10
10
  createSession,
11
11
  getOutput
12
- } from "./chunk-PPH7KYKH.js";
12
+ } from "./chunk-ZYSWVMID.js";
13
13
 
14
14
  // src/test-runner.ts
15
15
  import fs from "fs";
@@ -219,7 +219,8 @@
219
219
  meta-hide-from-llm="true"
220
220
  description="Edit subroutine definition in external editor"
221
221
  param-name="string:required:Subroutine name to edit"
222
- param-editor="string:optional:Editor command (default: $EDITOR or vi)">
222
+ param-editor="string:optional:Editor command (default: $EDITOR or vi)"
223
+ param-format="string:optional:format (braket or xml, default:braket)">
223
224
  <!-- Opens subroutine in temp file with editor (blocking) -->
224
225
  <!-- After save/exit, automatically re-imports into session -->
225
226
  <!-- Changes take effect immediately but are NOT saved to disk -->
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirac-lang",
3
- "version": "0.1.97",
3
+ "version": "0.1.99",
4
4
  "description": "LLM-Augmented Declarative Execution",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,12 +0,0 @@
1
- import {
2
- integrate,
3
- integrateChildren
4
- } from "./chunk-4TBIVB4X.js";
5
- import "./chunk-ECAW4X46.js";
6
- import "./chunk-SLGJRZ3P.js";
7
- import "./chunk-HRHAMPOB.js";
8
- import "./chunk-PPH7KYKH.js";
9
- export {
10
- integrate,
11
- integrateChildren
12
- };