Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Add Firmament V2 Box semantic exposures

Yuechen Lieebb36fa84eb
diff --git a/Aetheris.CLI.Tests/AirTraceCommandTests.cs b/Aetheris.CLI.Tests/AirTraceCommandTests.cs
index bcaff5f8..3c26ddfd 100644
--- a/Aetheris.CLI.Tests/AirTraceCommandTests.cs
+++ b/Aetheris.CLI.Tests/AirTraceCommandTests.cs
@@ -946,6 +946,34 @@ public sealed class AirTraceCommandTests
Assert.Contains("firmament-v2-no-v1-parser", output);
}
+ [Fact]
+ public void FirmamentV2Parser_ExposeBoxFaces_TraceJsonContainsSemanticRefs()
+ {
+ var (exitCode, output, _) = Run("trace", "--fixture", FirmamentV2Fixture("SemanticRefs/valid/named-box-faces-v2.valid.firmfixture"), "--json");
+ Assert.Equal(0, exitCode);
+ using var doc = JsonDocument.Parse(output);
+ var exposures = doc.RootElement.GetProperty("firmamentV2").GetProperty("solids")[0].GetProperty("exposures");
+ Assert.Equal(4, exposures.GetArrayLength());
+ var top = exposures.EnumerateArray().Single(e => e.GetProperty("alias").GetString() == "top");
+ Assert.Equal("face", top.GetProperty("selectorKind").GetString());
+ Assert.Equal("face(+Z)", top.GetProperty("selector").GetString());
+ Assert.Equal("FaceRef", top.GetProperty("refType").GetString());
+ Assert.Equal("+Z", top.GetProperty("axis").GetString());
+ var rim = exposures.EnumerateArray().Single(e => e.GetProperty("alias").GetString() == "topRim");
+ Assert.Equal("outerLoop", rim.GetProperty("subselector").GetString());
+ Assert.Equal("LoopRef", rim.GetProperty("refType").GetString());
+ }
+
+ [Fact]
+ public void FirmamentV2Parser_ExposeBoxFaces_TraceTextContainsFatArrowBindings()
+ {
+ var (exitCode, output, _) = Run("trace", "--fixture", FirmamentV2Fixture("SemanticRefs/valid/named-box-faces-v2.valid.firmfixture"));
+ Assert.Equal(0, exitCode);
+ Assert.Contains("face(+Z) => top : FaceRef", output);
+ Assert.Contains("face(-Z) => bottom : FaceRef", output);
+ Assert.Contains("face(+Z).outerLoop => topRim : LoopRef", output);
+ }
+
[Fact]
public void FirmamentV2Parser_MissingUnits_TraceReportsDiagnostic()
{
diff --git a/Aetheris.CLI.Tests/FirmamentFixtureCorpusTests.cs b/Aetheris.CLI.Tests/FirmamentFixtureCorpusTests.cs
index 0e5c0515..caebb0f6 100644
--- a/Aetheris.CLI.Tests/FirmamentFixtureCorpusTests.cs
+++ b/Aetheris.CLI.Tests/FirmamentFixtureCorpusTests.cs
@@ -190,7 +190,16 @@ public sealed class FirmamentFixtureCorpusTests
{
using var doc = Trace(path);
var diagnostics = doc.RootElement.GetProperty("diagnostics").EnumerateArray().Select(x => x.GetString()).ToArray();
- Assert.False(doc.RootElement.GetProperty("fixture").GetProperty("parserBacked").GetBoolean());
+ var fixture = LoadMetadata(path);
+ if (string.Equals(fixture.GetValueOrDefault("implementation"), "parser-backed", StringComparison.Ordinal))
+ {
+ Assert.True(doc.RootElement.GetProperty("fixture").GetProperty("parserBacked").GetBoolean());
+ Assert.Equal("FirmamentV2Parser", doc.RootElement.GetProperty("frontend").GetProperty("parserName").GetString());
+ }
+ else
+ {
+ Assert.False(doc.RootElement.GetProperty("fixture").GetProperty("parserBacked").GetBoolean());
+ }
Assert.DoesNotContain("air-x11-firmament-parse-failed", diagnostics);
}
}
diff --git a/Aetheris.CLI/AirTrace.cs b/Aetheris.CLI/AirTrace.cs
index 5ade5892..faea52f1 100644
--- a/Aetheris.CLI/AirTrace.cs
+++ b/Aetheris.CLI/AirTrace.cs
@@ -52,7 +52,8 @@ internal sealed record AirTraceConstructiveAirSummary(string NodeKind, string Ca
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, IReadOnlyList<AirTraceFirmamentV2SolidSummary> Solids);
-internal sealed record AirTraceFirmamentV2SolidSummary(string Name, string RecordType, IReadOnlyList<double> Size, string? DerivedFrom, IReadOnlyDictionary<string, IReadOnlyList<double>> Overrides);
+internal sealed record AirTraceFirmamentV2SolidSummary(string Name, string RecordType, IReadOnlyList<double> Size, string? DerivedFrom, IReadOnlyDictionary<string, IReadOnlyList<double>> Overrides, IReadOnlyList<AirTraceFirmamentV2ExposureSummary> Exposures);
+internal sealed record AirTraceFirmamentV2ExposureSummary(string Alias, string SelectorKind, string Selector, string RefType, string Axis, string? Subselector);
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);
@@ -159,7 +160,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, frontend.FirmamentV2.Solids.Select(s => new AirTraceFirmamentV2SolidSummary(s.Name, s.RecordType, s.Size, s.DerivedFrom, s.Overrides)).ToArray());
+ 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, s.Exposures.Select(e => new AirTraceFirmamentV2ExposureSummary(e.Alias, e.SelectorKind, e.Selector, e.RefType, e.Axis, e.Subselector)).ToArray())).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"),
@@ -335,6 +336,12 @@ internal static class AirTraceTextRenderer
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 (solid.Exposures.Count > 0)
+ {
+ b.AppendLine();
+ b.AppendLine(" Expose:");
+ foreach (var exposure in solid.Exposures) b.AppendLine($" {exposure.Selector} => {exposure.Alias} : {exposure.RefType}");
+ }
}
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 74c11444..072c795d 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentV2ParserTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentV2ParserTests.cs
@@ -143,6 +143,48 @@ public sealed class FirmamentV2ParserTests
Assert.Contains("firmament-v2-no-v1-parser", result.Diagnostics);
}
+ [Fact]
+ public void FirmamentV2Parser_ExposeBoxFaces_ParsesAliases()
+ {
+ var result = FirmamentV2Parser.Parse(Source("SemanticRefs/valid/named-box-faces-v2.valid.firmfixture"));
+ Assert.True(result.IsSuccess, string.Join(", ", result.Diagnostics));
+ var exposures = result.Document!.Solid.Box.Exposures;
+ Assert.Equal(4, exposures.Count);
+ Assert.Equal(["top", "bottom", "right", "topRim"], exposures.Select(e => e.Alias).ToArray());
+ Assert.Equal("FaceRef", exposures.Single(e => e.Alias == "top").RefType);
+ Assert.Equal("LoopRef", exposures.Single(e => e.Alias == "topRim").RefType);
+ }
+
+ [Fact]
+ public void FirmamentV2Parser_ExposeBoxFaces_LowersBoxToFeatureAir()
+ {
+ var result = FirmamentFrontendTraceProbe.ParseV2Only(Source("SemanticRefs/valid/named-box-faces-v2.valid.firmfixture"));
+ Assert.True(result.ParseSucceeded, string.Join(", ", result.Diagnostics));
+ Assert.Equal("CreateBox", result.FeatureAir!.FeatureAirNodeKind);
+ Assert.Equal(10, result.FeatureAir.SourceDimensions!.Width);
+ Assert.Equal(8, result.FeatureAir.SourceDimensions.Depth);
+ Assert.Equal(6, result.FeatureAir.SourceDimensions.Height);
+ Assert.Equal(4, result.FirmamentV2!.Solids.Single().Exposures.Count);
+ }
+
+ [Fact]
+ public void FirmamentV2Parser_ExposeBoxFaces_Diagnostics()
+ {
+ Assert.Contains(FirmamentV2Parser.ExposeAliasDuplicate, FirmamentV2Parser.Parse(Source("SemanticRefs/invalid/duplicate-expose-alias-v2.invalid.firmfixture")).Diagnostics);
+ Assert.Contains(FirmamentV2Parser.SelectorAxisInvalid, FirmamentV2Parser.Parse(Source("SemanticRefs/invalid/invalid-face-axis-v2.invalid.firmfixture")).Diagnostics);
+ Assert.Contains(FirmamentV2Parser.RawBackendIdReferenceForbidden, FirmamentV2Parser.Parse(Source("SemanticRefs/invalid/raw-brep-id-reference-v2.invalid.firmfixture")).Diagnostics);
+ Assert.Contains(FirmamentV2Parser.FatArrowOutsideExpose, FirmamentV2Parser.Parse(Source("SemanticRefs/invalid/fat-arrow-outside-expose-v2.invalid.firmfixture")).Diagnostics);
+ Assert.Contains(FirmamentV2Parser.SelectorUnsupported, FirmamentV2Parser.Parse(Source("SemanticRefs/invalid/unsupported-selector-edge-v2.invalid.firmfixture")).Diagnostics);
+ }
+
+ [Fact]
+ public void FirmamentV2Parser_ExposeBoxFaces_DoesNotUseV1Parser()
+ {
+ var result = FirmamentFrontendTraceProbe.ParseV2Only(Source("SemanticRefs/valid/named-box-faces-v2.valid.firmfixture"));
+ Assert.Equal("FirmamentV2Parser", result.ParserName);
+ Assert.Contains("firmament-v2-no-v1-parser", result.Diagnostics);
+ }
+
private static string Source(string relative)
{
var path = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "../../../../fixtures/FirmamentV2", relative));
diff --git a/Aetheris.Kernel.Firmament/FirmamentFrontendTraceProbe.cs b/Aetheris.Kernel.Firmament/FirmamentFrontendTraceProbe.cs
index ae75ed37..375ff04c 100644
--- a/Aetheris.Kernel.Firmament/FirmamentFrontendTraceProbe.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentFrontendTraceProbe.cs
@@ -17,7 +17,8 @@ public sealed record FirmamentFrontendTraceProbeResult(
FirmamentV2TraceSummary? FirmamentV2 = null);
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 FirmamentV2SolidTraceSummary(string Name, string RecordType, IReadOnlyList<double> Size, string? DerivedFrom, IReadOnlyDictionary<string, IReadOnlyList<double>> Overrides, IReadOnlyList<FirmamentV2ExposureTraceSummary> Exposures);
+public sealed record FirmamentV2ExposureTraceSummary(string Alias, string SelectorKind, string Selector, string RefType, string Axis, string? Subselector);
public sealed record FirmamentPrimitiveAirTraceSummary(
bool ParserBacked,
@@ -101,7 +102,7 @@ public static class FirmamentFrontendTraceProbe
featureDiagnostics,
featureAir,
null,
- 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()));
+ 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>>(), s.Box.Exposures.Select(e => new FirmamentV2ExposureTraceSummary(e.Alias, e.SelectorKind, e.Selector, e.RefType, e.Axis, e.Subselector)).ToArray())).ToArray()));
}
public static FirmamentFrontendTraceProbeResult ParseOnly(string sourceText)
diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.cs
index b1a65883..3b22ad8b 100644
--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.cs
@@ -10,7 +10,8 @@ public sealed record FirmamentV2SolidBinding(string Name, string RecordType, Fir
public bool IsDerived => !string.IsNullOrWhiteSpace(DerivedFrom);
}
-public sealed record FirmamentV2BoxRecord(IReadOnlyList<double> Size);
+public sealed record FirmamentV2BoxRecord(IReadOnlyList<double> Size, IReadOnlyList<FirmamentV2Exposure> Exposures);
+public sealed record FirmamentV2Exposure(string Alias, string SelectorKind, string Selector, string RefType, string Axis, string? Subselector);
public sealed record FirmamentV2ParseResult(bool IsSuccess, FirmamentV2Document? Document, IReadOnlyList<string> Diagnostics)
{
public static FirmamentV2ParseResult Success(FirmamentV2Document document, IReadOnlyList<string> diagnostics) => new(true, document, diagnostics);
diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs
index 3410e67a..ca7f8c5d 100644
--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs
@@ -21,13 +21,25 @@ public static class FirmamentV2Parser
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";
+ public const string ExposeBlockUnsupported = "firmament-v2-expose-block-unsupported";
+ public const string ExposeRequiresBoxRecord = "firmament-v2-expose-requires-box-record";
+ public const string ExposeAliasDuplicate = "firmament-v2-expose-alias-duplicate";
+ public const string ExposeAliasInvalid = "firmament-v2-expose-alias-invalid";
+ public const string SelectorUnsupported = "firmament-v2-selector-unsupported";
+ public const string SelectorAxisInvalid = "firmament-v2-selector-axis-invalid";
+ public const string SelectorSubselectorUnsupported = "firmament-v2-selector-subselector-unsupported";
+ public const string FatArrowOutsideExpose = "firmament-v2-fat-arrow-outside-expose";
+ public const string RawBackendIdReferenceForbidden = "firmament-raw-backend-id-reference-forbidden";
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*(?<target>[A-Za-z_][A-Za-z0-9_]*)(?<with>\s+with)?\s*\{(?<body>.*?)\}", RegexOptions.CultureInvariant | RegexOptions.Singleline);
+ private static readonly Regex SolidHeaderRegex = 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*\{", RegexOptions.CultureInvariant);
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);
+ private static readonly Regex ExposeRegex = new(@"\bexpose\s*\{(?<body>.*?)\}", RegexOptions.CultureInvariant | RegexOptions.Singleline);
+ private static readonly Regex ExposureLineRegex = new(@"^\s*(?<selector>.+?)\s*=>\s*(?<alias>[A-Za-z_][A-Za-z0-9_]*)\s*$", RegexOptions.CultureInvariant);
+ private static readonly Regex FaceSelectorRegex = new(@"^face\((?<axis>[+-][XYZ])\)(?<sub>\.[A-Za-z_][A-Za-z0-9_]*)?$", RegexOptions.CultureInvariant);
public static FirmamentV2ParseResult Parse(string sourceText)
{
@@ -35,6 +47,7 @@ public static class FirmamentV2Parser
var diagnostics = new List<string> { "firmament-v2-parser-invoked" };
var source = StripLineComments(sourceText);
+ if (ContainsRawBackendId(source)) diagnostics.Add(RawBackendIdReferenceForbidden);
if (ContainsUnsupportedConstruct(source)) diagnostics.Add(UnsupportedConstruct);
var modelMatch = ModelRegex.Match(source);
@@ -44,7 +57,7 @@ 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).Cast<Match>().ToArray();
+ var solidMatches = FindSolids(source).ToArray();
if (solidMatches.Length == 0 && LegacyEqualsSolidRegex.IsMatch(source)) diagnostics.Add(UnsupportedConstruct);
if (solidMatches.Length == 0) diagnostics.Add(MissingSolid);
@@ -54,10 +67,10 @@ public static class FirmamentV2Parser
{
foreach (var solid in solidMatches)
{
- var name = solid.Groups["name"].Value;
- var target = solid.Groups["target"].Value;
- var body = solid.Groups["body"].Value;
- var isWith = solid.Groups["with"].Success;
+ var name = solid.Name;
+ var target = solid.Target;
+ var body = solid.Body;
+ var isWith = solid.IsWith;
if (byName.ContainsKey(name)) { diagnostics.Add(DuplicateName); continue; }
FirmamentV2SolidBinding? binding = isWith
@@ -84,7 +97,8 @@ public static class FirmamentV2Parser
{
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));
+ var exposures = ParseExposures(body, diagnostics);
+ return values is null ? null : new(name, "Box", new(values, exposures));
}
private static FirmamentV2SolidBinding? ParseDerived(string name, string baseName, string body, Dictionary<string, FirmamentV2SolidBinding> byName, List<string> diagnostics)
@@ -94,13 +108,50 @@ public static class FirmamentV2Parser
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 (ExposeRegex.IsMatch(body)) { diagnostics.Add(ExposeBlockUnsupported); 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 });
+ 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 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 or ExposeBlockUnsupported or ExposeRequiresBoxRecord or ExposeAliasDuplicate or ExposeAliasInvalid or SelectorUnsupported or SelectorAxisInvalid or SelectorSubselectorUnsupported or FatArrowOutsideExpose or RawBackendIdReferenceForbidden;
+
+ private static IReadOnlyList<FirmamentV2Exposure> ParseExposures(string body, List<string> diagnostics)
+ {
+ var match = ExposeRegex.Match(body);
+ if (!match.Success)
+ {
+ if (body.Contains("=>", StringComparison.Ordinal)) diagnostics.Add(FatArrowOutsideExpose);
+ return [];
+ }
+
+ var exposures = new List<FirmamentV2Exposure>();
+ var aliases = new HashSet<string>(StringComparer.Ordinal);
+ foreach (var rawLine in match.Groups["body"].Value.Split('\n'))
+ {
+ var line = rawLine.Trim();
+ if (line.Length == 0) continue;
+ var binding = ExposureLineRegex.Match(line);
+ if (!binding.Success) { diagnostics.Add(SelectorUnsupported); continue; }
+ var alias = binding.Groups["alias"].Value;
+ if (!aliases.Add(alias)) { diagnostics.Add(ExposeAliasDuplicate); continue; }
+ var selector = binding.Groups["selector"].Value.Trim();
+ if (selector.StartsWith("edge(", StringComparison.Ordinal) || selector.StartsWith("vertex(", StringComparison.Ordinal)) { diagnostics.Add(SelectorUnsupported); continue; }
+ var face = FaceSelectorRegex.Match(selector);
+ if (!face.Success)
+ {
+ if (selector.StartsWith("face(", StringComparison.Ordinal)) diagnostics.Add(SelectorAxisInvalid);
+ else diagnostics.Add(SelectorUnsupported);
+ continue;
+ }
+ var axis = face.Groups["axis"].Value;
+ var sub = face.Groups["sub"].Success ? face.Groups["sub"].Value[1..] : null;
+ if (sub is not null && !string.Equals(sub, "outerLoop", StringComparison.Ordinal)) { diagnostics.Add(SelectorSubselectorUnsupported); continue; }
+ exposures.Add(new(alias, "face", selector, sub is null ? "FaceRef" : "LoopRef", axis, sub));
+ }
+ return exposures;
+ }
private static IReadOnlyList<double>? ParseSizeField(string body, List<string> diagnostics, string missingDiagnostic)
{
@@ -124,7 +175,34 @@ public static class FirmamentV2Parser
}
private static bool ContainsUnsupportedConstruct(string source) =>
- Regex.IsMatch(source, @"\b(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|modify)\b|<\s*Process\s*>", RegexOptions.CultureInvariant);
+
+ private static bool ContainsRawBackendId(string source) =>
+ Regex.IsMatch(source, @"\b(brep|step|backend|coedge)\s*\.|STEP\s*#|#[0-9]+", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
+
+ private sealed record SolidMatch(string Name, string Target, bool IsWith, string Body);
+
+ private static IEnumerable<SolidMatch> FindSolids(string source)
+ {
+ foreach (Match match in SolidHeaderRegex.Matches(source))
+ {
+ var open = source.IndexOf('{', match.Index);
+ var close = FindMatchingBrace(source, open);
+ if (close < 0) continue;
+ yield return new(match.Groups["name"].Value, match.Groups["target"].Value, match.Groups["with"].Success, source[(open + 1)..close]);
+ }
+ }
+
+ private static int FindMatchingBrace(string source, int open)
+ {
+ var depth = 0;
+ for (var i = open; i < source.Length; i++)
+ {
+ if (source[i] == '{') depth++;
+ else if (source[i] == '}' && --depth == 0) return i;
+ }
+ return -1;
+ }
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 d3b46cbf..07b1bd51 100644
--- a/docs/air-firmament-a1-firmament-fixture-corpus.md
+++ b/docs/air-firmament-a1-firmament-fixture-corpus.md
@@ -173,3 +173,7 @@ A2.2 expands the `fixtures/FirmamentV2/` metadata-only taxonomy with `RecordDeri
### 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.
+
+## X3 fixture stage note
+
+`fixtures/FirmamentV2/SemanticRefs/valid/named-box-faces-v2.valid.firmfixture` is parser-backed as of AIR-FIRMAMENT-X3 and is expected to reach `feature-air` while reporting four semantic exposure aliases.
diff --git a/docs/air-firmament-a2-1-semantic-references-admissibility-surface-doctrine.md b/docs/air-firmament-a2-1-semantic-references-admissibility-surface-doctrine.md
index 6c3de879..49c398ce 100644
--- a/docs/air-firmament-a2-1-semantic-references-admissibility-surface-doctrine.md
+++ b/docs/air-firmament-a2-1-semantic-references-admissibility-surface-doctrine.md
@@ -388,3 +388,7 @@ A2.2 extends this doctrine with `with` record derivation/configuration. `=>` rem
## 21. Non-goals
A2.1 explicitly preserves: no parser implementation; no backend implementation; 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.
+
+## X3 parser-backed Box exposure note
+
+AIR-FIRMAMENT-X3 advances the V2 named Box face exposure fixture from A2.1 metadata-only doctrine into the isolated Firmament V2 parser/frontend. The supported slice is limited to Box `expose { face(axis) => alias }` and `face(axis).outerLoop => alias` semantic summaries; aliases remain source-level names and not backend topology identifiers.
diff --git a/docs/air-firmament-x1-v2-parser-box.md b/docs/air-firmament-x1-v2-parser-box.md
index 26305474..fa1b42f8 100644
--- a/docs/air-firmament-x1-v2-parser-box.md
+++ b/docs/air-firmament-x1-v2-parser-box.md
@@ -83,3 +83,7 @@ Recommended AIR-FIRMAMENT-X2: add a small token/lexer layer and semantic-name ch
## 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.
+
+## X3 exposure extension
+
+The X1 Box record path remains the base V2 parser route. AIR-FIRMAMENT-X3 layers Box-only semantic exposure metadata on that route without changing `CreateBox` dimensions or geometry behavior.
diff --git a/docs/air-firmament-x2-v2-parser-box-with.md b/docs/air-firmament-x2-v2-parser-box-with.md
index 85640a2b..47a22407 100644
--- a/docs/air-firmament-x2-v2-parser-box-with.md
+++ b/docs/air-firmament-x2-v2-parser-box-with.md
@@ -94,3 +94,7 @@ Validated with targeted CLI traces and focused .NET test filters for Firmament V
## 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.
+
+## X3 alias-copying policy
+
+AIR-FIRMAMENT-X3 does not copy semantic exposure aliases through `with` derivation. Derived Box records continue to support size overrides, but expose blocks on derived records are rejected until an explicit safe alias-copying rule is designed.
diff --git a/docs/air-firmament-x3-v2-semantic-refs-expose.md b/docs/air-firmament-x3-v2-semantic-refs-expose.md
new file mode 100644
index 00000000..d6987d2f
--- /dev/null
+++ b/docs/air-firmament-x3-v2-semantic-refs-expose.md
@@ -0,0 +1,71 @@
+# AIR-FIRMAMENT-X3 — V2 Semantic Refs and `=>` Exposure for Box
+
+## Purpose and scope
+
+AIR-FIRMAMENT-X3 adds the first parser-backed Firmament V2 semantic subobject reference slice. The implemented scope is intentionally narrow: directly-authored `Box` records may contain an `expose { ... }` block whose entries bind supported semantic selectors to source-level aliases with `=>`.
+
+No geometry, BRep topology, STEP, material, PMI, shell, chamfer, fillet, surfacing, pattern, region, side-hole, Boolean, CIR topology authority, Firmasm, or production-route behavior changes are introduced.
+
+## Relationship to A2.1
+
+A2.1 established the semantic-reference admissibility doctrine and metadata-only fixtures. X3 advances the named Box faces fixture from metadata-only design coverage to parser-backed frontend behavior for `face(axis)` and `face(axis).outerLoop` selectors.
+
+## Relationship to X1/X2
+
+X1 introduced the isolated V2 parser/frontend for typed Box records and Feature AIR `CreateBox` summaries. X2 added parser-backed `base with { size: [...] }` Box derivation. X3 preserves both paths and adds exposure metadata without changing Box lowering dimensions.
+
+## V1/V2 parser separation
+
+X3 remains in the Firmament V2 parser/frontend namespace and structures. V2 exposure fixtures are routed through `FirmamentV2Parser`; V1 syntax is not expanded and V2 fixtures are not sent through the legacy parser.
+
+## Supported X3 syntax
+
+```firmament
+solid base: Box {
+ size: [10, 8, 6]
+ expose {
+ face(+Z) => top
+ face(-Z) => bottom
+ face(+X) => right
+ face(+Z).outerLoop => topRim
+ }
+}
+```
+
+Supported axes are `+X`, `-X`, `+Y`, `-Y`, `+Z`, and `-Z`.
+
+## Semantic reference model
+
+`face(axis)` creates a `FaceRef` summary. `face(axis).outerLoop` creates a `LoopRef` summary. Aliases such as `top` and `topRim` are source-level semantic names only: they are not BRep IDs, STEP entity IDs, coedge IDs, or backend topology identifiers, and they do not force BRep materialization.
+
+## `=>` exposure semantics
+
+Inside a Box `expose` block, `selector => alias` records a stable frontend exposure summary containing alias, selector kind, selector string, ref type, axis, and optional subselector.
+
+## Unsupported selectors and constructs
+
+Unsupported in X3: `edge(...)`, `vertex(...)`, profile selectors, feature-output selectors, selector predicates, arbitrary topology queries, raw backend/STEP/BRep/coedge IDs, aliases as feature targets, expose blocks outside Box records, regions, side-hole, chamfer, shell, material/FEA, templates/concepts/PMI/where, and selector-driven BRep emission.
+
+## Alias-copying / `with` policy
+
+`base with { size: [...] }` remains valid. X3 does not silently copy aliases through `with`; derived records receive no inherited exposure aliases. Expose blocks on derived records are rejected as unsupported until an explicit alias-copying rule is designed.
+
+## Trace JSON/text shape
+
+Text trace prints an `Expose:` section beneath each V2 solid with entries such as `face(+Z) => top : FaceRef`. JSON includes `firmamentV2.solids[].exposures[]` entries with `alias`, `selectorKind`, `selector`, `refType`, `axis`, and `subselector` fields.
+
+## Fixture changes
+
+`fixtures/FirmamentV2/SemanticRefs/valid/named-box-faces-v2.valid.firmfixture` is now parser-backed and expected to reach `feature-air` with four exposures. Focused invalid fixtures cover duplicate aliases, invalid axes, raw backend IDs, `=>` outside expose blocks, and unsupported `edge(...)` selectors.
+
+## Diagnostics
+
+X3 defines stable diagnostics for unsupported expose blocks, non-Box expose usage, duplicate/invalid aliases, unsupported selectors, invalid axes, unsupported subselectors, fat arrows outside expose blocks, and forbidden raw backend ID references.
+
+## Tests run
+
+The implementation was validated with targeted build, CLI trace/help, valid/invalid fixture trace, and filtered CLI/Kernel/FrictionLab test commands during the X3 change.
+
+## Next milestone recommendation
+
+The next milestone should keep alias semantics metadata-only unless an explicit design lands for alias copying through derivation and selector-backed BRep/topology materialization.
diff --git a/fixtures/FirmamentV2/SemanticRefs/invalid/duplicate-expose-alias-v2.invalid.firmfixture b/fixtures/FirmamentV2/SemanticRefs/invalid/duplicate-expose-alias-v2.invalid.firmfixture
new file mode 100644
index 00000000..9e0d9f4d
--- /dev/null
+++ b/fixtures/FirmamentV2/SemanticRefs/invalid/duplicate-expose-alias-v2.invalid.firmfixture
@@ -0,0 +1,21 @@
+// fixture-id: duplicate-expose-alias-v2
+// case: firmament-v2-duplicate-expose-alias
+// category: SemanticRefs
+// syntax-version: FirmamentV2
+// validity: invalid
+// implementation: parser-backed
+// expected: invalid
+// expected-stage: parsed
+// expected-diagnostic: firmament-v2-expose-alias-duplicate
+// parser-backed: true
+
+model DuplicateExposeAlias {
+ units mm
+ solid base: Box {
+ size: [10, 8, 6]
+ expose {
+ face(+Z) => top
+ face(-Z) => top
+ }
+ }
+}
diff --git a/fixtures/FirmamentV2/SemanticRefs/invalid/fat-arrow-outside-expose-v2.invalid.firmfixture b/fixtures/FirmamentV2/SemanticRefs/invalid/fat-arrow-outside-expose-v2.invalid.firmfixture
new file mode 100644
index 00000000..3270f731
--- /dev/null
+++ b/fixtures/FirmamentV2/SemanticRefs/invalid/fat-arrow-outside-expose-v2.invalid.firmfixture
@@ -0,0 +1,18 @@
+// fixture-id: fat-arrow-outside-expose-v2
+// case: firmament-v2-fat-arrow-outside-expose
+// category: SemanticRefs
+// syntax-version: FirmamentV2
+// validity: invalid
+// implementation: parser-backed
+// expected: invalid
+// expected-stage: parsed
+// expected-diagnostic: firmament-v2-fat-arrow-outside-expose
+// parser-backed: true
+
+model FatArrowOutsideExpose {
+ units mm
+ solid base: Box {
+ size: [10, 8, 6]
+ face(+Z) => top
+ }
+}
diff --git a/fixtures/FirmamentV2/SemanticRefs/invalid/invalid-face-axis-v2.invalid.firmfixture b/fixtures/FirmamentV2/SemanticRefs/invalid/invalid-face-axis-v2.invalid.firmfixture
new file mode 100644
index 00000000..ffda7369
--- /dev/null
+++ b/fixtures/FirmamentV2/SemanticRefs/invalid/invalid-face-axis-v2.invalid.firmfixture
@@ -0,0 +1,18 @@
+// fixture-id: invalid-face-axis-v2
+// case: firmament-v2-invalid-face-axis
+// category: SemanticRefs
+// syntax-version: FirmamentV2
+// validity: invalid
+// implementation: parser-backed
+// expected: invalid
+// expected-stage: parsed
+// expected-diagnostic: firmament-v2-selector-axis-invalid
+// parser-backed: true
+
+model InvalidFaceAxis {
+ units mm
+ solid base: Box {
+ size: [10, 8, 6]
+ expose { face(+W) => badFace }
+ }
+}
diff --git a/fixtures/FirmamentV2/SemanticRefs/invalid/raw-brep-id-reference-v2.invalid.firmfixture b/fixtures/FirmamentV2/SemanticRefs/invalid/raw-brep-id-reference-v2.invalid.firmfixture
index d45690ef..9db982c6 100644
--- a/fixtures/FirmamentV2/SemanticRefs/invalid/raw-brep-id-reference-v2.invalid.firmfixture
+++ b/fixtures/FirmamentV2/SemanticRefs/invalid/raw-brep-id-reference-v2.invalid.firmfixture
@@ -3,16 +3,17 @@
// category: SemanticRefs
// syntax-version: FirmamentV2
// validity: invalid
-// implementation: rejected
+// implementation: parser-backed
// expected: invalid
-// expected-stage: rejected
+// expected-stage: parsed
// expected-diagnostic: firmament-raw-backend-id-reference-forbidden
-// notes: AIR-FIRMAMENT-A2.1 forbids backend topology IDs in source references.
+// parser-backed: true
+// notes: AIR-FIRMAMENT-X3 keeps raw backend topology IDs forbidden in source references.
model RawBRepIdReference {
units mm
- solid base = box { size: [10, 8, 6] }
- modify base {
- feature bad: Chamfer { target: brep.face("F-00017") distance: 0.2 }
+ solid base: Box {
+ size: [10, 8, 6]
+ expose { brep.face("F-00017") => badFace }
}
}
diff --git a/fixtures/FirmamentV2/SemanticRefs/invalid/unsupported-selector-edge-v2.invalid.firmfixture b/fixtures/FirmamentV2/SemanticRefs/invalid/unsupported-selector-edge-v2.invalid.firmfixture
new file mode 100644
index 00000000..de5861e3
--- /dev/null
+++ b/fixtures/FirmamentV2/SemanticRefs/invalid/unsupported-selector-edge-v2.invalid.firmfixture
@@ -0,0 +1,18 @@
+// fixture-id: unsupported-selector-edge-v2
+// case: firmament-v2-unsupported-selector-edge
+// category: SemanticRefs
+// syntax-version: FirmamentV2
+// validity: invalid
+// implementation: parser-backed
+// expected: invalid
+// expected-stage: parsed
+// expected-diagnostic: firmament-v2-selector-unsupported
+// parser-backed: true
+
+model UnsupportedSelectorEdge {
+ units mm
+ solid base: Box {
+ size: [10, 8, 6]
+ expose { edge(+Z, +X) => unsupportedEdge }
+ }
+}
diff --git a/fixtures/FirmamentV2/SemanticRefs/valid/named-box-faces-v2.valid.firmfixture b/fixtures/FirmamentV2/SemanticRefs/valid/named-box-faces-v2.valid.firmfixture
index d3c3f44f..2162fe85 100644
--- a/fixtures/FirmamentV2/SemanticRefs/valid/named-box-faces-v2.valid.firmfixture
+++ b/fixtures/FirmamentV2/SemanticRefs/valid/named-box-faces-v2.valid.firmfixture
@@ -3,21 +3,29 @@
// category: SemanticRefs
// 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.1 metadata-only semantic exposure fixture; not parser-backed.
+// expected-stage: feature-air
+// expected-feature-air: CreateBox
+// expected-exposure-count: 4
+// expected-exposure: top = FaceRef face(+Z)
+// expected-exposure: bottom = FaceRef face(-Z)
+// expected-exposure: right = FaceRef face(+X)
+// expected-exposure: topRim = LoopRef face(+Z).outerLoop
+// parser-backed: true
+// notes: AIR-FIRMAMENT-X3 parser-backed Box semantic exposure fixture advanced from A2.1 metadata-only design coverage.
model NamedBoxFaces {
units mm
- solid base = box {
+ solid base: Box {
size: [10, 8, 6]
+
expose {
face(+Z) => top
- face(+Z).outerLoop => topRim
+ face(-Z) => bottom
face(+X) => right
+ face(+Z).outerLoop => topRim
}
}
}