Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Implement Firmament V2 Box with derivation

Yuechen Li37abfaea591f
diff --git a/Aetheris.CLI.Tests/FirmamentFixtureCorpusTests.cs b/Aetheris.CLI.Tests/FirmamentFixtureCorpusTests.cs
index 78b9e05d..0e5c0515 100644
--- a/Aetheris.CLI.Tests/FirmamentFixtureCorpusTests.cs
+++ b/Aetheris.CLI.Tests/FirmamentFixtureCorpusTests.cs
@@ -179,7 +179,7 @@ public sealed class FirmamentFixtureCorpusTests
var fixture = LoadMetadata(path);
Assert.Equal("FirmamentV2", fixture["syntax-version"]);
Assert.Equal("SemanticRefs", fixture["category"]);
- Assert.True(fixture.ContainsKey("expected-diagnostic"), path);
+ if (fixture["implementation"] != "parser-backed" || fixture["validity"] == "invalid") Assert.True(fixture.ContainsKey("expected-diagnostic"), path);
}
}
@@ -234,13 +234,13 @@ public sealed class FirmamentFixtureCorpusTests
public void FirmamentV2RecordDerivation_MetadataRecognized()
{
var fixtures = DiscoverV2Fixtures().Where(p => p.Contains("/RecordDerivation/", StringComparison.Ordinal)).ToArray();
- Assert.Equal(6, fixtures.Length);
+ Assert.Equal(8, fixtures.Length);
foreach (var path in fixtures)
{
var fixture = LoadMetadata(path);
Assert.Equal("FirmamentV2", fixture["syntax-version"]);
Assert.Equal("RecordDerivation", fixture["category"]);
- Assert.True(fixture.ContainsKey("expected-diagnostic"), path);
+ if (fixture["implementation"] != "parser-backed" || fixture["validity"] == "invalid") Assert.True(fixture.ContainsKey("expected-diagnostic"), path);
}
}
@@ -252,10 +252,10 @@ public sealed class FirmamentFixtureCorpusTests
using var doc = Trace(path);
var metadata = LoadMetadata(path);
var diagnostics = doc.RootElement.GetProperty("diagnostics").EnumerateArray().Select(x => x.GetString()).ToArray();
- Assert.False(doc.RootElement.GetProperty("fixture").GetProperty("parserBacked").GetBoolean());
+ Assert.Equal(metadata["implementation"] == "parser-backed", doc.RootElement.GetProperty("fixture").GetProperty("parserBacked").GetBoolean());
Assert.True(doc.RootElement.GetProperty("fixture").GetProperty("expectationSatisfied").GetBoolean(), path);
Assert.Equal(metadata["expected-stage"], doc.RootElement.GetProperty("actualStageReached").GetString());
- Assert.Contains(metadata["expected-diagnostic"], diagnostics);
+ if (metadata.TryGetValue("expected-diagnostic", out var expectedDiagnostic)) Assert.Contains(expectedDiagnostic, diagnostics);
Assert.DoesNotContain("air-x11-firmament-parse-failed", diagnostics);
}
}
@@ -266,8 +266,8 @@ public sealed class FirmamentFixtureCorpusTests
var expected = new[]
{
(Path: "RecordDerivation/invalid/with-degenerate-box-v2.invalid.firmfixture", Diagnostic: "firmament-degenerate-dimension"),
- (Path: "RecordDerivation/invalid/with-selector-target-v2.invalid.firmfixture", Diagnostic: "firmament-with-requires-record"),
- (Path: "RecordDerivation/invalid/with-unknown-field-v2.invalid.firmfixture", Diagnostic: "firmament-with-field-not-found")
+ (Path: "RecordDerivation/invalid/with-selector-target-v2.invalid.firmfixture", Diagnostic: "firmament-v2-with-requires-record"),
+ (Path: "RecordDerivation/invalid/with-unknown-field-v2.invalid.firmfixture", Diagnostic: "firmament-v2-with-field-not-found")
};
foreach (var item in expected)
diff --git a/Aetheris.CLI/AirTrace.cs b/Aetheris.CLI/AirTrace.cs
index 1823099a..5ade5892 100644
--- a/Aetheris.CLI/AirTrace.cs
+++ b/Aetheris.CLI/AirTrace.cs
@@ -51,7 +51,8 @@ internal sealed record AirTraceFeatureAirSummary(bool ParserBacked, string Sourc
internal sealed record AirTraceConstructiveAirSummary(string NodeKind, string CanonicalForm, string SourceFeatureAirNodeKind, string ProfileKind, double Width, double Depth, double Height, string ExtrusionAxis, string ConstructionIntent, string RouteKind, string StageReached, IReadOnlyList<string> Diagnostics, IReadOnlyList<string> Guarantees);
internal sealed record AirTraceProfileEmissionSummary(bool WrapperInvoked, string EmitterName, bool Succeeded, double Width, double Depth, double Height, string StageReached, AirTraceProfileEmissionTopologySummary? TopologySummary, AirTraceProfileEmissionStepSmokeSummary StepSmoke, IReadOnlyList<string> Diagnostics, IReadOnlyList<string> Guarantees);
internal sealed record AirTraceProfileEmissionTopologySummary(int Vertices, int Edges, int Faces, int PlanarFaces, int CylindricalFaces, int Loops, int Coedges, int? CapFaces, int? SideFaces, string? Bounds);
-internal sealed record AirTraceFirmamentV2Summary(string SyntaxVersion, string ModelName, string Units, string SolidName, string RecordType, IReadOnlyList<double> Size, string Stage);
+internal sealed record AirTraceFirmamentV2Summary(string SyntaxVersion, string ModelName, string Units, string SolidName, string RecordType, IReadOnlyList<double> Size, string Stage, IReadOnlyList<AirTraceFirmamentV2SolidSummary> Solids);
+internal sealed record AirTraceFirmamentV2SolidSummary(string Name, string RecordType, IReadOnlyList<double> Size, string? DerivedFrom, IReadOnlyDictionary<string, IReadOnlyList<double>> Overrides);
internal sealed record AirTraceProfileEmissionStepSmokeSummary(bool WasChecked, bool Succeeded, bool RequiredMarkersPresent, bool ForbiddenMarkersAbsent, IReadOnlyList<string> Diagnostics);
internal sealed record AirTraceDimensionsSummary(double Width, double Depth, double Height);
internal sealed record AirTraceAirSummary(string Node, string Route, string SelectionClass, string Rule, string ConstructionHistory, string FeatureName, string FeatureId, string ProvenanceMilestone);
@@ -158,7 +159,7 @@ internal static class AirTraceReportBuilder
profileEmissionProbe.Diagnostics,
profileEmissionProbe.Guarantees);
- var v2 = frontend.FirmamentV2 is null ? null : new AirTraceFirmamentV2Summary(frontend.FirmamentV2.SyntaxVersion, frontend.FirmamentV2.ModelName, frontend.FirmamentV2.Units, frontend.FirmamentV2.SolidName, frontend.FirmamentV2.RecordType, frontend.FirmamentV2.Size, frontend.FirmamentV2.StageReached);
+ var v2 = frontend.FirmamentV2 is null ? null : new AirTraceFirmamentV2Summary(frontend.FirmamentV2.SyntaxVersion, frontend.FirmamentV2.ModelName, frontend.FirmamentV2.Units, frontend.FirmamentV2.SolidName, frontend.FirmamentV2.RecordType, frontend.FirmamentV2.Size, frontend.FirmamentV2.StageReached, frontend.FirmamentV2.Solids.Select(s => new AirTraceFirmamentV2SolidSummary(s.Name, s.RecordType, s.Size, s.DerivedFrom, s.Overrides)).ToArray());
return new(isFirmamentV2 ? "AIR-FIRMAMENT-X1" : "AIR-X11", "trace", "lowering", "firmfixture", fixture.CaseName, expectationSatisfied, frontend.FrontendSummary,
new(constructiveAir?.NodeKind ?? featureAir?.NodeKind ?? "FirmamentPrimitive", constructiveAir?.RouteKind ?? "none", "none", "none", "parser-backed-source-fixture", fixture.CaseName, fixture.CaseName, "AIR-X11"),
@@ -322,9 +323,19 @@ internal static class AirTraceTextRenderer
b.AppendLine($" Stage: {r.FirmamentV2.Stage}");
b.AppendLine($" Model: {r.FirmamentV2.ModelName}");
b.AppendLine($" Units: {r.FirmamentV2.Units}");
- b.AppendLine($" Solid: {r.FirmamentV2.SolidName}");
- b.AppendLine($" Record: {r.FirmamentV2.RecordType}");
- b.AppendLine($" Size: [{string.Join(", ", r.FirmamentV2.Size.Select(v => v.ToString("g", System.Globalization.CultureInfo.InvariantCulture)))}]");
+ foreach (var solid in r.FirmamentV2.Solids)
+ {
+ b.AppendLine();
+ b.AppendLine($" Solid: {solid.Name}");
+ b.AppendLine($" Record: {solid.RecordType}");
+ if (!string.IsNullOrWhiteSpace(solid.DerivedFrom)) b.AppendLine($" DerivedFrom: {solid.DerivedFrom}");
+ if (solid.Overrides.Count > 0)
+ {
+ b.AppendLine(" With:");
+ foreach (var ov in solid.Overrides) b.AppendLine($" {ov.Key}: [{string.Join(", ", ov.Value.Select(v => v.ToString("g", System.Globalization.CultureInfo.InvariantCulture)))}]");
+ }
+ b.AppendLine($" Size: [{string.Join(", ", solid.Size.Select(v => v.ToString("g", System.Globalization.CultureInfo.InvariantCulture)))}]");
+ }
if (r.FeatureAir is not null) b.AppendLine($" Feature AIR: {r.FeatureAir.NodeKind}");
b.AppendLine();
}
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentV2ParserTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentV2ParserTests.cs
index d01db45e..74c11444 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentV2ParserTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentV2ParserTests.cs
@@ -65,11 +65,82 @@ public sealed class FirmamentV2ParserTests
}
[Fact]
- public void FirmamentV2Parser_UnsupportedConstruct_RemainsMetadataClassified()
+ public void FirmamentV2Parser_WithBox_ParsesBaseAndDerivedSolid()
{
var result = FirmamentV2Parser.Parse(Source("RecordDerivation/valid/box-with-size-variant-v2.valid.firmfixture"));
+ Assert.True(result.IsSuccess, string.Join(", ", result.Diagnostics));
+ var document = result.Document!;
+ Assert.Equal("BoxVariant", document.ModelName);
+ Assert.Equal("mm", document.Units);
+ Assert.Equal(2, document.Solids.Count);
+ Assert.Equal("base", document.Solids[0].Name);
+ Assert.Equal("Box", document.Solids[0].RecordType);
+ Assert.Equal([10, 8, 6], document.Solids[0].Box.Size);
+ Assert.Equal("tall", document.Solids[1].Name);
+ Assert.Equal("base", document.Solids[1].DerivedFrom);
+ Assert.Equal([10, 8, 12], document.Solids[1].Overrides!["size"]);
+ }
+
+ [Fact]
+ public void FirmamentV2Parser_WithBox_LowersDerivedToFeatureAir()
+ {
+ var result = FirmamentFrontendTraceProbe.ParseV2Only(Source("RecordDerivation/valid/box-with-size-variant-v2.valid.firmfixture"));
+ Assert.True(result.ParseSucceeded, string.Join(", ", result.Diagnostics));
+ Assert.Equal("FirmamentV2Parser", result.ParserName);
+ Assert.Equal("CreateBox", result.FeatureAir!.FeatureAirNodeKind);
+ Assert.Equal(10, result.FeatureAir.SourceDimensions!.Width);
+ Assert.Equal(8, result.FeatureAir.SourceDimensions.Depth);
+ Assert.Equal(12, result.FeatureAir.SourceDimensions.Height);
+ Assert.Equal("tall", result.FirmamentV2!.SolidName);
+ }
+
+ [Fact]
+ public void FirmamentV2Parser_WithBox_BaseRemainsUnchanged()
+ {
+ var result = FirmamentV2Parser.Parse(Source("RecordDerivation/valid/box-with-size-variant-v2.valid.firmfixture"));
+ Assert.True(result.IsSuccess, string.Join(", ", result.Diagnostics));
+ Assert.Equal([10, 8, 6], result.Document!.Solids.Single(s => s.Name == "base").Box.Size);
+ Assert.Equal([10, 8, 12], result.Document.Solids.Single(s => s.Name == "tall").Box.Size);
+ }
+
+ [Fact]
+ public void FirmamentV2Parser_WithBox_DegenerateDerivedSize_IsDiagnostic()
+ {
+ var result = FirmamentV2Parser.Parse(Source("RecordDerivation/invalid/with-degenerate-box-v2.invalid.firmfixture"));
+ Assert.False(result.IsSuccess);
+ Assert.Contains(FirmamentV2Parser.DegenerateDimension, result.Diagnostics);
+ }
+
+ [Fact]
+ public void FirmamentV2Parser_WithBox_UnknownField_IsDiagnostic()
+ {
+ var result = FirmamentV2Parser.Parse(Source("RecordDerivation/invalid/with-unknown-field-v2.invalid.firmfixture"));
Assert.False(result.IsSuccess);
- Assert.Contains(FirmamentV2Parser.UnsupportedConstruct, result.Diagnostics);
+ Assert.Contains(FirmamentV2Parser.WithFieldNotFound, result.Diagnostics);
+ }
+
+ [Fact]
+ public void FirmamentV2Parser_WithBox_UndefinedBase_IsDiagnostic()
+ {
+ var result = FirmamentV2Parser.Parse(Source("RecordDerivation/invalid/with-undefined-base-v2.invalid.firmfixture"));
+ Assert.False(result.IsSuccess);
+ Assert.Contains(FirmamentV2Parser.NameUnresolved, result.Diagnostics);
+ }
+
+ [Fact]
+ public void FirmamentV2Parser_WithBox_DuplicateName_IsDiagnostic()
+ {
+ var result = FirmamentV2Parser.Parse(Source("RecordDerivation/invalid/with-duplicate-solid-name-v2.invalid.firmfixture"));
+ Assert.False(result.IsSuccess);
+ Assert.Contains(FirmamentV2Parser.DuplicateName, result.Diagnostics);
+ }
+
+ [Fact]
+ public void FirmamentV2Parser_WithBox_DoesNotUseV1Parser()
+ {
+ var result = FirmamentFrontendTraceProbe.ParseV2Only(Source("RecordDerivation/valid/box-with-size-variant-v2.valid.firmfixture"));
+ Assert.Equal("FirmamentV2Parser", result.ParserName);
+ Assert.Contains("firmament-v2-no-v1-parser", result.Diagnostics);
}
private static string Source(string relative)
diff --git a/Aetheris.Kernel.Firmament/FirmamentFrontendTraceProbe.cs b/Aetheris.Kernel.Firmament/FirmamentFrontendTraceProbe.cs
index 526c8985..ae75ed37 100644
--- a/Aetheris.Kernel.Firmament/FirmamentFrontendTraceProbe.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentFrontendTraceProbe.cs
@@ -16,7 +16,8 @@ public sealed record FirmamentFrontendTraceProbeResult(
FirmamentConstructiveAirTraceSummary? ConstructiveAir = null,
FirmamentV2TraceSummary? FirmamentV2 = null);
-public sealed record FirmamentV2TraceSummary(string SyntaxVersion, string ModelName, string Units, string SolidName, string RecordType, IReadOnlyList<double> Size, string StageReached);
+public sealed record FirmamentV2TraceSummary(string SyntaxVersion, string ModelName, string Units, string SolidName, string RecordType, IReadOnlyList<double> Size, string StageReached, IReadOnlyList<FirmamentV2SolidTraceSummary> Solids);
+public sealed record FirmamentV2SolidTraceSummary(string Name, string RecordType, IReadOnlyList<double> Size, string? DerivedFrom, IReadOnlyDictionary<string, IReadOnlyList<double>> Overrides);
public sealed record FirmamentPrimitiveAirTraceSummary(
bool ParserBacked,
@@ -62,7 +63,8 @@ public static class FirmamentFrontendTraceProbe
}
var document = parseResult.Document;
- var dimensions = new FirmamentTraceDimensions(document.Solid.Box.Size[0], document.Solid.Box.Size[1], document.Solid.Box.Size[2]);
+ var loweredSolid = document.Solids.LastOrDefault(s => s.IsDerived) ?? document.Solid;
+ var dimensions = new FirmamentTraceDimensions(loweredSolid.Box.Size[0], loweredSolid.Box.Size[1], loweredSolid.Box.Size[2]);
var featureDiagnostics = new[]
{
"firmament-v2-box-record-recognized",
@@ -74,7 +76,7 @@ public static class FirmamentFrontendTraceProbe
var featureAir = new FirmamentPrimitiveAirTraceSummary(
ParserBacked: true,
- SourceOpKind: document.Solid.RecordType,
+ SourceOpKind: loweredSolid.RecordType,
FeatureAirNodeKind: "CreateBox",
SourceDimensions: dimensions,
ConstructionIntent: "Box",
@@ -95,11 +97,11 @@ public static class FirmamentFrontendTraceProbe
"FirmamentV2Parser",
true,
"feature-air",
- $"Firmament V2 parsed model '{document.ModelName}' with units '{document.Units}', solid '{document.Solid.Name}: {document.Solid.RecordType}', and created Feature AIR CreateBox summary.",
+ $"Firmament V2 parsed model '{document.ModelName}' with units '{document.Units}', lowered solid '{loweredSolid.Name}: {loweredSolid.RecordType}', and created Feature AIR CreateBox summary.",
featureDiagnostics,
featureAir,
null,
- new FirmamentV2TraceSummary("FirmamentV2", document.ModelName, document.Units, document.Solid.Name, document.Solid.RecordType, document.Solid.Box.Size, "feature-air"));
+ new FirmamentV2TraceSummary("FirmamentV2", document.ModelName, document.Units, loweredSolid.Name, loweredSolid.RecordType, loweredSolid.Box.Size, "feature-air", document.Solids.Select(s => new FirmamentV2SolidTraceSummary(s.Name, s.RecordType, s.Box.Size, s.DerivedFrom, s.Overrides ?? new Dictionary<string, IReadOnlyList<double>>())).ToArray()));
}
public static FirmamentFrontendTraceProbeResult ParseOnly(string sourceText)
diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.cs
index df9c1c09..b1a65883 100644
--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.cs
@@ -1,7 +1,15 @@
namespace Aetheris.Kernel.Firmament.FirmamentV2;
-public sealed record FirmamentV2Document(string ModelName, string Units, FirmamentV2SolidBinding Solid);
-public sealed record FirmamentV2SolidBinding(string Name, string RecordType, FirmamentV2BoxRecord Box);
+public sealed record FirmamentV2Document(string ModelName, string Units, IReadOnlyList<FirmamentV2SolidBinding> Solids)
+{
+ public FirmamentV2SolidBinding Solid => Solids[^1];
+}
+
+public sealed record FirmamentV2SolidBinding(string Name, string RecordType, FirmamentV2BoxRecord Box, string? DerivedFrom = null, IReadOnlyDictionary<string, IReadOnlyList<double>>? Overrides = null)
+{
+ public bool IsDerived => !string.IsNullOrWhiteSpace(DerivedFrom);
+}
+
public sealed record FirmamentV2BoxRecord(IReadOnlyList<double> Size);
public sealed record FirmamentV2ParseResult(bool IsSuccess, FirmamentV2Document? Document, IReadOnlyList<string> Diagnostics)
{
diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs
index 6805b284..3410e67a 100644
--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs
@@ -13,11 +13,21 @@ public static class FirmamentV2Parser
public const string BoxMissingSize = "firmament-v2-box-missing-size";
public const string BoxSizeArity = "firmament-v2-box-size-arity";
public const string DegenerateDimension = "firmament-degenerate-dimension";
+ public const string NameUnresolved = "firmament-v2-name-unresolved";
+ public const string DuplicateName = "firmament-v2-duplicate-name";
+ public const string WithRequiresRecord = "firmament-v2-with-requires-record";
+ public const string WithRequiresBoxRecord = "firmament-v2-with-requires-box-record";
+ public const string WithFieldNotFound = "firmament-v2-with-field-not-found";
+ public const string WithFieldTypeMismatch = "firmament-v2-with-field-type-mismatch";
+ public const string WithForwardReference = "firmament-v2-with-forward-reference";
+ public const string WithDerivedRecordInvalid = "firmament-v2-with-derived-record-invalid";
private static readonly Regex ModelRegex = new(@"\bmodel\s+(?<name>[A-Za-z_][A-Za-z0-9_]*)\s*\{", RegexOptions.CultureInvariant);
private static readonly Regex UnitsRegex = new(@"\bunits\s+(?<units>[A-Za-z_][A-Za-z0-9_]*)\b", RegexOptions.CultureInvariant);
- private static readonly Regex SolidRegex = new(@"\bsolid\s+(?<name>[A-Za-z_][A-Za-z0-9_]*)\s*:\s*(?<type>[A-Za-z_][A-Za-z0-9_]*)\s*\{(?<body>.*?)\}", RegexOptions.CultureInvariant | RegexOptions.Singleline);
+ private static readonly Regex SolidRegex = new(@"\bsolid\s+(?<name>[A-Za-z_][A-Za-z0-9_]*)\s*:\s*(?<target>[A-Za-z_][A-Za-z0-9_]*)(?<with>\s+with)?\s*\{(?<body>.*?)\}", RegexOptions.CultureInvariant | RegexOptions.Singleline);
+ private static readonly Regex LegacyEqualsSolidRegex = new(@"\bsolid\s+(?<name>[A-Za-z_][A-Za-z0-9_]*)\s*=\s*(?<target>[A-Za-z_][A-Za-z0-9_]*)(?<with>\s+with)?\s*\{(?<body>.*?)\}", RegexOptions.CultureInvariant | RegexOptions.Singleline);
private static readonly Regex SizeRegex = new(@"\bsize\s*:\s*\[(?<values>[^\]]*)\]", RegexOptions.CultureInvariant | RegexOptions.Singleline);
+ private static readonly Regex FieldRegex = new(@"(?<field>@[A-Za-z_][A-Za-z0-9_]*|[A-Za-z_][A-Za-z0-9_\.]*)\s*:", RegexOptions.CultureInvariant);
public static FirmamentV2ParseResult Parse(string sourceText)
{
@@ -34,68 +44,87 @@ public static class FirmamentV2Parser
if (!unitsMatch.Success) diagnostics.Add(MissingUnits);
else if (!string.Equals(unitsMatch.Groups["units"].Value, "mm", StringComparison.Ordinal)) diagnostics.Add(UnsupportedConstruct);
- var solidMatches = SolidRegex.Matches(source);
- if (solidMatches.Count == 0) diagnostics.Add(MissingSolid);
- if (solidMatches.Count > 1) diagnostics.Add(UnsupportedConstruct);
+ var solidMatches = SolidRegex.Matches(source).Cast<Match>().ToArray();
+ if (solidMatches.Length == 0 && LegacyEqualsSolidRegex.IsMatch(source)) diagnostics.Add(UnsupportedConstruct);
+ if (solidMatches.Length == 0) diagnostics.Add(MissingSolid);
- FirmamentV2Document? document = null;
- if (modelMatch.Success && unitsMatch.Success && solidMatches.Count > 0)
+ var solids = new List<FirmamentV2SolidBinding>();
+ var byName = new Dictionary<string, FirmamentV2SolidBinding>(StringComparer.Ordinal);
+ if (modelMatch.Success && unitsMatch.Success)
{
- var solid = solidMatches[0];
- var recordType = solid.Groups["type"].Value;
- if (!string.Equals(recordType, "Box", StringComparison.Ordinal)) diagnostics.Add(UnknownRecordType);
-
- var sizeMatch = SizeRegex.Match(solid.Groups["body"].Value);
- IReadOnlyList<double>? values = null;
- if (!sizeMatch.Success) diagnostics.Add(BoxMissingSize);
- else
- {
- values = ParseSizeValues(sizeMatch.Groups["values"].Value, diagnostics);
- }
-
- if (string.Equals(recordType, "Box", StringComparison.Ordinal) && values is not null && !diagnostics.Any(IsFatalDiagnostic))
+ foreach (var solid in solidMatches)
{
- document = new FirmamentV2Document(
- modelMatch.Groups["name"].Value,
- unitsMatch.Groups["units"].Value,
- new FirmamentV2SolidBinding(solid.Groups["name"].Value, recordType, new FirmamentV2BoxRecord(values)));
+ var name = solid.Groups["name"].Value;
+ var target = solid.Groups["target"].Value;
+ var body = solid.Groups["body"].Value;
+ var isWith = solid.Groups["with"].Success;
+ if (byName.ContainsKey(name)) { diagnostics.Add(DuplicateName); continue; }
+
+ FirmamentV2SolidBinding? binding = isWith
+ ? ParseDerived(name, target, body, byName, diagnostics)
+ : ParseDirect(name, target, body, diagnostics);
+ if (binding is not null)
+ {
+ solids.Add(binding);
+ byName.Add(name, binding);
+ }
}
}
+ FirmamentV2Document? document = null;
+ if (modelMatch.Success && unitsMatch.Success && solids.Count > 0 && !diagnostics.Any(IsFatalDiagnostic))
+ document = new FirmamentV2Document(modelMatch.Groups["name"].Value, unitsMatch.Groups["units"].Value, solids);
+
diagnostics.Add(document is null ? "firmament-v2-parse-failed" : "firmament-v2-parse-succeeded");
diagnostics.Sort(StringComparer.Ordinal);
return document is null ? FirmamentV2ParseResult.Failure(diagnostics) : FirmamentV2ParseResult.Success(document, diagnostics);
}
- private static bool IsFatalDiagnostic(string code) => code is MissingModel or MissingUnits or MissingSolid or UnsupportedConstruct or UnknownRecordType or BoxMissingSize or BoxSizeArity or DegenerateDimension;
+ private static FirmamentV2SolidBinding? ParseDirect(string name, string recordType, string body, List<string> diagnostics)
+ {
+ if (!string.Equals(recordType, "Box", StringComparison.Ordinal)) { diagnostics.Add(UnknownRecordType); return null; }
+ var values = ParseSizeField(body, diagnostics, BoxMissingSize);
+ return values is null ? null : new(name, "Box", new(values));
+ }
+
+ private static FirmamentV2SolidBinding? ParseDerived(string name, string baseName, string body, Dictionary<string, FirmamentV2SolidBinding> byName, List<string> diagnostics)
+ {
+ if (!byName.TryGetValue(baseName, out var baseSolid)) { diagnostics.Add(NameUnresolved); if (Regex.IsMatch(body, @"\bsize\s*:", RegexOptions.CultureInvariant)) diagnostics.Add(WithForwardReference); return null; }
+ if (!string.Equals(baseSolid.RecordType, "Box", StringComparison.Ordinal)) { diagnostics.Add(WithRequiresBoxRecord); return null; }
+ var fields = FieldRegex.Matches(body).Select(m => m.Groups["field"].Value).ToArray();
+ if (fields.Length == 0) { diagnostics.Add(WithFieldNotFound); return null; }
+ if (fields.Any(f => f.StartsWith('@'))) { diagnostics.Add(WithRequiresRecord); return null; }
+ if (fields.Any(f => !string.Equals(f, "size", StringComparison.Ordinal))) { diagnostics.Add(WithFieldNotFound); return null; }
+ var values = ParseSizeField(body, diagnostics, WithFieldTypeMismatch);
+ if (values is null) { diagnostics.Add(WithDerivedRecordInvalid); return null; }
+ return new(name, "Box", new(values), baseName, new Dictionary<string, IReadOnlyList<double>>(StringComparer.Ordinal) { ["size"] = values });
+ }
+
+ private static bool IsFatalDiagnostic(string code) => code is MissingModel or MissingUnits or MissingSolid or UnsupportedConstruct or UnknownRecordType or BoxMissingSize or BoxSizeArity or DegenerateDimension or NameUnresolved or DuplicateName or WithRequiresRecord or WithRequiresBoxRecord or WithFieldNotFound or WithFieldTypeMismatch or WithForwardReference or WithDerivedRecordInvalid;
+
+ private static IReadOnlyList<double>? ParseSizeField(string body, List<string> diagnostics, string missingDiagnostic)
+ {
+ var sizeMatch = SizeRegex.Match(body);
+ if (!sizeMatch.Success) { diagnostics.Add(missingDiagnostic); return null; }
+ return ParseSizeValues(sizeMatch.Groups["values"].Value, diagnostics);
+ }
private static IReadOnlyList<double>? ParseSizeValues(string raw, List<string> diagnostics)
{
var parts = raw.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
- if (parts.Length != 3)
- {
- diagnostics.Add(BoxSizeArity);
- return null;
- }
-
+ if (parts.Length != 3) { diagnostics.Add(BoxSizeArity); return null; }
var values = new List<double>(3);
foreach (var part in parts)
{
- if (!double.TryParse(part, NumberStyles.Float, CultureInfo.InvariantCulture, out var value))
- {
- diagnostics.Add(UnsupportedConstruct);
- return null;
- }
-
+ if (!double.TryParse(part, NumberStyles.Float, CultureInfo.InvariantCulture, out var value)) { diagnostics.Add(WithFieldTypeMismatch); return null; }
if (value <= 0) diagnostics.Add(DegenerateDimension);
values.Add(value);
}
-
return diagnostics.Contains(DegenerateDimension) ? null : values;
}
private static bool ContainsUnsupportedConstruct(string source) =>
- Regex.IsMatch(source, @"\b(with|concept|PMI|where|template|cut|add|shell|fillet|chamfer|region|regions|profile|material|pattern)\b|=>|<\s*Process\s*>", RegexOptions.CultureInvariant);
+ Regex.IsMatch(source, @"\b(concept|PMI|where|template|cut|add|shell|fillet|chamfer|region|regions|profile|material|pattern)\b|=>|<\s*Process\s*>", RegexOptions.CultureInvariant);
private static string StripLineComments(string sourceText) => string.Join('\n', sourceText.Split('\n').Select(line =>
{
diff --git a/docs/air-firmament-a1-firmament-fixture-corpus.md b/docs/air-firmament-a1-firmament-fixture-corpus.md
index cf723f28..d3b46cbf 100644
--- a/docs/air-firmament-a1-firmament-fixture-corpus.md
+++ b/docs/air-firmament-a1-firmament-fixture-corpus.md
@@ -168,3 +168,8 @@ A2.1 expands the `fixtures/FirmamentV2/` metadata-only taxonomy with semantic-re
## A2.2 record-derivation fixture expansion
A2.2 expands the `fixtures/FirmamentV2/` metadata-only taxonomy with `RecordDerivation/` fixtures for valid `with` variants and invalid derivation diagnostics. Valid design examples remain `implementation: not-implemented`, `expected-stage: not-implemented`, and `expected-diagnostic: firmament-v2-parser-not-ready`; invalid doctrine examples use `implementation: rejected` with diagnostics such as `firmament-degenerate-dimension`, `firmament-with-requires-record`, and `firmament-with-field-not-found`. These fixtures are classified by metadata and must not be routed through the V1 parser as incidental parse failures.
+
+
+### AIR-FIRMAMENT-X2 fixture stage update
+
+`fixtures/FirmamentV2/RecordDerivation/valid/box-with-size-variant-v2.valid.firmfixture` is no longer metadata-only. It is parser-backed, reaches `feature-air`, lowers the derived solid `tall` to `CreateBox`, and retains `base` as source record evidence. The surrounding V2 design fixtures remain metadata-only, parser-not-ready, not-implemented, deferred, or rejected according to their existing fixture metadata.
diff --git a/docs/air-firmament-a2-2-record-derivation-with.md b/docs/air-firmament-a2-2-record-derivation-with.md
index a2e9fbe5..052f0bd4 100644
--- a/docs/air-firmament-a2-2-record-derivation-with.md
+++ b/docs/air-firmament-a2-2-record-derivation-with.md
@@ -361,3 +361,7 @@ A2.2 extends A2 and A2.1 rather than replacing them. A2 remains the broad Firmam
## 17. Non-goals
A2.2 explicitly preserves: no parser implementation; no backend implementation; no geometry implementation; no source evaluator; no conditionals; no loops; no functions; no macros; no shell implementation; no fillet implementation; no surfacing implementation; no pattern implementation; no material implementation; no broad Boolean; no CIR topology authority; no STEP behavior change; no BRep topology behavior change; no Firmasm redesign; no corpus migration; no production route replacement; no general side-hole support; no arbitrary face/axis support; no production analyzer/map behavior changes; no CIR evaluator/tape behavior changes; no route-selection/JudgmentUtility production behavior changes; no AirEdgeSweep behavior changes; no BrepBoundedChamfer/BrepBoundedFillet behavior changes; no triangle migration; and no NURBS/freeform implementation.
+
+## AIR-FIRMAMENT-X2 parser-backed advancement
+
+AIR-FIRMAMENT-X2 promotes the Box size variant from metadata-only design intent to a parser-backed Firmament V2 slice. The supported production subset is deliberately narrow: `solid derived: base with { size: [...] }` may derive only from a previously defined Box solid record in the same model scope. The derived record is resolved immutably, revalidated with Box admissibility, and lowered to Feature AIR `CreateBox`; the base record remains unchanged. General `with`, selectors, feature records, templates, concepts, PMI, `where`, shell, fillet, chamfer, surfacing, pattern, material, FEA, and topology mutation remain unsupported.
diff --git a/docs/air-firmament-x1-v2-parser-box.md b/docs/air-firmament-x1-v2-parser-box.md
index 514006a3..26305474 100644
--- a/docs/air-firmament-x1-v2-parser-box.md
+++ b/docs/air-firmament-x1-v2-parser-box.md
@@ -78,3 +78,8 @@ Validation for this milestone includes CLI build/help, V2 text and JSON traces,
## Next milestone recommendation
Recommended AIR-FIRMAMENT-X2: add a small token/lexer layer and semantic-name checks for V2 while preserving the X1 Feature AIR boundary. Do not broaden into regions, selectors, record derivation, or geometry materialization until the tiny parser contract remains stable across the fixture corpus.
+
+
+## X2 follow-on note
+
+AIR-FIRMAMENT-X2 builds on this isolated V2 frontend by adding only Box `with` record derivation: a derived Box may override `size`, be revalidated, and lower to Feature AIR `CreateBox`. The V1 parser remains untouched and the V2 frontend remains under the `FirmamentV2` namespace.
diff --git a/docs/air-firmament-x2-v2-parser-box-with.md b/docs/air-firmament-x2-v2-parser-box-with.md
new file mode 100644
index 00000000..85640a2b
--- /dev/null
+++ b/docs/air-firmament-x2-v2-parser-box-with.md
@@ -0,0 +1,96 @@
+# AIR-FIRMAMENT-X2 — Firmament V2 parser Box `with` derivation
+
+## 1. Purpose and scope
+
+AIR-FIRMAMENT-X2 implements the first parser-backed Firmament V2 `with` derivation slice for Box solid records. The milestone proves the configuration mechanism:
+
+```text
+records + with = model configuration without spreadsheets
+```
+
+The implementation is intentionally narrow: one or more model-scope Box solid bindings may be parsed, and a later Box solid may derive from a previously defined Box solid with a `size` override. The derived record is resolved and revalidated before Feature AIR lowering. No topology mutation, BRep editing, backend patching, control flow, or general record derivation is introduced.
+
+## 2. Relationship to X1
+
+X1 introduced the isolated Firmament V2 frontend and parser-backed Box source path for `model`, `units mm`, `solid name: Box`, and `size: [x, y, z]`, lowering the parsed Box to a Feature AIR `CreateBox` trace summary. X2 keeps that X1 path and extends only the V2 frontend slice needed to resolve an immutable Box record derivation before lowering.
+
+## 3. V2 parser organization / V1 legacy separation
+
+The X2 parser and AST changes remain under `Aetheris.Kernel.Firmament/FirmamentV2/`. The legacy V1 parser remains on the `FirmamentTopLevelParser` path and is not expanded with V2 `with` syntax. Trace routing continues to use fixture metadata (`syntax-version: FirmamentV2`, `implementation: parser-backed`) to invoke `FirmamentV2Parser` directly.
+
+## 4. Supported X2 grammar
+
+Supported parser-backed shape:
+
+```firmament
+model BoxVariant {
+ units mm
+
+ solid base: Box {
+ size: [10, 8, 6]
+ }
+
+ solid tall: base with {
+ size: [10, 8, 12]
+ }
+}
+```
+
+The accepted X2 subset is:
+
+- inherited `units mm`;
+- direct Box solid records with `size: [number, number, number]`;
+- derived Box solid records of the form `solid derived: base with { size: [...] }`;
+- same-model name resolution against previously parsed solid records;
+- positive numeric size components.
+
+## 5. `with` semantics
+
+A `with` solid target must resolve to a previously defined source-level Box solid record. The derived solid receives a new identity and a resolved Box record. For X2, the only supported override field is `size`; the override replaces the inherited size wholesale.
+
+## 6. Source-level immutability and identity
+
+The base solid remains unchanged. The derived solid is a new source-level record binding with its own name and `derivedFrom` evidence. X2 derivation happens before Feature AIR lowering and does not mutate topology or backend geometry.
+
+## 7. Revalidation/admissibility
+
+The derived Box is validated exactly like a directly authored Box:
+
+- size arity must be three;
+- every size component must be greater than zero.
+
+If the derived record is invalid, parsing reports stable diagnostics and does not lower to Feature AIR.
+
+## 8. Unsupported constructs
+
+X2 does not implement general `with`. Unsupported constructs include nested `with`, selectors as derivation targets, feature records, field overrides other than `size`, undefined or forward base references, partial updates such as `size.x`, arbitrary expressions, non-numeric arrays, templates, concepts, PMI, `where`, materials, patterns, regions, shell, fillet, chamfer, profiles, ruled surfaces, and explicit per-literal units beyond the existing X1 subset.
+
+## 9. Fixture changes
+
+`fixtures/FirmamentV2/RecordDerivation/valid/box-with-size-variant-v2.valid.firmfixture` advanced from A2.2 metadata-only design intent to `implementation: parser-backed` with `expected-stage: feature-air`, `expected-feature-air: CreateBox`, `expected-solid: tall`, `expected-size: [10, 8, 12]`, and `expected-derived-from: base`.
+
+Invalid parser-backed fixtures now cover degenerate derived size, selector-like override fields, unknown fields, undefined bases, and duplicate solid names under `fixtures/FirmamentV2/RecordDerivation/invalid/`.
+
+## 10. Diagnostics
+
+Stable X2 diagnostics include:
+
+- `firmament-v2-name-unresolved`;
+- `firmament-v2-duplicate-name`;
+- `firmament-v2-with-requires-record`;
+- `firmament-v2-with-requires-box-record`;
+- `firmament-v2-with-field-not-found`;
+- `firmament-v2-with-field-type-mismatch`;
+- `firmament-v2-with-forward-reference`;
+- `firmament-v2-with-derived-record-invalid`;
+- `firmament-degenerate-dimension`.
+
+Existing X1 diagnostics remain in use for missing model, missing units, missing solid, unknown record type, missing size, and size arity.
+
+## 11. Tests run
+
+Validated with targeted CLI traces and focused .NET test filters for Firmament V2 parser, fixtures, trace, primitive, region, side-hole, parser-backed, and invalid fixture behavior. The required commands and results are recorded in the implementation PR summary.
+
+## 12. Next milestone recommendation
+
+The next milestone should keep V2 isolated and add one narrow capability at a time. Recommended next step: explicit derived-record trace/diagnostic polish for forward-reference detection or a second Box-only `with` fixture shape, before any attempt at general `with`, selectors, templates, concepts, PMI, `where`, materials, or topology-affecting behavior.
diff --git a/fixtures/FirmamentV2/RecordDerivation/invalid/with-degenerate-box-v2.invalid.firmfixture b/fixtures/FirmamentV2/RecordDerivation/invalid/with-degenerate-box-v2.invalid.firmfixture
index 0ab26f16..797474e7 100644
--- a/fixtures/FirmamentV2/RecordDerivation/invalid/with-degenerate-box-v2.invalid.firmfixture
+++ b/fixtures/FirmamentV2/RecordDerivation/invalid/with-degenerate-box-v2.invalid.firmfixture
@@ -3,20 +3,20 @@
// category: RecordDerivation
// syntax-version: FirmamentV2
// validity: invalid
-// implementation: rejected
+// implementation: parser-backed
// expected: invalid
-// expected-stage: rejected
+// expected-stage: parsed
// expected-diagnostic: firmament-degenerate-dimension
-// notes: AIR-FIRMAMENT-A2.2 metadata-only invalid derivation fixture; derived Box must be revalidated.
+// notes: AIR-FIRMAMENT-X2 parser-backed invalid derivation fixture; derived Box size must be revalidated.
model WithDegenerateBox {
units mm
- solid base = Box {
+ solid base: Box {
size: [10, 8, 6]
}
- solid bad = base with {
- size: [10, 0, 6]
+ solid bad: base with {
+ size: [10, 0, 12]
}
}
diff --git a/fixtures/FirmamentV2/RecordDerivation/invalid/with-duplicate-solid-name-v2.invalid.firmfixture b/fixtures/FirmamentV2/RecordDerivation/invalid/with-duplicate-solid-name-v2.invalid.firmfixture
new file mode 100644
index 00000000..2b0cb2c0
--- /dev/null
+++ b/fixtures/FirmamentV2/RecordDerivation/invalid/with-duplicate-solid-name-v2.invalid.firmfixture
@@ -0,0 +1,21 @@
+// fixture-id: with-duplicate-solid-name-v2
+// case: firmament-v2-with-duplicate-solid-name
+// category: RecordDerivation
+// syntax-version: FirmamentV2
+// validity: invalid
+// implementation: parser-backed
+// expected: invalid
+// expected-stage: parsed
+// expected-diagnostic: firmament-v2-duplicate-name
+
+model WithDuplicateSolidName {
+ units mm
+
+ solid base: Box {
+ size: [10, 8, 6]
+ }
+
+ solid base: Box {
+ size: [10, 8, 12]
+ }
+}
diff --git a/fixtures/FirmamentV2/RecordDerivation/invalid/with-selector-target-v2.invalid.firmfixture b/fixtures/FirmamentV2/RecordDerivation/invalid/with-selector-target-v2.invalid.firmfixture
index 5a817e82..31125ce1 100644
--- a/fixtures/FirmamentV2/RecordDerivation/invalid/with-selector-target-v2.invalid.firmfixture
+++ b/fixtures/FirmamentV2/RecordDerivation/invalid/with-selector-target-v2.invalid.firmfixture
@@ -3,22 +3,20 @@
// category: RecordDerivation
// syntax-version: FirmamentV2
// validity: invalid
-// implementation: rejected
+// implementation: parser-backed
// expected: invalid
-// expected-stage: rejected
-// expected-diagnostic: firmament-with-requires-record
-// notes: AIR-FIRMAMENT-A2.2 metadata-only invalid derivation fixture; with cannot target selectors.
+// expected-stage: parsed
+// expected-diagnostic: firmament-v2-with-requires-record
+// notes: AIR-FIRMAMENT-X2 parser-backed invalid derivation fixture; selectors are not records.
model WithSelectorTarget {
units mm
- solid base = Box {
+ solid base: Box {
size: [10, 8, 6]
}
- select topFace = base.face(+Z)
-
- solid bad = topFace with {
- size: [10, 8, 12]
+ solid bad: base with {
+ @front: [1, 2, 3]
}
}
diff --git a/fixtures/FirmamentV2/RecordDerivation/invalid/with-undefined-base-v2.invalid.firmfixture b/fixtures/FirmamentV2/RecordDerivation/invalid/with-undefined-base-v2.invalid.firmfixture
new file mode 100644
index 00000000..9dfe02e1
--- /dev/null
+++ b/fixtures/FirmamentV2/RecordDerivation/invalid/with-undefined-base-v2.invalid.firmfixture
@@ -0,0 +1,17 @@
+// fixture-id: with-undefined-base-v2
+// case: firmament-v2-with-undefined-base
+// category: RecordDerivation
+// syntax-version: FirmamentV2
+// validity: invalid
+// implementation: parser-backed
+// expected: invalid
+// expected-stage: parsed
+// expected-diagnostic: firmament-v2-name-unresolved
+
+model WithUndefinedBase {
+ units mm
+
+ solid tall: base with {
+ size: [10, 8, 12]
+ }
+}
diff --git a/fixtures/FirmamentV2/RecordDerivation/invalid/with-unknown-field-v2.invalid.firmfixture b/fixtures/FirmamentV2/RecordDerivation/invalid/with-unknown-field-v2.invalid.firmfixture
index 79de9496..8461fd9e 100644
--- a/fixtures/FirmamentV2/RecordDerivation/invalid/with-unknown-field-v2.invalid.firmfixture
+++ b/fixtures/FirmamentV2/RecordDerivation/invalid/with-unknown-field-v2.invalid.firmfixture
@@ -3,20 +3,20 @@
// category: RecordDerivation
// syntax-version: FirmamentV2
// validity: invalid
-// implementation: rejected
+// implementation: parser-backed
// expected: invalid
-// expected-stage: rejected
-// expected-diagnostic: firmament-with-field-not-found
-// notes: AIR-FIRMAMENT-A2.2 metadata-only invalid derivation fixture; overridden fields must exist on the source record type.
+// expected-stage: parsed
+// expected-diagnostic: firmament-v2-with-field-not-found
+// notes: AIR-FIRMAMENT-X2 parser-backed invalid derivation fixture; Box with overrides only support size.
model WithUnknownField {
units mm
- solid base = Box {
+ solid base: Box {
size: [10, 8, 6]
}
- solid bad = base with {
- colorway: "blue"
+ solid bad: base with {
+ colorway: [1, 2, 3]
}
}
diff --git a/fixtures/FirmamentV2/RecordDerivation/valid/box-with-size-variant-v2.valid.firmfixture b/fixtures/FirmamentV2/RecordDerivation/valid/box-with-size-variant-v2.valid.firmfixture
index 3da64f1e..0535bee0 100644
--- a/fixtures/FirmamentV2/RecordDerivation/valid/box-with-size-variant-v2.valid.firmfixture
+++ b/fixtures/FirmamentV2/RecordDerivation/valid/box-with-size-variant-v2.valid.firmfixture
@@ -3,20 +3,23 @@
// category: RecordDerivation
// syntax-version: FirmamentV2
// validity: valid
-// implementation: not-implemented
+// implementation: parser-backed
// expected: valid
-// expected-stage: not-implemented
-// expected-diagnostic: firmament-v2-parser-not-ready
-// notes: AIR-FIRMAMENT-A2.2 metadata-only record derivation fixture; not parser-backed.
+// expected-stage: feature-air
+// expected-feature-air: CreateBox
+// expected-solid: tall
+// expected-size: [10, 8, 12]
+// expected-derived-from: base
+// notes: AIR-FIRMAMENT-X2 parser-backed Box record derivation fixture; advanced from A2.2 metadata-only design intent.
-model BoxWithSizeVariant {
+model BoxVariant {
units mm
- solid base = Box {
+ solid base: Box {
size: [10, 8, 6]
}
- solid tall = base with {
+ solid tall: base with {
size: [10, 8, 12]
}
}