@githolon/dsl 0.103.2 → 0.103.4

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.
@@ -1589,74 +1589,71 @@ function defaultOpinions(
1589
1589
  owner: string,
1590
1590
  indent: number,
1591
1591
  ): string[] {
1592
- const pad = " ".repeat(indent);
1593
- if (typeof value === "string") return [`${pad}custom uniform string nomos:default = ${quote(value)}`];
1594
- if (typeof value === "boolean") return [`${pad}custom uniform bool nomos:default = ${value}`];
1592
+ // Every default, including a scalar, uses the same nominal value algebra as a call. Presence of
1593
+ // the typed `Default` child is the fact; there is no parallel property/tag representation.
1594
+ return emitNominalConstant("Default", value, owner, indent);
1595
+ }
1596
+
1597
+ enum NominalConstantPrim {
1598
+ Null = "NomosNullValue",
1599
+ Boolean = "NomosBoolValue",
1600
+ Integer = "NomosIntValue",
1601
+ Number = "NomosNumberValue",
1602
+ String = "NomosStringValue",
1603
+ List = "NomosListValue",
1604
+ Record = "NomosRecordValue",
1605
+ }
1606
+
1607
+ function nominalConstantPrim(value: import("./law_value_type.js").LawConstant): NominalConstantPrim {
1608
+ if (value === null) return NominalConstantPrim.Null;
1609
+ if (typeof value === "string") return NominalConstantPrim.String;
1610
+ if (typeof value === "boolean") return NominalConstantPrim.Boolean;
1595
1611
  if (typeof value === "number") {
1596
- return [Number.isInteger(value)
1597
- ? `${pad}custom uniform int64 nomos:default = ${value}`
1598
- : `${pad}custom uniform double nomos:default = ${value}`];
1612
+ return Number.isInteger(value) ? NominalConstantPrim.Integer : NominalConstantPrim.Number;
1599
1613
  }
1600
- if (value === null) return [`${pad}custom uniform token nomos:defaultKind = "null"`];
1601
-
1602
- // USDA dictionaries cannot faithfully represent heterogeneous/nested arrays. Preserve the
1603
- // complete constant instead as a typed prim tree: generic USD tools can traverse it, humans can
1604
- // inspect it, and the kernel parser retains every opinion without an embedded JSON sub-language.
1605
- const kind = Array.isArray(value) ? "array" : "record";
1606
- return [
1607
- `${pad}custom uniform token nomos:defaultKind = ${quote(kind)}`,
1608
- `${pad}def Scope "Default"`,
1609
- `${pad}{`,
1610
- ...emitDefaultValue(value, owner, indent + 4),
1611
- `${pad}}`,
1612
- ];
1614
+ return Array.isArray(value) ? NominalConstantPrim.List : NominalConstantPrim.Record;
1613
1615
  }
1614
1616
 
