Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Normalize Firmament fixtures and test sources to canonical syntax

Yuechen Lid12ddbc74e12
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.cs
index d3ec9734..47f7756d 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.cs
@@ -7,53 +7,99 @@ public sealed class FirmamentBooleanRequiredFieldValidationTests
[Fact]
public void Compiler_Accepts_ValidAdd() =>
AssertValidBooleanOp("""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "box", "id": "base", "size": [1, 2, 3] },
- { "op": "add", "id": "add1", "to": "base", "with": { "op": "box" }, "place": "ignored-for-now" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[2]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 1
+ 2
+ 3
+ -
+ op: add
+ id: add1
+ to: base
+ with:
+ op: box
+ place: ignored-for-now
""");
[Fact]
public void Compiler_Accepts_ValidSubtract() =>
AssertValidBooleanOp("""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "box", "id": "base", "size": [1, 2, 3] },
- { "op": "subtract", "id": "sub1", "from": "base", "with": { "op": "cylinder" } }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[2]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 1
+ 2
+ 3
+ -
+ op: subtract
+ id: sub1
+ from: base
+ with:
+ op: cylinder
""");
[Fact]
public void Compiler_Accepts_ValidIntersect() =>
AssertValidBooleanOp("""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "box", "id": "base", "size": [1, 2, 3] },
- { "op": "intersect", "id": "int1", "left": "base", "with": { "op": "sphere" } }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[2]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 1
+ 2
+ 3
+ -
+ op: intersect
+ id: int1
+ left: base
+ with:
+ op: sphere
""");
[Fact]
public void Compiler_Rejects_Add_MissingId() =>
AssertBooleanFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "add", "to": "base", "with": { "op": "box" } }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: add
+ to: base
+ with:
+ op: box
""",
FirmamentDiagnosticCodes.BooleanMissingRequiredField,
"Boolean op 'add' at index 0 is missing required field 'id'.");
@@ -62,13 +108,19 @@ public sealed class FirmamentBooleanRequiredFieldValidationTests
public void Compiler_Rejects_Add_MissingTo() =>
AssertBooleanFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "add", "id": "a1", "with": { "op": "box" } }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: add
+ id: a1
+ with:
+ op: box
""",
FirmamentDiagnosticCodes.BooleanMissingRequiredField,
"Boolean op 'add' at index 0 is missing required field 'to'.");
@@ -77,13 +129,18 @@ public sealed class FirmamentBooleanRequiredFieldValidationTests
public void Compiler_Rejects_Add_MissingWith() =>
AssertBooleanFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "add", "id": "a1", "to": "base" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: add
+ id: a1
+ to: base
""",
FirmamentDiagnosticCodes.BooleanMissingRequiredField,
"Boolean op 'add' at index 0 is missing required field 'with'.");
@@ -92,13 +149,19 @@ public sealed class FirmamentBooleanRequiredFieldValidationTests
public void Compiler_Rejects_Add_InvalidWithShape() =>
AssertBooleanFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "add", "id": "a1", "to": "base", "with": "sphere" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: add
+ id: a1
+ to: base
+ with: sphere
""",
FirmamentDiagnosticCodes.BooleanInvalidFieldTypeOrShape,
"Boolean op 'add' at index 0 has invalid field 'with'; expected an object-like mapping.");
@@ -107,13 +170,20 @@ public sealed class FirmamentBooleanRequiredFieldValidationTests
public void Compiler_Rejects_Add_MissingWithOp() =>
AssertBooleanFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "add", "id": "a1", "to": "base", "with": { "id": "tool1" } }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: add
+ id: a1
+ to: base
+ with:
+ id: tool1
""",
FirmamentDiagnosticCodes.BooleanInvalidFieldTypeOrShape,
"Boolean op 'add' at index 0 has invalid field 'with.op'; expected a non-empty scalar/string-like value.");
@@ -122,13 +192,19 @@ public sealed class FirmamentBooleanRequiredFieldValidationTests
public void Compiler_Rejects_Subtract_MissingId() =>
AssertBooleanFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "subtract", "from": "base", "with": { "op": "box" } }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: subtract
+ from: base
+ with:
+ op: box
""",
FirmamentDiagnosticCodes.BooleanMissingRequiredField,
"Boolean op 'subtract' at index 0 is missing required field 'id'.");
@@ -137,13 +213,19 @@ public sealed class FirmamentBooleanRequiredFieldValidationTests
public void Compiler_Rejects_Subtract_MissingFrom() =>
AssertBooleanFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "subtract", "id": "s1", "with": { "op": "box" } }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: subtract
+ id: s1
+ with:
+ op: box
""",
FirmamentDiagnosticCodes.BooleanMissingRequiredField,
"Boolean op 'subtract' at index 0 is missing required field 'from'.");
@@ -152,13 +234,18 @@ public sealed class FirmamentBooleanRequiredFieldValidationTests
public void Compiler_Rejects_Subtract_MissingWith() =>
AssertBooleanFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "subtract", "id": "s1", "from": "base" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: subtract
+ id: s1
+ from: base
""",
FirmamentDiagnosticCodes.BooleanMissingRequiredField,
"Boolean op 'subtract' at index 0 is missing required field 'with'.");
@@ -167,13 +254,20 @@ public sealed class FirmamentBooleanRequiredFieldValidationTests
public void Compiler_Rejects_Subtract_InvalidWithShape() =>
AssertBooleanFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "subtract", "id": "s1", "from": "base", "with": ["tool"] }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: subtract
+ id: s1
+ from: base
+ with[1]:
+ tool
""",
FirmamentDiagnosticCodes.BooleanInvalidFieldTypeOrShape,
"Boolean op 'subtract' at index 0 has invalid field 'with'; expected an object-like mapping.");
@@ -182,13 +276,20 @@ public sealed class FirmamentBooleanRequiredFieldValidationTests
public void Compiler_Rejects_Subtract_MissingWithOp() =>
AssertBooleanFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "subtract", "id": "s1", "from": "base", "with": { "op": "" } }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: subtract
+ id: s1
+ from: base
+ with:
+ op:
""",
FirmamentDiagnosticCodes.BooleanInvalidFieldTypeOrShape,
"Boolean op 'subtract' at index 0 has invalid field 'with.op'; expected a non-empty scalar/string-like value.");
@@ -197,13 +298,19 @@ public sealed class FirmamentBooleanRequiredFieldValidationTests
public void Compiler_Rejects_Intersect_MissingId() =>
AssertBooleanFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "intersect", "left": "base", "with": { "op": "box" } }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: intersect
+ left: base
+ with:
+ op: box
""",
FirmamentDiagnosticCodes.BooleanMissingRequiredField,
"Boolean op 'intersect' at index 0 is missing required field 'id'.");
@@ -212,13 +319,19 @@ public sealed class FirmamentBooleanRequiredFieldValidationTests
public void Compiler_Rejects_Intersect_MissingLeft() =>
AssertBooleanFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "intersect", "id": "i1", "with": { "op": "box" } }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: intersect
+ id: i1
+ with:
+ op: box
""",
FirmamentDiagnosticCodes.BooleanMissingRequiredField,
"Boolean op 'intersect' at index 0 is missing required field 'left'.");
@@ -227,13 +340,18 @@ public sealed class FirmamentBooleanRequiredFieldValidationTests
public void Compiler_Rejects_Intersect_MissingWith() =>
AssertBooleanFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "intersect", "id": "i1", "left": "base" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: intersect
+ id: i1
+ left: base
""",
FirmamentDiagnosticCodes.BooleanMissingRequiredField,
"Boolean op 'intersect' at index 0 is missing required field 'with'.");
@@ -242,13 +360,19 @@ public sealed class FirmamentBooleanRequiredFieldValidationTests
public void Compiler_Rejects_Intersect_InvalidWithShape() =>
AssertBooleanFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "intersect", "id": "i1", "left": "base", "with": 7 }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: intersect
+ id: i1
+ left: base
+ with: 7
""",
FirmamentDiagnosticCodes.BooleanInvalidFieldTypeOrShape,
"Boolean op 'intersect' at index 0 has invalid field 'with'; expected an object-like mapping.");
@@ -257,13 +381,20 @@ public sealed class FirmamentBooleanRequiredFieldValidationTests
public void Compiler_Rejects_Intersect_MissingWithOp() =>
AssertBooleanFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "intersect", "id": "i1", "left": "base", "with": { "id": "tool" } }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: intersect
+ id: i1
+ left: base
+ with:
+ id: tool
""",
FirmamentDiagnosticCodes.BooleanInvalidFieldTypeOrShape,
"Boolean op 'intersect' at index 0 has invalid field 'with.op'; expected a non-empty scalar/string-like value.");
@@ -272,13 +403,20 @@ public sealed class FirmamentBooleanRequiredFieldValidationTests
public void BooleanValidation_Diagnostics_AreDeterministic()
{
const string source = """
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "add", "id": "a1", "to": "base", "with": { "id": "tool" } }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: add
+ id: a1
+ to: base
+ with:
+ id: tool
""";
var compiler = new FirmamentCompiler();
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentCorpusScaffoldTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentCorpusScaffoldTests.cs
index e9a41eb4..662e1177 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentCorpusScaffoldTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentCorpusScaffoldTests.cs
@@ -74,6 +74,23 @@ public sealed class FirmamentCorpusScaffoldTests
}
}
+ [Fact]
+ public void FirmamentTestSourceLiterals_AvoidJsonShapedExamples()
+ {
+ var testsRoot = Path.Combine(FirmamentCorpusHarness.RepoRoot(), "Aetheris.Kernel.Firmament.Tests");
+ var testFiles = Directory.GetFiles(testsRoot, "*.cs", SearchOption.TopDirectoryOnly)
+ .OrderBy(path => path, StringComparer.Ordinal)
+ .ToArray();
+
+ Assert.NotEmpty(testFiles);
+
+ foreach (var testFile in testFiles)
+ {
+ var contents = FirmamentCorpusHarness.NormalizeLf(File.ReadAllText(testFile));
+ Assert.DoesNotContain("\"firmament\":", contents, StringComparison.Ordinal);
+ }
+ }
+
[Fact]
public void CuratedCases_Compile_WithExpectedOutcomeAndDiagnostics()
{
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentDocumentCoherenceValidationTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentDocumentCoherenceValidationTests.cs
index 39a4ffe2..d1dc4b31 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentDocumentCoherenceValidationTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentDocumentCoherenceValidationTests.cs
@@ -57,15 +57,28 @@ public sealed class FirmamentDocumentCoherenceValidationTests
public void Compiler_Leaves_ValidationTargets_Unresolved()
{
const string source = """
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "box", "id": "base", "size": [1, 2, 3] },
- { "op": "expect_exists", "target": "future_feature.top_face" },
- { "op": "expect_selectable", "target": "ghost_feature", "count": 1 }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[3]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 1
+ 2
+ 3
+ -
+ op: expect_exists
+ target: future_feature.top_face
+ -
+ op: expect_selectable
+ target: ghost_feature
+ count: 1
""";
var compiler = new FirmamentCompiler();
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentScaffoldTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentScaffoldTests.cs
index 0b50a9c8..ab7fc869 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentScaffoldTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentScaffoldTests.cs
@@ -23,11 +23,14 @@ public sealed class FirmamentScaffoldTests
{
var compiler = new FirmamentCompiler();
var source = """
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": []
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[0]:
""";
var result = compiler.Compile(new FirmamentCompileRequest(new FirmamentSourceDocument(source)));
@@ -46,13 +49,21 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Accepts_KnownPrimitiveOp() =>
AssertValidOpsCount(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "box", "id": "b1", "size": [1, 2, 3] }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: box
+ id: b1
+ size[3]:
+ 1
+ 2
+ 3
""",
1);
@@ -60,14 +71,27 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Accepts_MultipleKnownOps() =>
AssertValidOpsCount(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "box", "id": "b1", "size": [2, 3, 4] },
- { "op": "subtract", "id": "cut1", "from": "b1", "with": { "op": "box" } }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[2]:
+ -
+ op: box
+ id: b1
+ size[3]:
+ 2
+ 3
+ 4
+ -
+ op: subtract
+ id: cut1
+ from: b1
+ with:
+ op: box
""",
2);
@@ -77,13 +101,19 @@ public sealed class FirmamentScaffoldTests
{
var compiler = new FirmamentCompiler();
var source = """
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "sphere", "id": "s1", "radius": 2.5, "note": "x" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: sphere
+ id: s1
+ radius: 2.5
+ note: x
""";
var result = compiler.Compile(new FirmamentCompileRequest(new FirmamentSourceDocument(source)));
@@ -114,15 +144,29 @@ public sealed class FirmamentScaffoldTests
{
var compiler = new FirmamentCompiler();
var source = """
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "box", "id": "b1", "size": [1, 2, 3] },
- { "op": "subtract", "id": "s1", "from": "b1", "with": { "op": "sphere" } },
- { "op": "expect_manifold" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[3]:
+ -
+ op: box
+ id: b1
+ size[3]:
+ 1
+ 2
+ 3
+ -
+ op: subtract
+ id: s1
+ from: b1
+ with:
+ op: sphere
+ -
+ op: expect_manifold
""";
var result = compiler.Compile(new FirmamentCompileRequest(new FirmamentSourceDocument(source)));
@@ -140,14 +184,27 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Accepts_KnownBooleanOp() =>
AssertValidOpsCount(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "box", "id": "b1", "size": [1, 2, 3] },
- { "op": "add", "id": "add1", "to": "b1", "with": { "op": "sphere" } }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[2]:
+ -
+ op: box
+ id: b1
+ size[3]:
+ 1
+ 2
+ 3
+ -
+ op: add
+ id: add1
+ to: b1
+ with:
+ op: sphere
""",
2);
@@ -155,13 +212,17 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Accepts_KnownValidationOp() =>
AssertValidOpsCount(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "expect_exists", "target": "base" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: expect_exists
+ target: base
""",
1);
@@ -169,13 +230,16 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Rejects_OpEntry_MissingOp() =>
AssertSingleValidationError(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "target": "a" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ target: a
""",
FirmamentDiagnosticCodes.StructureMissingRequiredOpField,
"Operation entry at index 0 is missing required field 'op'.");
@@ -184,13 +248,15 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Rejects_OpEntry_WrongShape() =>
AssertSingleValidationError(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- "not-an-object"
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ - not-an-object
""",
FirmamentDiagnosticCodes.StructureInvalidOpsEntryShape,
"Operation entry at index 0 must be an object with fields.");
@@ -199,13 +265,16 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Rejects_OpValue_InvalidShape() =>
AssertSingleValidationError(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op:
""",
FirmamentDiagnosticCodes.StructureInvalidOpFieldValue,
"Operation entry at index 0 has invalid 'op' value; expected a non-empty scalar.");
@@ -215,13 +284,16 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Rejects_UnknownOpKind() =>
AssertSingleValidationError(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "torus" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: torus
""",
FirmamentDiagnosticCodes.StructureUnknownOpKind,
"Operation entry at index 0 has unknown op kind 'torus'.");
@@ -231,13 +303,16 @@ public sealed class FirmamentScaffoldTests
{
var compiler = new FirmamentCompiler();
var source = """
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "torus" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: torus
""";
var first = compiler.Compile(new FirmamentCompileRequest(new FirmamentSourceDocument(source)));
@@ -260,13 +335,16 @@ public sealed class FirmamentScaffoldTests
{
var compiler = new FirmamentCompiler();
var source = """
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "target": "a" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ target: a
""";
var first = compiler.Compile(new FirmamentCompileRequest(new FirmamentSourceDocument(source)));
@@ -316,10 +394,10 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Rejects_MissingModel() =>
AssertSingleValidationError(
"""
- {
- "firmament": { "version": "1" },
- "ops": []
- }
+ firmament:
+ version: 1
+
+ ops[0]:
""",
FirmamentDiagnosticCodes.StructureMissingRequiredSection,
"Missing required top-level section 'model'.");
@@ -328,10 +406,12 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Rejects_MissingOps() =>
AssertSingleValidationError(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" }
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
""",
FirmamentDiagnosticCodes.StructureMissingRequiredSection,
"Missing required top-level section 'ops'.");
@@ -340,11 +420,13 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Rejects_MissingVersion() =>
AssertSingleValidationError(
"""
- {
- "firmament": { },
- "model": { "name": "demo", "units": "mm" },
- "ops": []
- }
+ firmament:
+
+ model:
+ name: demo
+ units: mm
+
+ ops[0]:
""",
FirmamentDiagnosticCodes.StructureMissingRequiredField,
"Missing required field 'version' in section 'firmament'.");
@@ -353,11 +435,13 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Rejects_MissingName() =>
AssertSingleValidationError(
"""
- {
- "firmament": { "version": "1" },
- "model": { "units": "mm" },
- "ops": []
- }
+ firmament:
+ version: 1
+
+ model:
+ units: mm
+
+ ops[0]:
""",
FirmamentDiagnosticCodes.StructureMissingRequiredField,
"Missing required field 'name' in section 'model'.");
@@ -366,11 +450,13 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Rejects_MissingUnits() =>
AssertSingleValidationError(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo" },
- "ops": []
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+
+ ops[0]:
""",
FirmamentDiagnosticCodes.StructureMissingRequiredField,
"Missing required field 'units' in section 'model'.");
@@ -379,12 +465,16 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Rejects_UnknownTopLevelSection() =>
AssertSingleValidationError(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [],
- "other": {}
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[0]:
+
+ other:
""",
FirmamentDiagnosticCodes.StructureUnknownTopLevelSection,
"Unknown top-level section 'other'.");
@@ -393,13 +483,19 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Accepts_ValidCylinderPrimitiveOp() =>
AssertValidOpsCount(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "cylinder", "id": "c1", "radius": 1.5, "height": 10 }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: cylinder
+ id: c1
+ radius: 1.5
+ height: 10
""",
1);
@@ -407,13 +503,20 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Rejects_Box_MissingId() =>
AssertSingleValidationError(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "box", "size": [1, 2, 3] }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: box
+ size[3]:
+ 1
+ 2
+ 3
""",
FirmamentDiagnosticCodes.PrimitiveMissingRequiredField,
"Primitive op 'box' at index 0 is missing required field 'id'.");
@@ -422,13 +525,17 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Rejects_Box_MissingSize() =>
AssertSingleValidationError(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "box", "id": "b1" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: box
+ id: b1
""",
FirmamentDiagnosticCodes.PrimitiveMissingRequiredField,
"Primitive op 'box' at index 0 is missing required field 'size'.");
@@ -437,13 +544,20 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Rejects_Box_InvalidSizeShape() =>
AssertSingleValidationError(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "box", "id": "b1", "size": [1, 2] }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: box
+ id: b1
+ size[2]:
+ 1
+ 2
""",
FirmamentDiagnosticCodes.PrimitiveInvalidFieldTypeOrShape,
"Primitive op 'box' at index 0 has invalid field 'size'; expected exactly 3 numeric components.");
@@ -452,13 +566,21 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Rejects_Box_NonPositiveSizeComponent() =>
AssertSingleValidationError(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "box", "id": "b1", "size": [1, 0, 3] }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: box
+ id: b1
+ size[3]:
+ 1
+ 0
+ 3
""",
FirmamentDiagnosticCodes.PrimitiveInvalidFieldValue,
"Primitive op 'box' at index 0 has invalid field 'size' value; all components must be greater than 0.");
@@ -467,13 +589,18 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Rejects_Cylinder_MissingRadius() =>
AssertSingleValidationError(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "cylinder", "id": "c1", "height": 5 }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: cylinder
+ id: c1
+ height: 5
""",
FirmamentDiagnosticCodes.PrimitiveMissingRequiredField,
"Primitive op 'cylinder' at index 0 is missing required field 'radius'.");
@@ -482,13 +609,18 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Rejects_Cylinder_MissingHeight() =>
AssertSingleValidationError(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "cylinder", "id": "c1", "radius": 2 }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: cylinder
+ id: c1
+ radius: 2
""",
FirmamentDiagnosticCodes.PrimitiveMissingRequiredField,
"Primitive op 'cylinder' at index 0 is missing required field 'height'.");
@@ -497,13 +629,19 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Rejects_Cylinder_NonPositiveRadiusOrHeight() =>
AssertSingleValidationError(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "cylinder", "id": "c1", "radius": -1, "height": 5 }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: cylinder
+ id: c1
+ radius: -1
+ height: 5
""",
FirmamentDiagnosticCodes.PrimitiveInvalidFieldValue,
"Primitive op 'cylinder' at index 0 has invalid field 'radius' value; expected a numeric value greater than 0.");
@@ -512,13 +650,17 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Rejects_Sphere_MissingRadius() =>
AssertSingleValidationError(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "sphere", "id": "s1" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: sphere
+ id: s1
""",
FirmamentDiagnosticCodes.PrimitiveMissingRequiredField,
"Primitive op 'sphere' at index 0 is missing required field 'radius'.");
@@ -527,13 +669,18 @@ public sealed class FirmamentScaffoldTests
public void Compiler_Rejects_Sphere_NonPositiveRadius() =>
AssertSingleValidationError(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "sphere", "id": "s1", "radius": 0 }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: sphere
+ id: s1
+ radius: 0
""",
FirmamentDiagnosticCodes.PrimitiveInvalidFieldValue,
"Primitive op 'sphere' at index 0 has invalid field 'radius' value; expected a numeric value greater than 0.");
@@ -543,13 +690,20 @@ public sealed class FirmamentScaffoldTests
{
var compiler = new FirmamentCompiler();
var source = """
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "box", "id": "b1", "size": [1, 2] }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: box
+ id: b1
+ size[2]:
+ 1
+ 2
""";
var first = compiler.Compile(new FirmamentCompileRequest(new FirmamentSourceDocument(source)));
@@ -619,26 +773,104 @@ public sealed class FirmamentScaffoldTests
var compiler = new FirmamentCompiler();
var payload = opName switch
{
- "box" => "{ \"op\": \"box\", \"id\": \"b1\", \"size\": [1, 1, 1] }",
- "cylinder" => "{ \"op\": \"cylinder\", \"id\": \"c1\", \"radius\": 1, \"height\": 2 }",
- "sphere" => "{ \"op\": \"sphere\", \"id\": \"s1\", \"radius\": 1 }",
- "add" => "{ \"op\": \"box\", \"id\": \"b1\", \"size\": [1, 1, 1] }, { \"op\": \"add\", \"id\": \"a1\", \"to\": \"b1\", \"with\": { \"op\": \"sphere\" } }",
- "subtract" => "{ \"op\": \"box\", \"id\": \"b1\", \"size\": [1, 1, 1] }, { \"op\": \"subtract\", \"id\": \"s1\", \"from\": \"b1\", \"with\": { \"op\": \"sphere\" } }",
- "intersect" => "{ \"op\": \"box\", \"id\": \"b1\", \"size\": [1, 1, 1] }, { \"op\": \"intersect\", \"id\": \"i1\", \"left\": \"b1\", \"with\": { \"op\": \"sphere\" } }",
- "expect_exists" => "{ \"op\": \"expect_exists\", \"target\": \"b1\" }",
- "expect_selectable" => "{ \"op\": \"expect_selectable\", \"target\": \"b1\", \"count\": 1 }",
- "expect_manifold" => "{ \"op\": \"expect_manifold\" }",
- _ => $"{{ \"op\": \"{opName}\" }}"
+ "box" => """
+ -
+ op: box
+ id: b1
+ size[3]:
+ 1
+ 1
+ 1
+""",
+ "cylinder" => """
+ -
+ op: cylinder
+ id: c1
+ radius: 1
+ height: 2
+""",
+ "sphere" => """
+ -
+ op: sphere
+ id: s1
+ radius: 1
+""",
+ "add" => """
+ -
+ op: box
+ id: b1
+ size[3]:
+ 1
+ 1
+ 1
+ -
+ op: add
+ id: a1
+ to: b1
+ with:
+ op: sphere
+""",
+ "subtract" => """
+ -
+ op: box
+ id: b1
+ size[3]:
+ 1
+ 1
+ 1
+ -
+ op: subtract
+ id: s1
+ from: b1
+ with:
+ op: sphere
+""",
+ "intersect" => """
+ -
+ op: box
+ id: b1
+ size[3]:
+ 1
+ 1
+ 1
+ -
+ op: intersect
+ id: i1
+ left: b1
+ with:
+ op: sphere
+""",
+ "expect_exists" => """
+ -
+ op: expect_exists
+ target: b1
+""",
+ "expect_selectable" => """
+ -
+ op: expect_selectable
+ target: b1
+ count: 1
+""",
+ "expect_manifold" => """
+ -
+ op: expect_manifold
+""",
+ _ => $$"""
+ -
+ op: {{opName}}
+"""
};
var source = $$"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- {{payload}}
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[{{((opName is "add" or "subtract" or "intersect") ? 2 : 1)}}]:
+ {{payload}}
""";
var result = compiler.Compile(new FirmamentCompileRequest(new FirmamentSourceDocument(source)));
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentValidationRequiredFieldValidationTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentValidationRequiredFieldValidationTests.cs
index 8ff44637..19d219ac 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentValidationRequiredFieldValidationTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentValidationRequiredFieldValidationTests.cs
@@ -8,52 +8,67 @@ public sealed class FirmamentValidationRequiredFieldValidationTests
public void Compiler_Accepts_ValidExpectExists() =>
AssertValidationSuccess(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "expect_exists", "target": "base.top_face" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: expect_exists
+ target: base.top_face
""");
[Fact]
public void Compiler_Accepts_ValidExpectSelectable() =>
AssertValidationSuccess(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "expect_selectable", "target": "hole", "count": 4 }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: expect_selectable
+ target: hole
+ count: 4
""");
[Fact]
public void Compiler_Accepts_ValidExpectManifold_WithoutPayload() =>
AssertValidationSuccess(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "expect_manifold" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: expect_manifold
""");
[Fact]
public void Compiler_Rejects_ExpectExists_MissingTarget() =>
AssertValidationFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "expect_exists" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: expect_exists
""",
FirmamentDiagnosticCodes.ValidationMissingRequiredField,
"Validation op 'expect_exists' at index 0 is missing required field 'target'.");
@@ -62,13 +77,17 @@ public sealed class FirmamentValidationRequiredFieldValidationTests
public void Compiler_Rejects_ExpectSelectable_MissingTarget() =>
AssertValidationFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "expect_selectable", "count": 2 }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: expect_selectable
+ count: 2
""",
FirmamentDiagnosticCodes.ValidationMissingRequiredField,
"Validation op 'expect_selectable' at index 0 is missing required field 'target'.");
@@ -77,13 +96,17 @@ public sealed class FirmamentValidationRequiredFieldValidationTests
public void Compiler_Rejects_ExpectSelectable_MissingCount() =>
AssertValidationFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "expect_selectable", "target": "base" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: expect_selectable
+ target: base
""",
FirmamentDiagnosticCodes.ValidationMissingRequiredField,
"Validation op 'expect_selectable' at index 0 is missing required field 'count'.");
@@ -92,13 +115,18 @@ public sealed class FirmamentValidationRequiredFieldValidationTests
public void Compiler_Rejects_ExpectSelectable_NonNumericCount() =>
AssertValidationFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "expect_selectable", "target": "base", "count": "many" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: expect_selectable
+ target: base
+ count: many
""",
FirmamentDiagnosticCodes.ValidationInvalidFieldTypeOrShape,
"Validation op 'expect_selectable' at index 0 has invalid field 'count'; expected a numeric scalar value.");
@@ -107,13 +135,18 @@ public sealed class FirmamentValidationRequiredFieldValidationTests
public void Compiler_Rejects_ExpectSelectable_NonIntegerCount() =>
AssertValidationFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "expect_selectable", "target": "base", "count": 1.5 }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: expect_selectable
+ target: base
+ count: 1.5
""",
FirmamentDiagnosticCodes.ValidationInvalidFieldValue,
"Validation op 'expect_selectable' at index 0 has invalid field 'count' value; expected an integer-valued number greater than 0.");
@@ -122,13 +155,18 @@ public sealed class FirmamentValidationRequiredFieldValidationTests
public void Compiler_Rejects_ExpectSelectable_NonPositiveCount() =>
AssertValidationFailure(
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "expect_selectable", "target": "base", "count": 0 }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: expect_selectable
+ target: base
+ count: 0
""",
FirmamentDiagnosticCodes.ValidationInvalidFieldValue,
"Validation op 'expect_selectable' at index 0 has invalid field 'count' value; expected an integer-valued number greater than 0.");
@@ -138,13 +176,17 @@ public sealed class FirmamentValidationRequiredFieldValidationTests
{
var source =
"""
- {
- "firmament": { "version": "1" },
- "model": { "name": "demo", "units": "mm" },
- "ops": [
- { "op": "expect_selectable", "target": "base" }
- ]
- }
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[1]:
+ -
+ op: expect_selectable
+ target: base
""";
var compiler = new FirmamentCompiler();
diff --git a/Aetheris.Kernel.Firmament/Parsing/FirmamentTopLevelParser.cs b/Aetheris.Kernel.Firmament/Parsing/FirmamentTopLevelParser.cs
index 87261de2..98b8a15e 100644
--- a/Aetheris.Kernel.Firmament/Parsing/FirmamentTopLevelParser.cs
+++ b/Aetheris.Kernel.Firmament/Parsing/FirmamentTopLevelParser.cs
@@ -1,3 +1,4 @@
+using System.Linq;
using System.Text.Json;
using Aetheris.Kernel.Core.Diagnostics;
using Aetheris.Kernel.Core.Results;
@@ -291,6 +292,41 @@ internal static class FirmamentTopLevelParser
string? currentObjectSection = null;
FirmamentToonObjectEntry? currentArrayObjectEntry = null;
FirmamentToonSection? currentArraySection = null;
+ string? currentNestedFieldName = null;
+ int currentNestedFieldIndent = -1;
+ var currentNestedLines = new List<string>();
+
+ static string CollapseNestedFieldValue(IReadOnlyList<string> nestedLines)
+ {
+ var nonEmptyLines = nestedLines.Where(line => !string.IsNullOrWhiteSpace(line)).Select(line => line.Trim()).ToList();
+ if (nonEmptyLines.Count == 0)
+ {
+ return string.Empty;
+ }
+
+ if (nonEmptyLines.All(line => line.Contains(':', StringComparison.Ordinal)))
+ {
+ return "{ " + string.Join(", ", nonEmptyLines) + " }";
+ }
+
+ return "[" + string.Join(", ", nonEmptyLines) + "]";
+ }
+
+ void FlushNestedFieldIfNeeded()
+ {
+ if (currentArrayObjectEntry is null || string.IsNullOrWhiteSpace(currentNestedFieldName))
+ {
+ currentNestedFieldName = null;
+ currentNestedFieldIndent = -1;
+ currentNestedLines.Clear();
+ return;
+ }
+
+ currentArrayObjectEntry.Fields[currentNestedFieldName] = CollapseNestedFieldValue(currentNestedLines);
+ currentNestedFieldName = null;
+ currentNestedFieldIndent = -1;
+ currentNestedLines.Clear();
+ }
var lines = sourceText.Replace("\r\n", "\n", StringComparison.Ordinal).Replace("\r", "\n", StringComparison.Ordinal).Split('\n');
for (var index = 0; index < lines.Length; index++)
@@ -303,14 +339,28 @@ internal static class FirmamentTopLevelParser
continue;
}
+ var indentation = rawLine.Length - rawLine.TrimStart().Length;
+
if (char.IsWhiteSpace(rawLine[0]))
{
var field = line.Trim();
if (currentArraySection is not null)
{
+ if (!string.IsNullOrWhiteSpace(currentNestedFieldName) && indentation <= currentNestedFieldIndent)
+ {
+ FlushNestedFieldIfNeeded();
+ }
+
+ if (!string.IsNullOrWhiteSpace(currentNestedFieldName) && indentation > currentNestedFieldIndent)
+ {
+ currentNestedLines.Add(field);
+ continue;
+ }
+
if (field == "-")
{
+ FlushNestedFieldIfNeeded();
currentObjectSection = null;
currentArrayObjectEntry = new FirmamentToonObjectEntry();
currentArraySection.ArrayEntries.Add(currentArrayObjectEntry);
@@ -319,6 +369,7 @@ internal static class FirmamentTopLevelParser
if (field.StartsWith("- ", StringComparison.Ordinal))
{
+ FlushNestedFieldIfNeeded();
currentObjectSection = null;
currentArrayObjectEntry = null;
currentArraySection.ArrayEntries.Add(new FirmamentToonObjectEntry { IsObjectLike = false });
@@ -337,13 +388,24 @@ internal static class FirmamentTopLevelParser
}
var arrayFieldName = field[..arraySeparator].Trim();
+ var normalizedArrayFieldName = TryParseArrayHeader(arrayFieldName, out var normalizedSectionName)
+ ? normalizedSectionName
+ : arrayFieldName;
var arrayFieldValue = field[(arraySeparator + 1)..].Trim();
- if (arrayFieldName.Length == 0)
+ if (normalizedArrayFieldName.Length == 0)
{
return InvalidToonSyntax();
}
- currentArrayObjectEntry.Fields[arrayFieldName] = arrayFieldValue;
+ if (arrayFieldValue.Length == 0)
+ {
+ currentNestedFieldName = normalizedArrayFieldName;
+ currentNestedFieldIndent = indentation;
+ currentNestedLines.Clear();
+ continue;
+ }
+
+ currentArrayObjectEntry.Fields[normalizedArrayFieldName] = arrayFieldValue;
continue;
}
@@ -369,6 +431,7 @@ internal static class FirmamentTopLevelParser
continue;
}
+ FlushNestedFieldIfNeeded();
currentObjectSection = null;
currentArrayObjectEntry = null;
currentArraySection = null;
@@ -402,6 +465,7 @@ internal static class FirmamentTopLevelParser
currentObjectSection = header;
}
+ FlushNestedFieldIfNeeded();
return KernelResult<FirmamentToonTopLevel>.Success(new FirmamentToonTopLevel(sections));
}
diff --git a/testdata/firmament/fixtures/m0b-valid-one-op.firmament b/testdata/firmament/fixtures/m0b-valid-one-op.firmament
index 25ce96bc..78e3ffda 100644
--- a/testdata/firmament/fixtures/m0b-valid-one-op.firmament
+++ b/testdata/firmament/fixtures/m0b-valid-one-op.firmament
@@ -9,4 +9,7 @@ ops[1]:
-
op: box
id: b1
- size: [1, 2, 3]
+ size[3]:
+ 1
+ 2
+ 3
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m0b-valid-two-ops.firmament b/testdata/firmament/fixtures/m0b-valid-two-ops.firmament
index 76cb8ef9..7560db93 100644
--- a/testdata/firmament/fixtures/m0b-valid-two-ops.firmament
+++ b/testdata/firmament/fixtures/m0b-valid-two-ops.firmament
@@ -9,9 +9,13 @@ ops[2]:
-
op: box
id: b1
- size: [1, 2, 3]
+ size[3]:
+ 1
+ 2
+ 3
-
op: subtract
id: cut1
from: b1
- with: { op: cylinder }
+ with:
+ op: cylinder
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m0c-valid-known-boolean-op.firmament b/testdata/firmament/fixtures/m0c-valid-known-boolean-op.firmament
index a60a60aa..658748ae 100644
--- a/testdata/firmament/fixtures/m0c-valid-known-boolean-op.firmament
+++ b/testdata/firmament/fixtures/m0c-valid-known-boolean-op.firmament
@@ -9,9 +9,13 @@ ops[2]:
-
op: box
id: base
- size: [1, 2, 3]
+ size[3]:
+ 1
+ 2
+ 3
-
op: add
id: add1
to: base
- with: { op: sphere }
+ with:
+ op: sphere
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m1a-invalid-box-missing-id.firmament b/testdata/firmament/fixtures/m1a-invalid-box-missing-id.firmament
index 566b51b1..1c1ada21 100644
--- a/testdata/firmament/fixtures/m1a-invalid-box-missing-id.firmament
+++ b/testdata/firmament/fixtures/m1a-invalid-box-missing-id.firmament
@@ -8,4 +8,7 @@ model:
ops[1]:
-
op: box
- size: [1, 2, 3]
+ size[3]:
+ 1
+ 2
+ 3
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m1a-invalid-box-size-non-positive.firmament b/testdata/firmament/fixtures/m1a-invalid-box-size-non-positive.firmament
index fc68550b..83769508 100644
--- a/testdata/firmament/fixtures/m1a-invalid-box-size-non-positive.firmament
+++ b/testdata/firmament/fixtures/m1a-invalid-box-size-non-positive.firmament
@@ -9,4 +9,7 @@ ops[1]:
-
op: box
id: b1
- size: [1, 0, 3]
+ size[3]:
+ 1
+ 0
+ 3
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m1a-invalid-box-size-shape.firmament b/testdata/firmament/fixtures/m1a-invalid-box-size-shape.firmament
index d0578fe4..7fefa50e 100644
--- a/testdata/firmament/fixtures/m1a-invalid-box-size-shape.firmament
+++ b/testdata/firmament/fixtures/m1a-invalid-box-size-shape.firmament
@@ -9,4 +9,6 @@ ops[1]:
-
op: box
id: b1
- size: [1, 2]
+ size[2]:
+ 1
+ 2
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m1b-invalid-add-missing-id.firmament b/testdata/firmament/fixtures/m1b-invalid-add-missing-id.firmament
index 73421a36..0d7c01aa 100644
--- a/testdata/firmament/fixtures/m1b-invalid-add-missing-id.firmament
+++ b/testdata/firmament/fixtures/m1b-invalid-add-missing-id.firmament
@@ -9,4 +9,5 @@ ops[1]:
-
op: add
to: base
- with: { op: box }
+ with:
+ op: box
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m1b-invalid-add-missing-to.firmament b/testdata/firmament/fixtures/m1b-invalid-add-missing-to.firmament
index 79b20ab4..5dcdc0fc 100644
--- a/testdata/firmament/fixtures/m1b-invalid-add-missing-to.firmament
+++ b/testdata/firmament/fixtures/m1b-invalid-add-missing-to.firmament
@@ -9,4 +9,5 @@ ops[1]:
-
op: add
id: a1
- with: { op: box }
+ with:
+ op: box
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m1b-invalid-add-missing-with-op.firmament b/testdata/firmament/fixtures/m1b-invalid-add-missing-with-op.firmament
index f6bbb838..c04fa21f 100644
--- a/testdata/firmament/fixtures/m1b-invalid-add-missing-with-op.firmament
+++ b/testdata/firmament/fixtures/m1b-invalid-add-missing-with-op.firmament
@@ -10,4 +10,5 @@ ops[1]:
op: add
id: a1
to: base
- with: { id: tool }
+ with:
+ id: tool
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m1b-invalid-intersect-missing-id.firmament b/testdata/firmament/fixtures/m1b-invalid-intersect-missing-id.firmament
index 98b0c7c8..eb14c863 100644
--- a/testdata/firmament/fixtures/m1b-invalid-intersect-missing-id.firmament
+++ b/testdata/firmament/fixtures/m1b-invalid-intersect-missing-id.firmament
@@ -9,4 +9,5 @@ ops[1]:
-
op: intersect
left: base
- with: { op: box }
+ with:
+ op: box
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m1b-invalid-intersect-missing-left.firmament b/testdata/firmament/fixtures/m1b-invalid-intersect-missing-left.firmament
index 6451104c..85a57a4c 100644
--- a/testdata/firmament/fixtures/m1b-invalid-intersect-missing-left.firmament
+++ b/testdata/firmament/fixtures/m1b-invalid-intersect-missing-left.firmament
@@ -9,4 +9,5 @@ ops[1]:
-
op: intersect
id: i1
- with: { op: box }
+ with:
+ op: box
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m1b-invalid-intersect-missing-with-op.firmament b/testdata/firmament/fixtures/m1b-invalid-intersect-missing-with-op.firmament
index 9c3791e0..36c24da2 100644
--- a/testdata/firmament/fixtures/m1b-invalid-intersect-missing-with-op.firmament
+++ b/testdata/firmament/fixtures/m1b-invalid-intersect-missing-with-op.firmament
@@ -10,4 +10,5 @@ ops[1]:
op: intersect
id: i1
left: base
- with: { id: tool }
+ with:
+ id: tool
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m1b-invalid-subtract-missing-from.firmament b/testdata/firmament/fixtures/m1b-invalid-subtract-missing-from.firmament
index 540df1d4..3d304ba5 100644
--- a/testdata/firmament/fixtures/m1b-invalid-subtract-missing-from.firmament
+++ b/testdata/firmament/fixtures/m1b-invalid-subtract-missing-from.firmament
@@ -9,4 +9,5 @@ ops[1]:
-
op: subtract
id: s1
- with: { op: box }
+ with:
+ op: box
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m1b-invalid-subtract-missing-id.firmament b/testdata/firmament/fixtures/m1b-invalid-subtract-missing-id.firmament
index 042a3d71..8ada58f8 100644
--- a/testdata/firmament/fixtures/m1b-invalid-subtract-missing-id.firmament
+++ b/testdata/firmament/fixtures/m1b-invalid-subtract-missing-id.firmament
@@ -9,4 +9,5 @@ ops[1]:
-
op: subtract
from: base
- with: { op: box }
+ with:
+ op: box
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m1b-invalid-subtract-missing-with-op.firmament b/testdata/firmament/fixtures/m1b-invalid-subtract-missing-with-op.firmament
index 83ffbbc4..850c92c3 100644
--- a/testdata/firmament/fixtures/m1b-invalid-subtract-missing-with-op.firmament
+++ b/testdata/firmament/fixtures/m1b-invalid-subtract-missing-with-op.firmament
@@ -10,4 +10,5 @@ ops[1]:
op: subtract
id: s1
from: base
- with: { id: tool }
+ with:
+ id: tool
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m1b-valid-add.firmament b/testdata/firmament/fixtures/m1b-valid-add.firmament
index 27b9d217..56e9fbfc 100644
--- a/testdata/firmament/fixtures/m1b-valid-add.firmament
+++ b/testdata/firmament/fixtures/m1b-valid-add.firmament
@@ -9,9 +9,13 @@ ops[2]:
-
op: box
id: base
- size: [1, 2, 3]
+ size[3]:
+ 1
+ 2
+ 3
-
op: add
id: add1
to: base
- with: { op: box }
+ with:
+ op: box
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m1b-valid-intersect.firmament b/testdata/firmament/fixtures/m1b-valid-intersect.firmament
index e9985e23..3b9f6bfb 100644
--- a/testdata/firmament/fixtures/m1b-valid-intersect.firmament
+++ b/testdata/firmament/fixtures/m1b-valid-intersect.firmament
@@ -9,9 +9,13 @@ ops[2]:
-
op: box
id: base
- size: [1, 2, 3]
+ size[3]:
+ 1
+ 2
+ 3
-
op: intersect
id: int1
left: base
- with: { op: cylinder }
+ with:
+ op: cylinder
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m1b-valid-subtract.firmament b/testdata/firmament/fixtures/m1b-valid-subtract.firmament
index b557b133..9ccef73b 100644
--- a/testdata/firmament/fixtures/m1b-valid-subtract.firmament
+++ b/testdata/firmament/fixtures/m1b-valid-subtract.firmament
@@ -9,9 +9,13 @@ ops[2]:
-
op: box
id: base
- size: [1, 2, 3]
+ size[3]:
+ 1
+ 2
+ 3
-
op: subtract
id: sub1
from: base
- with: { op: sphere }
+ with:
+ op: sphere
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m2a-invalid-add-to-missing-id.firmament b/testdata/firmament/fixtures/m2a-invalid-add-to-missing-id.firmament
index 0c0f781c..7cca44df 100644
--- a/testdata/firmament/fixtures/m2a-invalid-add-to-missing-id.firmament
+++ b/testdata/firmament/fixtures/m2a-invalid-add-to-missing-id.firmament
@@ -10,4 +10,5 @@ ops[1]:
op: add
id: fused
to: missing
- with: { op: box }
+ with:
+ op: box
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m2a-invalid-duplicate-id-across-primitive-boolean.firmament b/testdata/firmament/fixtures/m2a-invalid-duplicate-id-across-primitive-boolean.firmament
index 499d0870..ae41081b 100644
--- a/testdata/firmament/fixtures/m2a-invalid-duplicate-id-across-primitive-boolean.firmament
+++ b/testdata/firmament/fixtures/m2a-invalid-duplicate-id-across-primitive-boolean.firmament
@@ -9,10 +9,13 @@ ops[2]:
-
op: box
id: base
- size: [10, 20, 30]
-
+ size[3]:
+ 10
+ 20
+ 30
-
op: add
id: base
to: base
- with: { op: sphere }
+ with:
+ op: sphere
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m2a-invalid-duplicate-primitive-id.firmament b/testdata/firmament/fixtures/m2a-invalid-duplicate-primitive-id.firmament
index 5384a098..b0c83bb3 100644
--- a/testdata/firmament/fixtures/m2a-invalid-duplicate-primitive-id.firmament
+++ b/testdata/firmament/fixtures/m2a-invalid-duplicate-primitive-id.firmament
@@ -9,8 +9,10 @@ ops[2]:
-
op: box
id: base
- size: [10, 20, 30]
-
+ size[3]:
+ 10
+ 20
+ 30
-
op: sphere
id: base
diff --git a/testdata/firmament/fixtures/m2a-invalid-forward-reference.firmament b/testdata/firmament/fixtures/m2a-invalid-forward-reference.firmament
index 4e1cb5d3..e5830eea 100644
--- a/testdata/firmament/fixtures/m2a-invalid-forward-reference.firmament
+++ b/testdata/firmament/fixtures/m2a-invalid-forward-reference.firmament
@@ -10,9 +10,12 @@ ops[2]:
op: add
id: fused
to: later
- with: { op: box }
-
+ with:
+ op: box
-
op: box
id: later
- size: [10, 20, 30]
+ size[3]:
+ 10
+ 20
+ 30
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m2a-invalid-intersect-left-missing-id.firmament b/testdata/firmament/fixtures/m2a-invalid-intersect-left-missing-id.firmament
index 6560400c..934df2d2 100644
--- a/testdata/firmament/fixtures/m2a-invalid-intersect-left-missing-id.firmament
+++ b/testdata/firmament/fixtures/m2a-invalid-intersect-left-missing-id.firmament
@@ -10,4 +10,5 @@ ops[1]:
op: intersect
id: clip1
left: missing
- with: { op: sphere }
+ with:
+ op: sphere
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m2a-invalid-subtract-from-missing-id.firmament b/testdata/firmament/fixtures/m2a-invalid-subtract-from-missing-id.firmament
index 0d3a223a..ccd63582 100644
--- a/testdata/firmament/fixtures/m2a-invalid-subtract-from-missing-id.firmament
+++ b/testdata/firmament/fixtures/m2a-invalid-subtract-from-missing-id.firmament
@@ -10,4 +10,5 @@ ops[1]:
op: subtract
id: cut1
from: missing
- with: { op: cylinder }
+ with:
+ op: cylinder
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m2a-valid-boolean-references-earlier-id.firmament b/testdata/firmament/fixtures/m2a-valid-boolean-references-earlier-id.firmament
index 5f9adec1..57d92c0c 100644
--- a/testdata/firmament/fixtures/m2a-valid-boolean-references-earlier-id.firmament
+++ b/testdata/firmament/fixtures/m2a-valid-boolean-references-earlier-id.firmament
@@ -9,10 +9,13 @@ ops[2]:
-
op: box
id: base
- size: [10, 20, 30]
-
+ size[3]:
+ 10
+ 20
+ 30
-
op: add
id: fused
to: base
- with: { op: cylinder }
+ with:
+ op: cylinder
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m2a-valid-chained-features.firmament b/testdata/firmament/fixtures/m2a-valid-chained-features.firmament
index bd7d1f21..5cd045a2 100644
--- a/testdata/firmament/fixtures/m2a-valid-chained-features.firmament
+++ b/testdata/firmament/fixtures/m2a-valid-chained-features.firmament
@@ -9,22 +9,25 @@ ops[4]:
-
op: box
id: base
- size: [10, 20, 30]
-
+ size[3]:
+ 10
+ 20
+ 30
-
op: subtract
id: cut1
from: base
- with: { op: cylinder }
-
+ with:
+ op: cylinder
-
op: intersect
id: clipped
left: cut1
- with: { op: sphere }
-
+ with:
+ op: sphere
-
op: add
id: merged
to: clipped
- with: { op: box }
+ with:
+ op: box
\ No newline at end of file
diff --git a/testdata/firmament/fixtures/m2a-valid-two-primitives-distinct-ids.firmament b/testdata/firmament/fixtures/m2a-valid-two-primitives-distinct-ids.firmament
index 2c8e0bb9..53b4d90d 100644
--- a/testdata/firmament/fixtures/m2a-valid-two-primitives-distinct-ids.firmament
+++ b/testdata/firmament/fixtures/m2a-valid-two-primitives-distinct-ids.firmament
@@ -9,8 +9,10 @@ ops[2]:
-
op: box
id: base
- size: [10, 20, 30]
-
+ size[3]:
+ 10
+ 20
+ 30
-
op: sphere
id: cap