Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Implement Firmament V2 let records
Yuechen Li16b368f149e1
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentV2ParserTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentV2ParserTests.csindex 7f0f5537..ba5971b2 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentV2ParserTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentV2ParserTests.cs@@ -927,6 +927,126 @@ model BadPmiDiameter {Assert.Contains(FirmamentV2Parser.LetDuplicateName, result.Diagnostics);}++ [Fact]+ public void FirmamentV2Parser_LetRecordGroups_ParseAndBindFields()+ {+ var result = FirmamentV2Parser.Parse(Source("Language/valid/let-record-groups.valid.firmfixture"));++ Assert.True(result.IsSuccess, string.Join(", ", result.Diagnostics));+ var record = Assert.Single(result.Document!.LetRecords!);+ Assert.Equal("MountingPattern", record.Name);+ Assert.Equal(6, record.Fields.Count);+ var bound = Assert.Single(result.Document!.BoundLetRecords!);+ Assert.Equal("MountingPattern", bound.Name);+ AssertLet(bound.Fields["holeDiameter"], "holeDiameter", FirmamentV2PrimitiveType.Length, 6.0d, "mm");+ AssertLet(bound.Fields["holeSpacingX"], "holeSpacingX", FirmamentV2PrimitiveType.Length, 80.0d, "mm");+ AssertLet(bound.Fields["holeSpacingY"], "holeSpacingY", FirmamentV2PrimitiveType.Length, 40.0d, "mm");+ AssertLet(bound.Fields["holeCount"], "holeCount", FirmamentV2PrimitiveType.Int, 4, null);+ AssertLet(bound.Fields["label"], "label", FirmamentV2PrimitiveType.String, "M6 mount group", null);+ AssertLet(bound.Fields["inspectionRequired"], "inspectionRequired", FirmamentV2PrimitiveType.Bool, true, null);+ }++ [Fact]+ public void FirmamentV2Parser_LetRecordGroups_AllowSameFieldNameAcrossRecords()+ {+ var result = FirmamentV2Parser.Parse("""+ model MultipleRecords {+ units mm+ solid base: Box { size: [10, 8, 6] }+ let MountingPattern { holeDiameter: length = 6.0mm }+ let InspectionPattern { holeDiameter: length = 6.1mm }+ }+ """);++ Assert.True(result.IsSuccess, string.Join(", ", result.Diagnostics));+ Assert.Equal(2, result.Document!.BoundLetRecords!.Count);+ }++ [Fact]+ public void FirmamentV2Parser_DottedReferenceScalarLet_ResolvesRecordFieldValue()+ {+ var result = FirmamentV2Parser.Parse("""+ model DottedReference {+ units mm+ solid base: Box { size: [10, 8, 6] }+ let MountingPattern { holeDiameter: length = 6.0mm }+ let exportedHoleDiameter: length = MountingPattern.holeDiameter+ }+ """);++ Assert.True(result.IsSuccess, string.Join(", ", result.Diagnostics));+ AssertLet(Assert.Single(result.Document!.BoundLets!), "exportedHoleDiameter", FirmamentV2PrimitiveType.Length, 6.0d, "mm");+ }++ [Theory]+ [InlineData("let MountingPattern { holeDiameter: length = 6.0mm holeDiameter: length = 7.0mm }", FirmamentV2Parser.LetInvalidLiteral)]+ [InlineData("let MountingPattern { holeDiameter: length = 6.0mm tol 0.05mm }", FirmamentV2Parser.LetInvalidLiteral)]+ [InlineData("let MountingPattern { radius: length = holeDiameter / 2 }", FirmamentV2Parser.LetLiteralOnly)]+ [InlineData("let Process { Tooling { minimumRadius: length = 1.5mm } }", FirmamentV2Parser.LetInvalidLiteral)]+ public void FirmamentV2Parser_LetRecordGroups_InvalidRecordBodiesAreDiagnostics(string recordSource, string expectedDiagnostic)+ {+ var result = FirmamentV2Parser.Parse($$"""+ model InvalidRecord {+ units mm+ solid base: Box { size: [10, 8, 6] }+ {{recordSource}}+ }+ """);++ Assert.False(result.IsSuccess);+ Assert.Contains(expectedDiagnostic, result.Diagnostics);+ }+++ [Fact]+ public void FirmamentV2Parser_LetRecordGroups_DuplicateFieldAndTopLevelNamesAreDiagnostics()+ {+ var duplicateField = FirmamentV2Parser.Parse("""+ model DuplicateRecordField {+ units mm+ solid base: Box { size: [10, 8, 6] }+ let MountingPattern {+ holeDiameter: length = 6.0mm+ holeDiameter: length = 7.0mm+ }+ }+ """);+ Assert.False(duplicateField.IsSuccess);+ Assert.Contains(FirmamentV2Parser.LetRecordDuplicateField, duplicateField.Diagnostics);++ var duplicateTopLevel = FirmamentV2Parser.Parse("""+ model DuplicateTopLevel {+ units mm+ solid base: Box { size: [10, 8, 6] }+ let holeDiameter: length = 6.0mm+ let holeDiameter { value: length = 6.0mm }+ }+ """);+ Assert.False(duplicateTopLevel.IsSuccess);+ Assert.Contains(FirmamentV2Parser.LetDuplicateName, duplicateTopLevel.Diagnostics);+ }++ [Theory]+ [InlineData("let exportedHoleDiameter: length = MissingPattern.holeDiameter", FirmamentV2Parser.LetReferenceUnknownRecord)]+ [InlineData("let MountingPattern { holeDiameter: length = 6.0mm }\nlet exportedHoleDiameter: length = MountingPattern.missingField", FirmamentV2Parser.LetReferenceUnknownField)]+ [InlineData("let holeDiameter: length = 6.0mm\nlet exported: length = holeDiameter.value", FirmamentV2Parser.LetReferenceNonRecord)]+ [InlineData("let MountingPattern { holeCount: int = 4 }\nlet exportedHoleDiameter: length = MountingPattern.holeCount", FirmamentV2Parser.LetTypeMismatch)]+ [InlineData("let MountingPattern { holeDiameter: length = 6.0mm }\nlet exportedHoleDiameter: length = MountingPattern", FirmamentV2Parser.LetReferenceRecordUsedAsValue)]+ public void FirmamentV2Parser_DottedReference_InvalidReferencesAreDiagnostics(string letSource, string expectedDiagnostic)+ {+ var result = FirmamentV2Parser.Parse($$"""+ model InvalidReference {+ units mm+ solid base: Box { size: [10, 8, 6] }+ {{letSource}}+ }+ """);++ Assert.False(result.IsSuccess);+ Assert.Contains(expectedDiagnostic, result.Diagnostics);+ }+private static void AssertLet(FirmamentV2BoundLet actual, string name, FirmamentV2PrimitiveType type, object value, string? unit){Assert.Equal(name, actual.Name);diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.csindex 997a9a6a..889f84c2 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)+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 FirmamentV2SolidBinding Solid => Solids[^1];public FirmamentV2SideHoleIntent? SideHoleIntent => ModifyBlocks?.SelectMany(m => m.Regions.Select(r =>@@ -14,8 +14,21 @@ public sealed record FirmamentV2Document(string ModelName, string Units, IReadOnpublic sealed record FirmamentV2SourceSpan(int Start, int Length);public enum FirmamentV2PrimitiveType { Int, Float, Length, Angle, String, Bool }public sealed record FirmamentV2LiteralValue(FirmamentV2PrimitiveType Type, object Value, double? NumericValue = null, string? Unit = null, string? Raw = null);-public sealed record FirmamentV2LetDeclaration(string Name, FirmamentV2PrimitiveType DeclaredType, FirmamentV2LiteralValue LiteralValue, FirmamentV2SourceSpan SourceSpan);+public abstract record FirmamentV2ValueExpression;+public sealed record FirmamentV2LiteralExpression(FirmamentV2LiteralValue Value) : FirmamentV2ValueExpression;+public sealed record FirmamentV2DottedReferenceExpression(string RecordName, string FieldName, string Source) : FirmamentV2ValueExpression;+public sealed record FirmamentV2IdentifierReferenceExpression(string Name, string Source) : FirmamentV2ValueExpression;+public sealed record FirmamentV2LetDeclaration(string Name, FirmamentV2PrimitiveType DeclaredType, FirmamentV2ValueExpression ValueExpression, FirmamentV2SourceSpan SourceSpan)+{+ public FirmamentV2LiteralValue LiteralValue => ValueExpression is FirmamentV2LiteralExpression literal ? literal.Value : throw new InvalidOperationException("Let value is not a literal.");+}+public sealed record FirmamentV2LetRecordDeclaration(string Name, IReadOnlyList<FirmamentV2LetRecordField> Fields, FirmamentV2SourceSpan SourceSpan);+public sealed record FirmamentV2LetRecordField(string Name, FirmamentV2PrimitiveType DeclaredType, FirmamentV2ValueExpression ValueExpression, FirmamentV2SourceSpan SourceSpan)+{+ public FirmamentV2LiteralValue LiteralValue => ValueExpression is FirmamentV2LiteralExpression literal ? literal.Value : throw new InvalidOperationException("Record field value is not a literal.");+}public sealed record FirmamentV2BoundLet(string Name, FirmamentV2PrimitiveType Type, FirmamentV2LiteralValue Value, FirmamentV2SourceSpan SourceSpan);+public sealed record FirmamentV2BoundLetRecord(string Name, IReadOnlyDictionary<string, FirmamentV2BoundLet> Fields, FirmamentV2SourceSpan SourceSpan);public sealed record FirmamentV2SolidBinding(string Name, string RecordType, FirmamentV2PrimitiveRecord Primitive, string? DerivedFrom = null, IReadOnlyDictionary<string, IReadOnlyList<double>>? Overrides = null){diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.csindex ce820025..e3e3696f 100644--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs@@ -45,6 +45,12 @@ public static class FirmamentV2Parserpublic const string LetInvalidLiteral = "firmament-v2-let-invalid-literal";public const string LetUnitMismatch = "firmament-v2-let-unit-mismatch";public const string LetLiteralOnly = "firmament-v2-let-literal-only";+ public const string LetRecordDuplicateName = "firmament-v2-let-record-duplicate-name";+ public const string LetRecordDuplicateField = "firmament-v2-let-record-duplicate-field";+ public const string LetReferenceUnknownRecord = "firmament-v2-let-reference-unknown-record";+ public const string LetReferenceUnknownField = "firmament-v2-let-reference-unknown-field";+ public const string LetReferenceNonRecord = "firmament-v2-let-reference-non-record";+ public const string LetReferenceRecordUsedAsValue = "firmament-v2-let-reference-record-used-as-value";public const string ModifyTargetUnresolved = "firmament-v2-modify-target-unresolved";public const string ModifyTargetNotSolid = "firmament-v2-modify-target-not-solid";@@ -119,6 +125,9 @@ public static class FirmamentV2Parserprivate 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" };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(@"\blet\s+(?<name>[A-Za-z_][A-Za-z0-9_]*)\s*\{", RegexOptions.CultureInvariant);+ 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);+ private static readonly Regex DottedReferenceRegex = new(@"^(?<record>[A-Za-z_][A-Za-z0-9_]*)\.(?<field>[A-Za-z_][A-Za-z0-9_]*)$", RegexOptions.CultureInvariant);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);@@ -203,7 +212,11 @@ public static class FirmamentV2Parser}}- var lets = ParseLets(source, byName.Keys, diagnostics);+ var letRecords = ParseLetRecords(source, byName.Keys, diagnostics);+ var topLevelNames = byName.Keys.Concat(letRecords.Select(r => r.Name));+ var lets = ParseLets(source, topLevelNames, diagnostics);+ var boundLetRecords = BindLetRecords(letRecords);+ var boundLets = BindLets(lets, boundLetRecords, byName.Keys, diagnostics);var modifyBlocks = ParseModifyBlocks(source, byName, diagnostics);var templates = ParseTemplates(source, diagnostics);@@ -213,13 +226,47 @@ public static class FirmamentV2ParserFirmamentV2Document? 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, lets.Select(l => new FirmamentV2BoundLet(l.Name, l.DeclaredType, l.LiteralValue, l.SourceSpan)).ToArray());+ document = new FirmamentV2Document(modelMatch.Groups["name"].Value, unitsMatch.Groups["units"].Value, solids, modifyBlocks, templates, pmi, recognizedRegions, replacements, lets, boundLets, letRecords, boundLetRecords);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 IReadOnlyList<FirmamentV2LetRecordDeclaration> ParseLetRecords(string source, IEnumerable<string> topLevelNames, List<string> diagnostics)+ {+ var records = new List<FirmamentV2LetRecordDeclaration>();+ var names = new HashSet<string>(topLevelNames, StringComparer.Ordinal);+ foreach (Match match in LetRecordHeaderRegex.Matches(source))+ {+ var name = match.Groups["name"].Value;+ var open = source.IndexOf('{', match.Index);+ var close = FindMatchingBrace(source, open);+ if (close < 0) { diagnostics.Add(UnsupportedConstruct); continue; }+ if (names.Contains(name) || ReservedWords.Contains(name)) { diagnostics.Add(LetRecordDuplicateName); continue; }+ names.Add(name);+ var fields = new List<FirmamentV2LetRecordField>();+ var fieldNames = new HashSet<string>(StringComparer.Ordinal);+ var body = source[(open + 1)..close];+ if (LetRecordHeaderRegex.IsMatch(body)) { diagnostics.Add(UnsupportedConstruct); continue; }+ foreach (var rawLine in body.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries))+ {+ var line = rawLine.Trim();+ if (line.Length == 0) continue;+ var fm = LetRecordFieldRegex.Match(line);+ if (!fm.Success) { diagnostics.Add(LetInvalidLiteral); continue; }+ var fieldName = fm.Groups["name"].Value;+ if (ReservedWords.Contains(fieldName) || !fieldNames.Add(fieldName)) { diagnostics.Add(LetRecordDuplicateField); continue; }+ if (!TryParseLetType(fm.Groups["type"].Value, out var type)) { diagnostics.Add(LetUnknownType); continue; }+ var expr = ParseLetValueExpression(type, fm.Groups["literal"].Value.Trim(), diagnostics);+ if (expr is FirmamentV2LiteralExpression) fields.Add(new(fieldName, type, expr, new FirmamentV2SourceSpan(open + 1 + body.IndexOf(rawLine, StringComparison.Ordinal), rawLine.Length)));+ else if (expr is not null) diagnostics.Add(LetLiteralOnly);+ }+ records.Add(new(name, fields, new FirmamentV2SourceSpan(match.Index, close - match.Index + 1)));+ }+ return records;+ }+private static IReadOnlyList<FirmamentV2LetDeclaration> ParseLets(string source, IEnumerable<string> topLevelNames, List<string> diagnostics){var lets = new List<FirmamentV2LetDeclaration>();@@ -231,7 +278,7 @@ public static class FirmamentV2Parsernames.Add(name);if (!TryParseLetType(match.Groups["type"].Value, out var type)) { diagnostics.Add(LetUnknownType); continue; }var literal = match.Groups["literal"].Value.Trim();- var value = ParseLetLiteral(type, literal, diagnostics);+ var value = ParseLetValueExpression(type, literal, diagnostics);if (value is not null) lets.Add(new FirmamentV2LetDeclaration(name, type, value, new FirmamentV2SourceSpan(match.Index, match.Length)));}return lets;@@ -252,6 +299,15 @@ public static class FirmamentV2Parserreturn text is "int" or "float" or "length" or "angle" or "string" or "bool";}+ private static FirmamentV2ValueExpression? ParseLetValueExpression(FirmamentV2PrimitiveType type, string literal, List<string> diagnostics)+ {+ var refMatch = DottedReferenceRegex.Match(literal);+ if (refMatch.Success) return new FirmamentV2DottedReferenceExpression(refMatch.Groups["record"].Value, refMatch.Groups["field"].Value, literal);+ if (Regex.IsMatch(literal, @"^[A-Za-z_][A-Za-z0-9_]*$", RegexOptions.CultureInvariant) && type is not FirmamentV2PrimitiveType.Bool) return new FirmamentV2IdentifierReferenceExpression(literal, literal);+ var value = ParseLetLiteral(type, literal, diagnostics);+ return value is null ? null : new FirmamentV2LiteralExpression(value);+ }+private static FirmamentV2LiteralValue? ParseLetLiteral(FirmamentV2PrimitiveType type, string literal, List<string> diagnostics){if (literal.Contains('/') || Regex.IsMatch(literal, @"^[A-Za-z_][A-Za-z0-9_]*\b", RegexOptions.CultureInvariant) && type is not FirmamentV2PrimitiveType.Bool)@@ -287,6 +343,32 @@ public static class FirmamentV2Parser}}+ private static IReadOnlyList<FirmamentV2BoundLetRecord> BindLetRecords(IReadOnlyList<FirmamentV2LetRecordDeclaration> records) =>+ records.Select(r => new FirmamentV2BoundLetRecord(r.Name, r.Fields.Where(f => f.ValueExpression is FirmamentV2LiteralExpression).Select(f => new FirmamentV2BoundLet(f.Name, f.DeclaredType, f.LiteralValue, f.SourceSpan)).ToDictionary(f => f.Name, StringComparer.Ordinal), r.SourceSpan)).ToArray();++ private static IReadOnlyList<FirmamentV2BoundLet> BindLets(IReadOnlyList<FirmamentV2LetDeclaration> lets, IReadOnlyList<FirmamentV2BoundLetRecord> records, IEnumerable<string> solidNames, List<string> diagnostics)+ {+ var recordMap = records.ToDictionary(r => r.Name, StringComparer.Ordinal);+ var scalarNames = new HashSet<string>(lets.Select(l => l.Name).Concat(solidNames), StringComparer.Ordinal);+ var bound = new List<FirmamentV2BoundLet>();+ foreach (var let in lets)+ {+ if (let.ValueExpression is FirmamentV2LiteralExpression literal) { bound.Add(new(let.Name, let.DeclaredType, literal.Value, let.SourceSpan)); continue; }+ if (let.ValueExpression is FirmamentV2IdentifierReferenceExpression identifier)+ {+ diagnostics.Add(recordMap.ContainsKey(identifier.Name) ? LetReferenceRecordUsedAsValue : LetLiteralOnly);+ continue;+ }+ var reference = (FirmamentV2DottedReferenceExpression)let.ValueExpression;+ if (scalarNames.Contains(reference.RecordName)) { diagnostics.Add(LetReferenceNonRecord); continue; }+ if (!recordMap.TryGetValue(reference.RecordName, out var record)) { diagnostics.Add(LetReferenceUnknownRecord); continue; }+ if (!record.Fields.TryGetValue(reference.FieldName, out var field)) { diagnostics.Add(LetReferenceUnknownField); continue; }+ if (field.Type != let.DeclaredType) { diagnostics.Add(LetTypeMismatch); continue; }+ bound.Add(new(let.Name, let.DeclaredType, field.Value, let.SourceSpan));+ }+ return bound;+ }+private static FirmamentV2SolidBinding? ParseDirect(string name, string recordType, string body, List<string> diagnostics, string? sourceDirectory){if (string.Equals(recordType, "Box", StringComparison.Ordinal))@@ -394,7 +476,7 @@ public static class FirmamentV2Parserreturn 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 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 RecognitionEvidenceRadiusInvalid or RecognitionEvidenceSurfaceFamilyUnknown or RecognitionEvidenceAxisInvalid or SemanticProposalKindMismatch or SemanticProposalRadiusInvalid or SemanticProposalTargetUnresolved or SemanticProposalEndUnsupported;private static IReadOnlyList<FirmamentV2Exposure> ParseExposures(string body, List<string> diagnostics){diff --git a/docs/implementation/firmament-v2-l2-let-record-groups.md b/docs/implementation/firmament-v2-l2-let-record-groups.mdnew file mode 100644index 00000000..61fa1c8b--- /dev/null+++ b/docs/implementation/firmament-v2-l2-let-record-groups.md@@ -0,0 +1,66 @@+# Firmament V2 L2 grouped `let` records++Milestone: **V2-PHASE1-L2**++L2 implements the next narrow Firmament V2 language slice after primitive typed `let` declarations. The implementation remains a pure manufacturing-intent data feature and does not broaden Phase 1 into CAD modeling or executable scripting.++## Supported syntax++Top-level grouped `let` records are accepted with one level of primitive typed fields:++```firmament+let MountingPattern {+ holeDiameter: length = 6.0mm+ holeSpacingX: length = 80.0mm+ holeSpacingY: length = 40.0mm+ holeCount: int = 4+ label: string = "M6 mount group"+ inspectionRequired: bool = true+}+```++Supported field types are the L1 primitives: `int`, `float`, `length`, `angle`, `string`, and `bool`.++## Model and binding++The parser exposes record declarations as `FirmamentV2LetRecordDeclaration` values containing `FirmamentV2LetRecordField` entries. The bound document exposes `FirmamentV2BoundLetRecord` values whose fields are bound `FirmamentV2BoundLet` entries keyed by field name.++Scalar L1 lets remain exposed through `Lets` and `BoundLets`; L2 records are exposed through `LetRecords` and `BoundLetRecords`.++## Dotted references++A scalar `let` value may be exactly a dotted reference to a grouped-let field:++```firmament+let MountingPattern {+ holeDiameter: length = 6.0mm+}++let exportedHoleDiameter: length = MountingPattern.holeDiameter+```++The reference resolves to the referenced field's already-bound primitive value. The scalar declaration's type must match the referenced field type. L2 does not add arithmetic or reference chaining; this is only the minimal binder path needed to establish record-field references for later milestones.++## Deterministic diagnostics++L2 adds deterministic diagnostics for grouped-let and dotted-reference failures:++- `firmament-v2-let-record-duplicate-name`+- `firmament-v2-let-record-duplicate-field`+- `firmament-v2-let-reference-unknown-record`+- `firmament-v2-let-reference-unknown-field`+- `firmament-v2-let-reference-non-record`+- `firmament-v2-let-reference-record-used-as-value`++Existing L1 diagnostics continue to apply for unknown primitive types, primitive type mismatches, invalid literals, unit mismatches, duplicate scalar lets, and non-literal arithmetic attempts.++## Explicit non-scope++L2 deliberately does not implement:++- arithmetic expressions;+- tolerance syntax;+- nested records;+- top-level dotted field assignment sugar such as `let Group.field: length = 1.0mm`;+- PMI or Forge wiring for records;+- conditionals, loops, user functions, mutation, hidden behavior, or any Turing-complete language feature.diff --git a/docs/v2/aetheris-v2-phase1-scope-contract.md b/docs/v2/aetheris-v2-phase1-scope-contract.mdindex 87c6c7da..6b200139 100644--- a/docs/v2/aetheris-v2-phase1-scope-contract.md+++ b/docs/v2/aetheris-v2-phase1-scope-contract.md@@ -94,6 +94,13 @@ Hard doctrine:This doctrine exists because Firmament files must be auditable. Humans, LLMs, suppliers, manufacturing engineers, and inspection systems must be able to reason about the file without executing hidden behavior. Manufacturing intent must remain visible as data, not concealed behind logic, state, or control flow.+## Phase 1 language status note++- L1 primitive immutable typed `let` declarations are implemented.+- L2 grouped one-level `let` records and exact dotted record-field references are implemented for parser/model/binder exposure.+- L3 arithmetic remains deferred.+- L4 tolerance syntax remains deferred.+## 5. `let` declarations and typed valuesFirmament V2.0 should use `let`, not `param`, for named values.diff --git a/fixtures/FirmamentV2/Language/valid/let-record-groups.valid.firmfixture b/fixtures/FirmamentV2/Language/valid/let-record-groups.valid.firmfixturenew file mode 100644index 00000000..e148b7b0--- /dev/null+++ b/fixtures/FirmamentV2/Language/valid/let-record-groups.valid.firmfixture@@ -0,0 +1,16 @@+// syntax-version: FirmamentV2+// implementation: parser-backed+// expected-stage: parser+model LetRecordGroups {+ units mm+ solid base: Box { size: [10, 8, 6] }++ let MountingPattern {+ holeDiameter: length = 6.0mm+ holeSpacingX: length = 80.0mm+ holeSpacingY: length = 40.0mm+ holeCount: int = 4+ label: string = "M6 mount group"+ inspectionRequired: bool = true+ }+}