1615
- function emitDefaultValue(
1617
+ function emitNominalConstant(
1618
+ name: string,
1616
1619
  value: import("./law_value_type.js").LawConstant,
1617
1620
  owner: string,
1618
1621
  indent: number,
1619
1622
  ): string[] {
1620
1623
  const pad = " ".repeat(indent);
1624
+ const lines = [
1625
+ `${pad}def ${nominalConstantPrim(value)} ${quote(name)}`,
1626
+ `${pad}{`,
1627
+ ];
1621
1628
  if (typeof value === "string") {
1622
- return [
1623
- `${pad}custom uniform token nomos:valueKind = "string"`,
1624
- `${pad}custom uniform string nomos:value = ${quote(value)}`,
1625
- ];
1629
+ lines.push(`${pad} custom uniform string nomos:value = ${quote(value)}`);
1630
+ return [...lines, `${pad}}`];
1626
1631
  }
1627
1632
  if (typeof value === "boolean") {
1628
- return [
1629
- `${pad}custom uniform token nomos:valueKind = "bool"`,
1630
- `${pad}custom uniform bool nomos:value = ${value}`,
1631
- ];
1633
+ lines.push(`${pad} custom uniform bool nomos:value = ${value}`);
1634
+ return [...lines, `${pad}}`];
1632
1635
  }
1633
1636
  if (typeof value === "number") {
1634
1637
  if (!Number.isFinite(value)) fail(`field '${owner}' has a non-finite numeric default`);
1635
- return [
1636
- `${pad}custom uniform token nomos:valueKind = ${quote(Number.isInteger(value) ? "int" : "number")}`,
1637
- Number.isInteger(value)
1638
- ? `${pad}custom uniform int64 nomos:value = ${value}`
1639
- : `${pad}custom uniform double nomos:value = ${value}`,
1640
- ];
1638
+ lines.push(Number.isInteger(value)
1639
+ ? `${pad} custom uniform int64 nomos:value = ${value}`
1640
+ : `${pad} custom uniform double nomos:value = ${value}`);
1641
+ return [...lines, `${pad}}`];
1641
1642
  }
1642
- if (value === null) return [`${pad}custom uniform token nomos:valueKind = "null"`];
1643
+ if (value === null) return [...lines, `${pad}}`];
1643
1644
 
1644
1645
  const entries: readonly [string, import("./law_value_type.js").LawConstant][] = Array.isArray(value)
1645
1646
  ? value.map((item, index) => [String(index), item] as const)
1646
1647
  : Object.entries(value).sort(([left], [right]) => left.localeCompare(right));
1647
- const kind = Array.isArray(value) ? "array" : "record";
1648
- const lines = [`${pad}custom uniform token nomos:valueKind = ${quote(kind)}`];
1649
1648
  for (const [index, [key, item]] of entries.entries()) {
1650
- lines.push(
1651
- "",
1652
- `${pad}def Scope "v_${String(index).padStart(8, "0")}"`,
1653
- `${pad}{`,
1654
- `${pad} custom uniform string nomos:key = ${quote(key)}`,
1655
- ...emitDefaultValue(item, owner, indent + 4),
1656
- `${pad}}`,
1657
- );
1649
+ const childName = `${Array.isArray(value) ? "i" : "f"}_${String(index).padStart(8, "0")}`;
1650
+ const child = emitNominalConstant(childName, item, owner, indent + 4);
1651
+ if (!Array.isArray(value)) {
1652
+ child.splice(2, 0, `${pad} custom uniform string nomos:name = ${quote(key)}`);
1653
+ }
1654
+ lines.push("", ...child);
1658
1655
  }
1659
- return lines;
1656
+ return [...lines, `${pad}}`];
1660
1657
  }
1661
1658
 
1662
1659
  function emitField(
@@ -1703,14 +1700,8 @@ function emitField(
1703
1700
  body.push(
1704
1701
  `${pad} def NomosFieldEvolutionCase "c_${String(caseIndex).padStart(8, "0")}"`,
1705
1702
  `${pad} {`,
1706
- `${pad} def Scope "From"`,
1707
- `${pad} {`,
1708
- ...emitDefaultValue(evolutionCase.from as import("./law_value_type.js").LawConstant, field.entity.label, indent + 24),
1709
- `${pad} }`,
1710
- `${pad} def Scope "To"`,
1711
- `${pad} {`,
1712
- ...emitDefaultValue(evolutionCase.to as import("./law_value_type.js").LawConstant, field.entity.label, indent + 24),
1713
- `${pad} }`,
1703
+ ...emitNominalConstant("From", evolutionCase.from as import("./law_value_type.js").LawConstant, field.entity.label, indent + 20),
1704
+ ...emitNominalConstant("To", evolutionCase.to as import("./law_value_type.js").LawConstant, field.entity.label, indent + 20),
1714
1705
  `${pad} }`,
1715
1706
  );
1716
1707
  }