Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Implement Firmament V2 Forge concept applications

Yuechen Lib2a3e29be0c8
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentV2ForgeConceptApplicationTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentV2ForgeConceptApplicationTests.cs
new file mode 100644
index 00000000..ebdee4f5
--- /dev/null
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentV2ForgeConceptApplicationTests.cs
@@ -0,0 +1,74 @@
+using Aetheris.Kernel.Firmament.FirmamentV2;
+
+namespace Aetheris.Kernel.Firmament.Tests;
+
+public sealed class FirmamentV2ForgeConceptApplicationTests
+{
+ [Fact]
+ public void FirmamentV2ForgeConceptApplication_ParsesAndBindsProcessAndHole()
+ {
+ var result = FirmamentV2Parser.Parse(Source("Language/valid/concept-applications-forge.valid.firmfixture"));
+
+ Assert.True(result.IsSuccess, string.Join(", ", result.Diagnostics));
+ var document = result.Document!;
+ var process = Assert.Single(document.ManufacturingConcepts!);
+ Assert.Equal("process", process.Application.FamilyName);
+ Assert.Equal("CNC", process.Application.ConceptName);
+ Assert.Equal(["material", "minimumToolRadius"], process.Fields.Select(f => f.Name).ToArray());
+ Assert.True(FirmamentV2ForgeConceptRegistry.TryGet("process", "CNC", out _));
+ Assert.DoesNotContain(FirmamentV2Parser.ConceptMissingRequiredField, result.Diagnostics);
+
+ var feature = Assert.Single(document.FeatureConcepts!);
+ Assert.Equal("mountHole", feature.Name);
+ Assert.Equal("hole", feature.Application.FamilyName);
+ Assert.Equal("Countersink", feature.Application.ConceptName);
+ Assert.Equal(["target", "diameter", "countersinkDiameter", "angle"], feature.Fields.Select(f => f.Name).ToArray());
+ Assert.Equal("part.region(\"mountHoleA\")", feature.BoundFields!.Single(f => f.Name == "target").TargetSource);
+ Assert.NotNull(feature.BoundFields!.Single(f => f.Name == "diameter").BoundValue!.AliasTolerance);
+ Assert.NotNull(feature.BoundFields!.Single(f => f.Name == "countersinkDiameter").BoundValue!.AliasTolerance);
+ }
+
+ [Theory]
+ [InlineData("manufacturing banana<CNC> {\n material: \"Aluminum6061\"\n}", FirmamentV2Parser.ConceptUnknownFamily)]
+ [InlineData("manufacturing process<LaserGoblin> {\n material: \"Aluminum6061\"\n minimumToolRadius: 1.5mm\n}", FirmamentV2Parser.ConceptUnknownConcept)]
+ [InlineData("manufacturing process<CNC> {\n material: \"Aluminum6061\"\n}", FirmamentV2Parser.ConceptMissingRequiredField)]
+ [InlineData("manufacturing process<CNC> {\n material: \"Aluminum6061\"\n material: \"Steel\"\n minimumToolRadius: 1.5mm\n}", FirmamentV2Parser.ConceptDuplicateField)]
+ [InlineData("manufacturing process<CNC> {\n material: \"Aluminum6061\"\n minimumToolRadius: 1.5\n}", FirmamentV2Parser.ConceptFieldTypeMismatch)]
+ [InlineData("feature mountHole: hole<Countersink> {\n target: part.region(\"mountHoleA\")\n diameter: 6.0mm\n countersinkDiameter: 10.0mm\n angle: 90mm\n}", FirmamentV2Parser.ConceptFieldTypeMismatch)]
+ public void FirmamentV2ForgeConceptApplication_InvalidConceptsProduceDeterministicDiagnostics(string conceptSource, string diagnostic)
+ {
+ var source = $$"""
+ model InvalidConceptProbe {
+ units mm
+ solid part: Box { size: [20, 20, 6] }
+ {{conceptSource}}
+ }
+ """;
+
+ var result = FirmamentV2Parser.Parse(source);
+
+ Assert.False(result.IsSuccess);
+ Assert.Contains(diagnostic, result.Diagnostics);
+ }
+
+ [Fact]
+ public void FirmamentV2ForgeConceptApplication_DoesNotLowerToDfmPmiOrGeometry()
+ {
+ var result = FirmamentV2Parser.Parse(Source("Language/valid/concept-applications-forge.valid.firmfixture"));
+
+ Assert.True(result.IsSuccess, string.Join(", ", result.Diagnostics));
+ Assert.Empty(result.Document!.Templates!);
+ Assert.Empty(result.Document.Pmi!);
+ Assert.Empty(result.Document.ModifyBlocks!);
+ Assert.Single(result.Document.Solids);
+ }
+
+ private static string Source(string relative) => File.ReadAllText(Path.Combine(FindRepoRoot(), "fixtures/FirmamentV2", relative));
+
+ private static string FindRepoRoot()
+ {
+ var dir = new DirectoryInfo(AppContext.BaseDirectory);
+ while (dir is not null && !File.Exists(Path.Combine(dir.FullName, "Aetheris.slnx"))) dir = dir.Parent;
+ return dir?.FullName ?? throw new InvalidOperationException("Could not find repo root.");
+ }
+}
diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.cs
index e41dd480..80bf77a1 100644
--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.cs
@@ -1,6 +1,6 @@
namespace Aetheris.Kernel.Firmament.FirmamentV2;
-public sealed record FirmamentV2Document(string ModelName, string Units, IReadOnlyList<FirmamentV2SolidBinding> Solids, IReadOnlyList<FirmamentV2ModifyBlock>? ModifyBlocks = null, IReadOnlyList<FirmamentV2TemplateDecl>? Templates = null, IReadOnlyList<FirmamentV2PmiDecl>? Pmi = null, IReadOnlyList<FirmamentV2RecognizedRegion>? RecognizedRegions = null, IReadOnlyList<FirmamentV2ReplacementDecl>? Replacements = null, IReadOnlyList<FirmamentV2LetDeclaration>? Lets = null, IReadOnlyList<FirmamentV2BoundLet>? BoundLets = null, IReadOnlyList<FirmamentV2LetRecordDeclaration>? LetRecords = null, IReadOnlyList<FirmamentV2BoundLetRecord>? BoundLetRecords = null)
+public sealed record FirmamentV2Document(string ModelName, string Units, IReadOnlyList<FirmamentV2SolidBinding> Solids, IReadOnlyList<FirmamentV2ModifyBlock>? ModifyBlocks = null, IReadOnlyList<FirmamentV2TemplateDecl>? Templates = null, IReadOnlyList<FirmamentV2PmiDecl>? Pmi = null, IReadOnlyList<FirmamentV2RecognizedRegion>? RecognizedRegions = null, IReadOnlyList<FirmamentV2ReplacementDecl>? Replacements = null, IReadOnlyList<FirmamentV2LetDeclaration>? Lets = null, IReadOnlyList<FirmamentV2BoundLet>? BoundLets = null, IReadOnlyList<FirmamentV2LetRecordDeclaration>? LetRecords = null, IReadOnlyList<FirmamentV2BoundLetRecord>? BoundLetRecords = null, IReadOnlyList<FirmamentV2ManufacturingConceptDeclaration>? ManufacturingConcepts = null, IReadOnlyList<FirmamentV2FeatureConceptDeclaration>? FeatureConcepts = null)
{
public FirmamentV2SolidBinding Solid => Solids[^1];
public FirmamentV2SideHoleIntent? SideHoleIntent => ModifyBlocks?.SelectMany(m => m.Regions.Select(r =>
@@ -34,6 +34,12 @@ public sealed record FirmamentV2BoundExpression(FirmamentV2PrimitiveType Inferre
public sealed record FirmamentV2BoundLet(string Name, FirmamentV2PrimitiveType Type, FirmamentV2LiteralValue Value, FirmamentV2SourceSpan SourceSpan, FirmamentV2BoundExpression? Expression = null, IReadOnlySet<string>? Dependencies = null, FirmamentV2Tolerance? Tolerance = null);
public sealed record FirmamentV2BoundLetRecord(string Name, IReadOnlyDictionary<string, FirmamentV2BoundLet> Fields, FirmamentV2SourceSpan SourceSpan);
+public sealed record FirmamentV2ConceptApplication(string FamilyName, string ConceptName, FirmamentV2SourceSpan SourceSpan);
+public sealed record FirmamentV2ConceptField(string Name, FirmamentV2ValueExpression ValueExpression, string Source, FirmamentV2SourceSpan SourceSpan);
+public sealed record FirmamentV2BoundConceptField(string Name, FirmamentV2ConceptField Field, FirmamentV2BoundExpression? BoundValue, string? TargetSource = null);
+public sealed record FirmamentV2ManufacturingConceptDeclaration(FirmamentV2ConceptApplication Application, IReadOnlyList<FirmamentV2ConceptField> Fields, FirmamentV2SourceSpan SourceSpan, IReadOnlyList<FirmamentV2BoundConceptField>? BoundFields = null);
+public sealed record FirmamentV2FeatureConceptDeclaration(string Name, FirmamentV2ConceptApplication Application, IReadOnlyList<FirmamentV2ConceptField> Fields, FirmamentV2SourceSpan SourceSpan, IReadOnlyList<FirmamentV2BoundConceptField>? BoundFields = null);
+
public sealed record FirmamentV2SolidBinding(string Name, string RecordType, FirmamentV2PrimitiveRecord Primitive, string? DerivedFrom = null, IReadOnlyDictionary<string, IReadOnlyList<double>>? Overrides = null)
{
public bool IsDerived => !string.IsNullOrWhiteSpace(DerivedFrom);
diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2ForgeConceptRegistry.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2ForgeConceptRegistry.cs
new file mode 100644
index 00000000..c32e1fdc
--- /dev/null
+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2ForgeConceptRegistry.cs
@@ -0,0 +1,75 @@
+namespace Aetheris.Kernel.Firmament.FirmamentV2;
+
+public enum FirmamentV2ForgeFieldKind
+{
+ Length,
+ Angle,
+ Target,
+ Material
+}
+
+public sealed record FirmamentV2ForgeFieldDescriptor(string Name, FirmamentV2ForgeFieldKind Kind, bool Required)
+{
+ public bool Accepts(FirmamentV2PrimitiveType type) => Kind switch
+ {
+ FirmamentV2ForgeFieldKind.Length => type == FirmamentV2PrimitiveType.Length,
+ FirmamentV2ForgeFieldKind.Angle => type == FirmamentV2PrimitiveType.Angle,
+ FirmamentV2ForgeFieldKind.Material => type == FirmamentV2PrimitiveType.String,
+ FirmamentV2ForgeFieldKind.Target => false,
+ _ => false
+ };
+}
+
+public sealed record FirmamentV2ForgeConceptDescriptor(string FamilyName, string ConceptName, IReadOnlyDictionary<string, FirmamentV2ForgeFieldDescriptor> Fields);
+
+public static class FirmamentV2ForgeConceptRegistry
+{
+ private static readonly IReadOnlyDictionary<string, IReadOnlyDictionary<string, FirmamentV2ForgeConceptDescriptor>> Families = Build();
+
+ public static bool HasFamily(string familyName) => Families.ContainsKey(familyName);
+
+ public static bool TryGet(string familyName, string conceptName, out FirmamentV2ForgeConceptDescriptor descriptor)
+ {
+ descriptor = null!;
+ if (!Families.TryGetValue(familyName, out var concepts)) return false;
+ return concepts.TryGetValue(conceptName, out descriptor!);
+ }
+
+ private static IReadOnlyDictionary<string, IReadOnlyDictionary<string, FirmamentV2ForgeConceptDescriptor>> Build()
+ {
+ var process = new Dictionary<string, FirmamentV2ForgeConceptDescriptor>(StringComparer.Ordinal)
+ {
+ ["CNC"] = Descriptor("process", "CNC",
+ Field("material", FirmamentV2ForgeFieldKind.Material),
+ Field("minimumToolRadius", FirmamentV2ForgeFieldKind.Length))
+ };
+
+ var hole = new Dictionary<string, FirmamentV2ForgeConceptDescriptor>(StringComparer.Ordinal)
+ {
+ ["Countersink"] = Descriptor("hole", "Countersink",
+ Field("target", FirmamentV2ForgeFieldKind.Target),
+ Field("diameter", FirmamentV2ForgeFieldKind.Length),
+ Field("countersinkDiameter", FirmamentV2ForgeFieldKind.Length),
+ Field("angle", FirmamentV2ForgeFieldKind.Angle)),
+ ["Shaft"] = Descriptor("hole", "Shaft",
+ Field("target", FirmamentV2ForgeFieldKind.Target),
+ Field("diameter", FirmamentV2ForgeFieldKind.Length)),
+ ["Counterbore"] = Descriptor("hole", "Counterbore",
+ Field("target", FirmamentV2ForgeFieldKind.Target),
+ Field("diameter", FirmamentV2ForgeFieldKind.Length),
+ Field("counterboreDiameter", FirmamentV2ForgeFieldKind.Length),
+ Field("counterboreDepth", FirmamentV2ForgeFieldKind.Length))
+ };
+
+ return new Dictionary<string, IReadOnlyDictionary<string, FirmamentV2ForgeConceptDescriptor>>(StringComparer.Ordinal)
+ {
+ ["process"] = process,
+ ["hole"] = hole
+ };
+ }
+
+ private static FirmamentV2ForgeConceptDescriptor Descriptor(string family, string concept, params FirmamentV2ForgeFieldDescriptor[] fields) =>
+ new(family, concept, fields.ToDictionary(f => f.Name, StringComparer.Ordinal));
+
+ private static FirmamentV2ForgeFieldDescriptor Field(string name, FirmamentV2ForgeFieldKind kind) => new(name, kind, true);
+}
diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs
index 89170989..e4414348 100644
--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs
@@ -39,6 +39,15 @@ public static class FirmamentV2Parser
public const string DfmConceptUnitMismatch = "firmament-v2-dfm-concept-unit-mismatch";
public const string DfmMinimumToolRadiusViolation = "firmament-v2-dfm-minimum-tool-radius-violation";
+ public const string ConceptUnknownFamily = "firmament-v2-concept-unknown-family";
+ public const string ConceptUnknownConcept = "firmament-v2-concept-unknown-concept";
+ public const string ConceptMissingRequiredField = "firmament-v2-concept-missing-required-field";
+ public const string ConceptUnknownField = "firmament-v2-concept-unknown-field";
+ public const string ConceptDuplicateField = "firmament-v2-concept-duplicate-field";
+ public const string ConceptFieldTypeMismatch = "firmament-v2-concept-field-type-mismatch";
+ public const string ConceptInvalidTarget = "firmament-v2-concept-invalid-target";
+ public const string ConceptDescriptorUnavailable = "firmament-v2-concept-descriptor-unavailable";
+
public const string LetDuplicateName = "firmament-v2-let-duplicate-name";
public const string LetUnknownType = "firmament-v2-let-unknown-type";
public const string LetTypeMismatch = "firmament-v2-let-type-mismatch";
@@ -141,7 +150,7 @@ public static class FirmamentV2Parser
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 HashSet<string> ReservedWords = new(StringComparer.Ordinal) { "let", "model", "units", "solid", "modify", "region", "cut", "template", "concept", "pmi", "recognize", "replace", "with", "true", "false", "int", "float", "length", "angle", "string", "bool", "tol" };
+ private static readonly HashSet<string> ReservedWords = new(StringComparer.Ordinal) { "let", "model", "units", "solid", "modify", "region", "cut", "template", "concept", "pmi", "recognize", "replace", "with", "manufacturing", "process", "feature", "true", "false", "int", "float", "length", "angle", "string", "bool", "tol" };
private static readonly Regex LetRegex = new(@"\blet\s+(?<name>[A-Za-z_][A-Za-z0-9_]*)\s*:\s*(?<type>[A-Za-z_][A-Za-z0-9_]*)\s*=\s*(?<literal>[^\r\n{}]+)", RegexOptions.CultureInvariant);
private static readonly Regex LetRecordHeaderRegex = new(@"^\s*let\s+(?<name>[A-Za-z_][A-Za-z0-9_]*)\s*\{", RegexOptions.CultureInvariant | RegexOptions.Multiline);
private static readonly Regex LetRecordFieldRegex = new(@"^\s*(?<name>[A-Za-z_][A-Za-z0-9_]*)\s*:\s*(?<type>[A-Za-z_][A-Za-z0-9_]*)\s*=\s*(?<literal>.+?)\s*$", RegexOptions.CultureInvariant);
@@ -181,6 +190,10 @@ public static class FirmamentV2Parser
private static readonly Regex ImportedFaceTargetRegex = new("^(?<body>[A-Za-z_][A-Za-z0-9_]*)\\.face\\(\\\"(?<entity>#[0-9]+)\\\"\\)$", RegexOptions.CultureInvariant);
private static readonly Regex RecognizedRegionTargetRegex = new("^(?<body>[A-Za-z_][A-Za-z0-9_]*)\\.region\\(\\\"(?<region>[A-Za-z_][A-Za-z0-9_]*)\\\"\\)$", RegexOptions.CultureInvariant);
private static readonly Regex ValueRegex = new(@"\b(?:value|diameter)\s*:\s*(?<value>[^\s}]+)", RegexOptions.CultureInvariant);
+ private static readonly Regex ManufacturingConceptHeaderRegex = new(@"\bmanufacturing\s+(?<family>[A-Za-z_][A-Za-z0-9_]*)\s*<\s*(?<concept>[A-Za-z_][A-Za-z0-9_]*)\s*>\s*\{", RegexOptions.CultureInvariant);
+ private static readonly Regex FeatureConceptHeaderRegex = new(@"\bfeature\s+(?<name>[A-Za-z_][A-Za-z0-9_]*)\s*:\s*(?<family>[A-Za-z_][A-Za-z0-9_]*)\s*<\s*(?<concept>[A-Za-z_][A-Za-z0-9_]*)\s*>\s*\{", RegexOptions.CultureInvariant);
+ private static readonly Regex ConceptFieldLineRegex = new(@"^\s*(?<name>[A-Za-z_][A-Za-z0-9_]*)\s*:\s*(?<value>.+?)\s*$", RegexOptions.CultureInvariant);
+ private static readonly Regex TargetExpressionRegex = new(@"^[A-Za-z_][A-Za-z0-9_]*\.(?:region|face)\(""[^""]+""\)$", RegexOptions.CultureInvariant);
private static readonly Regex TemplateHeaderRegex = new(@"\btemplate\s*<\s*(?<process>[A-Za-z_][A-Za-z0-9_]*)\s*>\s+(?<name>[A-Za-z_][A-Za-z0-9_]*)\s*\{", RegexOptions.CultureInvariant);
private static readonly Regex ConceptRegex = new(@"\bconcept\s+(?<name>[A-Za-z_][A-Za-z0-9_]*)\s*:\s*(?<value>[-+0-9.eE]+)\s*(?<unit>[A-Za-z_][A-Za-z0-9_]*)?", RegexOptions.CultureInvariant);
private static readonly Regex PathRegex = new("\\bpath\\s*:\\s*\"(?<path>[^\"]+)\"", RegexOptions.CultureInvariant);
@@ -240,10 +253,11 @@ public static class FirmamentV2Parser
var recognizedRegions = ParseRecognizedRegions(source, byName, diagnostics);
var replacements = ParseReplacements(source, byName, recognizedRegions, diagnostics);
var pmi = ParsePmi(source, byName, modifyBlocks, recognizedRegions, diagnostics);
+ var (manufacturingConcepts, featureConcepts) = ParseConceptApplications(source, boundLets, boundLetRecords, diagnostics);
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, modifyBlocks, templates, pmi, recognizedRegions, replacements, lets, boundLets, letRecords, boundLetRecords);
+ document = new FirmamentV2Document(modelMatch.Groups["name"].Value, unitsMatch.Groups["units"].Value, solids, modifyBlocks, templates, pmi, recognizedRegions, replacements, lets, boundLets, letRecords, boundLetRecords, manufacturingConcepts, featureConcepts);
diagnostics.Add(document is null ? "firmament-v2-parse-failed" : "firmament-v2-parse-succeeded");
diagnostics.Sort(StringComparer.Ordinal);
@@ -665,7 +679,7 @@ public static class FirmamentV2Parser
return new(name, "Box", new FirmamentV2BoxRecord(values, []), baseName, new Dictionary<string, IReadOnlyList<double>>(StringComparer.Ordinal) { ["size"] = values });
}
- private static bool IsFatalDiagnostic(string code) => code is PrimitiveFieldMissing or PrimitiveFieldUnknown or PrimitiveFieldInvalid or 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 or ModifyTargetUnresolved or ModifyTargetNotSolid or RegionUnsupported or RegionAttachmentSelectorUnsupported or CutUnsupported or CutToolUnsupported or CylinderRadiusMissing or CylinderRadiusInvalid or CylinderRadiusNotFinite or ThroughSelectorUnsupported or AliasUnresolved or AliasRefTypeUnsupported or SideHoleAliasMustResolveToFace or SideHoleAliasResolvesToUnsupportedFace or SideHoleOnlyPlusXMinusXSupported or SideHoleRouteUnsupported or SideHoleSameFaceUnsupported or SideHoleAxisNotYetSupported or SideHoleRadiusExceedsClearance or CylinderCenterInvalid or CylinderCenterArityInvalid or CylinderCenterNotFinite or SideHoleCenterExceedsClearance or HoleVariantUnknown or HoleEntryFaceMissing or HoleCenterMissing or HoleShaftMissing or HoleEndMissing or HoleDiameterInvalid or HoleDepthInvalid or HoleCounterboreInvalid or HoleCountersinkInvalid or PmiKindUnknown or PmiTargetMissing or PmiTargetUnresolved or PmiDiameterInvalid or PmiDuplicateName or InlineStepUnknownBody or InlineStepUnknownFace or PmiImportedTargetNotFace or PmiImportedTargetRequiresCanonicalStep or PmiInvalidImportedTarget or InlineStepPathMissing or InlineStepPathInvalid or InlineStepFileMissing or InlineStepRequiresCanonical or UnknownRecognitionBody or UnknownRecognitionFace or DuplicateRegion or UnknownRecognitionRegion or InvalidRecognitionKind or InvalidRecognitionConfidence or PmiRecognizedRegionKindMismatch or UnknownReplacementBody or UnknownReplacementRegion or ReplacementKindMismatch or ReplacementFaceUnresolved or ReplacementUnsupportedKind or ReplacementVerificationFailed or ReplacementRadiusInvalid or ReplacementEndUnsupported or LetDuplicateName or LetUnknownType or LetTypeMismatch or LetInvalidLiteral or LetUnitMismatch or LetLiteralOnly or LetRecordDuplicateName or LetRecordDuplicateField or LetReferenceUnknownRecord or LetReferenceUnknownField or LetReferenceNonRecord or LetReferenceRecordUsedAsValue or ExpressionUnknownSymbol or ExpressionUnknownRecord or ExpressionUnknownField or ExpressionRecordUsedAsValue or ExpressionScalarUsedAsRecord or ExpressionTypeMismatch or ExpressionInvalidOperator or ExpressionDivisionByZero or ExpressionCycle or ExpressionUnsupported or ToleranceInvalidType or ToleranceUnitMismatch or ToleranceInvalidLiteral or ToleranceNegativeBilateral or ToleranceMissingMinus or ToleranceMissingPlus or ToleranceUnsupported or RecognitionEvidenceRadiusInvalid or RecognitionEvidenceSurfaceFamilyUnknown or RecognitionEvidenceAxisInvalid or SemanticProposalKindMismatch or SemanticProposalRadiusInvalid or SemanticProposalTargetUnresolved or SemanticProposalEndUnsupported;
+ private static bool IsFatalDiagnostic(string code) => code is PrimitiveFieldMissing or PrimitiveFieldUnknown or PrimitiveFieldInvalid or 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 or ModifyTargetUnresolved or ModifyTargetNotSolid or RegionUnsupported or RegionAttachmentSelectorUnsupported or CutUnsupported or CutToolUnsupported or CylinderRadiusMissing or CylinderRadiusInvalid or CylinderRadiusNotFinite or ThroughSelectorUnsupported or AliasUnresolved or AliasRefTypeUnsupported or SideHoleAliasMustResolveToFace or SideHoleAliasResolvesToUnsupportedFace or SideHoleOnlyPlusXMinusXSupported or SideHoleRouteUnsupported or SideHoleSameFaceUnsupported or SideHoleAxisNotYetSupported or SideHoleRadiusExceedsClearance or CylinderCenterInvalid or CylinderCenterArityInvalid or CylinderCenterNotFinite or SideHoleCenterExceedsClearance or HoleVariantUnknown or HoleEntryFaceMissing or HoleCenterMissing or HoleShaftMissing or HoleEndMissing or HoleDiameterInvalid or HoleDepthInvalid or HoleCounterboreInvalid or HoleCountersinkInvalid or PmiKindUnknown or PmiTargetMissing or PmiTargetUnresolved or PmiDiameterInvalid or PmiDuplicateName or InlineStepUnknownBody or InlineStepUnknownFace or PmiImportedTargetNotFace or PmiImportedTargetRequiresCanonicalStep or PmiInvalidImportedTarget or InlineStepPathMissing or InlineStepPathInvalid or InlineStepFileMissing or InlineStepRequiresCanonical or UnknownRecognitionBody or UnknownRecognitionFace or DuplicateRegion or UnknownRecognitionRegion or InvalidRecognitionKind or InvalidRecognitionConfidence or PmiRecognizedRegionKindMismatch or UnknownReplacementBody or UnknownReplacementRegion or ReplacementKindMismatch or ReplacementFaceUnresolved or ReplacementUnsupportedKind or ReplacementVerificationFailed or ReplacementRadiusInvalid or ReplacementEndUnsupported or LetDuplicateName or LetUnknownType or LetTypeMismatch or LetInvalidLiteral or LetUnitMismatch or LetLiteralOnly or LetRecordDuplicateName or LetRecordDuplicateField or LetReferenceUnknownRecord or LetReferenceUnknownField or LetReferenceNonRecord or LetReferenceRecordUsedAsValue or ExpressionUnknownSymbol or ExpressionUnknownRecord or ExpressionUnknownField or ExpressionRecordUsedAsValue or ExpressionScalarUsedAsRecord or ExpressionTypeMismatch or ExpressionInvalidOperator or ExpressionDivisionByZero or ExpressionCycle or ExpressionUnsupported or ToleranceInvalidType or ToleranceUnitMismatch or ToleranceInvalidLiteral or ToleranceNegativeBilateral or ToleranceMissingMinus or ToleranceMissingPlus or ToleranceUnsupported or RecognitionEvidenceRadiusInvalid or RecognitionEvidenceSurfaceFamilyUnknown or RecognitionEvidenceAxisInvalid or SemanticProposalKindMismatch or SemanticProposalRadiusInvalid or SemanticProposalTargetUnresolved or SemanticProposalEndUnsupported or ConceptUnknownFamily or ConceptUnknownConcept or ConceptMissingRequiredField or ConceptUnknownField or ConceptDuplicateField or ConceptFieldTypeMismatch or ConceptInvalidTarget or ConceptDescriptorUnavailable;
private static IReadOnlyList<FirmamentV2Exposure> ParseExposures(string body, List<string> diagnostics)
{
@@ -932,6 +946,131 @@ public static class FirmamentV2Parser
}
return FirmamentV2FaceTarget.Alias(source, exposure.Axis);
}
+
+ private static (IReadOnlyList<FirmamentV2ManufacturingConceptDeclaration> Manufacturing, IReadOnlyList<FirmamentV2FeatureConceptDeclaration> Features) ParseConceptApplications(
+ string source,
+ IReadOnlyList<FirmamentV2BoundLet> boundLets,
+ IReadOnlyList<FirmamentV2BoundLetRecord> boundLetRecords,
+ List<string> diagnostics)
+ {
+ var manufacturing = new List<FirmamentV2ManufacturingConceptDeclaration>();
+ foreach (Match match in ManufacturingConceptHeaderRegex.Matches(source))
+ {
+ var open = source.IndexOf('{', match.Index);
+ var close = FindMatchingBrace(source, open);
+ if (close < 0) { diagnostics.Add(UnsupportedConstruct); continue; }
+ var application = new FirmamentV2ConceptApplication(match.Groups["family"].Value, match.Groups["concept"].Value, new(match.Groups["family"].Index, match.Groups["concept"].Index + match.Groups["concept"].Length - match.Groups["family"].Index));
+ var fields = ParseConceptFields(source[(open + 1)..close], open + 1, diagnostics);
+ var bound = ValidateConceptApplication(application, fields, boundLets, boundLetRecords, diagnostics);
+ manufacturing.Add(new(application, fields, new(match.Index, close - match.Index + 1), bound));
+ }
+
+ var features = new List<FirmamentV2FeatureConceptDeclaration>();
+ foreach (Match match in FeatureConceptHeaderRegex.Matches(source))
+ {
+ var open = source.IndexOf('{', match.Index);
+ var close = FindMatchingBrace(source, open);
+ if (close < 0) { diagnostics.Add(UnsupportedConstruct); continue; }
+ var application = new FirmamentV2ConceptApplication(match.Groups["family"].Value, match.Groups["concept"].Value, new(match.Groups["family"].Index, match.Groups["concept"].Index + match.Groups["concept"].Length - match.Groups["family"].Index));
+ var fields = ParseConceptFields(source[(open + 1)..close], open + 1, diagnostics);
+ var bound = ValidateConceptApplication(application, fields, boundLets, boundLetRecords, diagnostics);
+ features.Add(new(match.Groups["name"].Value, application, fields, new(match.Index, close - match.Index + 1), bound));
+ }
+
+ return (manufacturing, features);
+ }
+
+ private static IReadOnlyList<FirmamentV2ConceptField> ParseConceptFields(string body, int bodyStart, List<string> diagnostics)
+ {
+ var fields = new List<FirmamentV2ConceptField>();
+ var offset = 0;
+ foreach (var rawLine in body.Split('\n'))
+ {
+ var lineStart = bodyStart + offset;
+ offset += rawLine.Length + 1;
+ var line = rawLine.Trim();
+ if (line.Length == 0) continue;
+ var match = ConceptFieldLineRegex.Match(line);
+ if (!match.Success) { diagnostics.Add(UnsupportedConstruct); continue; }
+ var valueSource = match.Groups["value"].Value.Trim();
+ var expression = ParseConceptFieldExpression(valueSource, diagnostics);
+ if (expression is not null)
+ fields.Add(new(match.Groups["name"].Value, expression, valueSource, new(lineStart + rawLine.IndexOf(match.Groups["name"].Value, StringComparison.Ordinal), rawLine.Length)));
+ }
+
+ return fields;
+ }
+
+ private static FirmamentV2ValueExpression? ParseConceptFieldExpression(string valueSource, List<string> diagnostics)
+ {
+ if (TargetExpressionRegex.IsMatch(valueSource)) return new FirmamentV2IdentifierReferenceExpression(valueSource, valueSource);
+ if (valueSource.IndexOfAny(['+', '-', '*', '/', '(', ')']) >= 0 && !valueSource.EndsWith(")", StringComparison.Ordinal))
+ {
+ diagnostics.Add(ExpressionUnsupported);
+ return null;
+ }
+
+ var dotted = DottedReferenceRegex.Match(valueSource);
+ if (dotted.Success) return new FirmamentV2DottedReferenceExpression(dotted.Groups["record"].Value, dotted.Groups["field"].Value, valueSource);
+ if (valueSource is "true" or "false") return new FirmamentV2LiteralExpression(new(FirmamentV2PrimitiveType.Bool, valueSource == "true", null, null, valueSource));
+ if (Regex.IsMatch(valueSource, "^\\\"[^\\\"]*\\\"$", RegexOptions.CultureInvariant)) return new FirmamentV2LiteralExpression(new(FirmamentV2PrimitiveType.String, valueSource[1..^1], null, null, valueSource));
+ if (Regex.IsMatch(valueSource, @"^[A-Za-z_][A-Za-z0-9_]*$", RegexOptions.CultureInvariant)) return new FirmamentV2IdentifierReferenceExpression(valueSource, valueSource);
+ var type = valueSource.EndsWith("mm", StringComparison.Ordinal) ? FirmamentV2PrimitiveType.Length : valueSource.EndsWith("deg", StringComparison.Ordinal) ? FirmamentV2PrimitiveType.Angle : valueSource.Contains('.', StringComparison.Ordinal) ? FirmamentV2PrimitiveType.Float : FirmamentV2PrimitiveType.Int;
+ var literal = ParseLetLiteral(type, valueSource, diagnostics);
+ if (literal is not null) return new FirmamentV2LiteralExpression(literal);
+ diagnostics.Add(ExpressionUnsupported);
+ return null;
+ }
+
+ private static IReadOnlyList<FirmamentV2BoundConceptField> ValidateConceptApplication(
+ FirmamentV2ConceptApplication application,
+ IReadOnlyList<FirmamentV2ConceptField> fields,
+ IReadOnlyList<FirmamentV2BoundLet> boundLets,
+ IReadOnlyList<FirmamentV2BoundLetRecord> boundLetRecords,
+ List<string> diagnostics)
+ {
+ if (!FirmamentV2ForgeConceptRegistry.TryGet(application.FamilyName, application.ConceptName, out var descriptor))
+ {
+ diagnostics.Add(FirmamentV2ForgeConceptRegistry.HasFamily(application.FamilyName) ? ConceptUnknownConcept : ConceptUnknownFamily);
+ return [];
+ }
+
+ var bound = new List<FirmamentV2BoundConceptField>();
+ var seen = new HashSet<string>(StringComparer.Ordinal);
+ var fieldNames = fields.Select(f => f.Name).ToHashSet(StringComparer.Ordinal);
+ foreach (var field in fields)
+ {
+ if (!seen.Add(field.Name)) { diagnostics.Add(ConceptDuplicateField); continue; }
+ if (!descriptor.Fields.TryGetValue(field.Name, out var schema)) { diagnostics.Add(ConceptUnknownField); continue; }
+ bound.Add(BindConceptField(field, schema, boundLets, boundLetRecords, diagnostics));
+ }
+
+ foreach (var required in descriptor.Fields.Values.Where(f => f.Required))
+ if (!fieldNames.Contains(required.Name)) diagnostics.Add(ConceptMissingRequiredField);
+ return bound;
+ }
+
+ private static FirmamentV2BoundConceptField BindConceptField(FirmamentV2ConceptField field, FirmamentV2ForgeFieldDescriptor schema, IReadOnlyList<FirmamentV2BoundLet> boundLets, IReadOnlyList<FirmamentV2BoundLetRecord> boundLetRecords, List<string> diagnostics)
+ {
+ if (schema.Kind == FirmamentV2ForgeFieldKind.Target)
+ {
+ if (!TargetExpressionRegex.IsMatch(field.Source)) diagnostics.Add(ConceptInvalidTarget);
+ return new(field.Name, field, null, field.Source);
+ }
+
+ FirmamentV2BoundExpression? bound = field.ValueExpression switch
+ {
+ FirmamentV2LiteralExpression l => new(l.Value.Type, l.Value, new HashSet<string>(StringComparer.Ordinal), field.SourceSpan),
+ FirmamentV2IdentifierReferenceExpression r when boundLets.FirstOrDefault(l => l.Name == r.Name) is { } let => new(let.Type, let.Value, new HashSet<string>((let.Dependencies ?? new HashSet<string>()).Append(let.Name), StringComparer.Ordinal), let.SourceSpan, let.Tolerance),
+ FirmamentV2IdentifierReferenceExpression r when schema.Kind == FirmamentV2ForgeFieldKind.Material => new(FirmamentV2PrimitiveType.String, new(FirmamentV2PrimitiveType.String, r.Name, null, null, r.Source), new HashSet<string>(StringComparer.Ordinal), field.SourceSpan),
+ FirmamentV2DottedReferenceExpression r when boundLetRecords.FirstOrDefault(x => x.Name == r.RecordName)?.Fields.TryGetValue(r.FieldName, out var f) == true => new(f.Type, f.Value, new HashSet<string> { $"{r.RecordName}.{r.FieldName}" }, f.SourceSpan, f.Tolerance),
+ _ => null
+ };
+
+ if (bound is null) diagnostics.Add(ExpressionUnknownSymbol);
+ else if (!schema.Accepts(bound.InferredType)) diagnostics.Add(ConceptFieldTypeMismatch);
+ return new(field.Name, field, bound);
+ }
private static IReadOnlyList<FirmamentV2TemplateDecl> ParseTemplates(string source, List<string> diagnostics)
{
var templates = new List<FirmamentV2TemplateDecl>();
@@ -1264,7 +1403,7 @@ public static class FirmamentV2Parser
}
private static bool ContainsUnsupportedConstruct(string source) =>
- Regex.IsMatch(source, @"\b(PMI|where|add|shell|fillet|chamfer|regions|profile|material|pattern)\b|<\s*Process\s*>", RegexOptions.CultureInvariant);
+ Regex.IsMatch(source, @"\b(PMI|where|add|shell|fillet|chamfer|regions|profile|pattern)\b|<\s*Process\s*>", RegexOptions.CultureInvariant);
private static bool ContainsRawBackendId(string source) =>
Regex.IsMatch(source, @"\b(brep|backend|coedge)\s*\.|STEP\s*#", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
diff --git a/docs/implementation/firmament-v2-f1-forge-concept-applications.md b/docs/implementation/firmament-v2-f1-forge-concept-applications.md
new file mode 100644
index 00000000..e696e57c
--- /dev/null
+++ b/docs/implementation/firmament-v2-f1-forge-concept-applications.md
@@ -0,0 +1,72 @@
+# Firmament V2 F1 Forge concept-family applications
+
+F1 implements the first Forge-backed concept-family application syntax for Firmament V2 Phase 1.
+
+## Supported syntax
+
+Firmament V2 now accepts generic `family<Concept>` applications in two declaration forms:
+
+```firmament
+manufacturing process<CNC> {
+ material: "Aluminum6061"
+ minimumToolRadius: 1.5mm
+}
+
+feature mountHole: hole<Countersink> {
+ target: part.region("mountHoleA")
+ diameter: MountingPattern.holeDiameter
+ countersinkDiameter: MountingPattern.countersinkDiameter
+ angle: 90deg
+}
+```
+
+The parser stores the concept-family application shape as `familyName`, `conceptName`, and source span. Manufacturing declarations store the application and fields; feature declarations also store the feature name.
+
+## Forge descriptor lookup behavior
+
+Concept applications are parsed generically. Concept names are not parser branches. After parsing, Firmament V2 validates the family and concept through the built-in Forge concept descriptor registry used by this phase-one workbench path.
+
+The registry is intentionally narrow and descriptor-oriented. It records field names, required status, and basic field kind expectations so later Forge milestones can add richer descriptor loading, DFM compatibility, PMI lowering, and reporting without changing the parser syntax.
+
+## Built-in concepts supported
+
+F1 includes these built-in descriptors:
+
+- `process<CNC>`
+- `hole<Countersink>`
+- `hole<Shaft>`
+- `hole<Counterbore>`
+
+Canonical spelling is case-sensitive as shown above for concept names, with lower-case family names.
+
+## Field validation rules
+
+F1 validates:
+
+- unknown concept family;
+- unknown concept within a known family;
+- missing required fields;
+- unknown fields;
+- duplicate fields;
+- basic field kind mismatches for length, angle, material, and target fields.
+
+Field values may be primitive literals, scalar let references, dotted let-record references, material identifiers/strings, or target expressions such as `part.region("mountHoleA")`. Toleranced let references preserve their alias tolerance metadata in the bound field value.
+
+Material typing remains intentionally simple: `material` accepts a string literal or bare material identifier and is treated as material identity text. Rich material catalogs are deferred.
+
+## Diagnostics
+
+F1 adds deterministic diagnostics:
+
+- `firmament-v2-concept-unknown-family`
+- `firmament-v2-concept-unknown-concept`
+- `firmament-v2-concept-missing-required-field`
+- `firmament-v2-concept-unknown-field`
+- `firmament-v2-concept-duplicate-field`
+- `firmament-v2-concept-field-type-mismatch`
+- `firmament-v2-concept-invalid-target`
+- `firmament-v2-concept-descriptor-unavailable`
+
+## Explicit non-scope
+
+F1 does not execute DFM checks, lower concept applications to PMI, create or mutate geometry, materialize hole features, or introduce hidden behavior. It also does not hardcode a complete concept catalog into parser grammar; concept-specific requirements live in descriptors/validation.
diff --git a/docs/v2/aetheris-v2-phase1-scope-contract.md b/docs/v2/aetheris-v2-phase1-scope-contract.md
index ba393d25..cb040096 100644
--- a/docs/v2/aetheris-v2-phase1-scope-contract.md
+++ b/docs/v2/aetheris-v2-phase1-scope-contract.md
@@ -427,7 +427,7 @@ L1: let declarations + primitive typed literals — implemented as top-level imm
L2: let record groups + dotted references
L3: arithmetic expression graph + acyclic validation
L4: tolerance syntax and tolerant dimension values
-F1: Forge concept-family application syntax
+F1: Forge concept-family application syntax — implemented for descriptor-validated `manufacturing process<CNC>` and `feature name: hole<Concept>` declarations; validation only, with no DFM execution, PMI lowering, or geometry/modeling behavior.
P1: pmi block v2 record-shaped dimensions/datums/basic controls
R1: validation/report integration
D1: demo/update packet for V2.0 Phase 1 workflow
diff --git a/fixtures/FirmamentV2/Language/valid/concept-applications-forge.valid.firmfixture b/fixtures/FirmamentV2/Language/valid/concept-applications-forge.valid.firmfixture
new file mode 100644
index 00000000..0de5b1a4
--- /dev/null
+++ b/fixtures/FirmamentV2/Language/valid/concept-applications-forge.valid.firmfixture
@@ -0,0 +1,34 @@
+// fixture: FirmamentV2 Forge concept-family applications
+// syntax-version: FirmamentV2
+// expected-parser: FirmamentV2Parser
+// expected-concepts: process<CNC>, hole<Countersink>
+
+model ConceptApplicationsForge {
+ units mm
+
+ let Process {
+ minimumToolRadius: length = 1.5mm
+ materialName: string = "Aluminum6061"
+ }
+
+ let MountingPattern {
+ holeDiameter: length = 6.0mm tol 0.05mm
+ countersinkDiameter: length = 10.0mm tol 0.10mm
+ }
+
+ solid part: Box {
+ size: [20, 20, 6]
+ }
+
+ manufacturing process<CNC> {
+ material: Process.materialName
+ minimumToolRadius: Process.minimumToolRadius
+ }
+
+ feature mountHole: hole<Countersink> {
+ target: part.region("mountHoleA")
+ diameter: MountingPattern.holeDiameter
+ countersinkDiameter: MountingPattern.countersinkDiameter
+ angle: 90deg
+ }
+}