diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e8f96424..faf903bab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **API:** `RaiseStatementNode::getRaiseLocation` method. - **API:** `VariableNameDeclaration::isExceptItem` method. +### Fixed + +- Parsing errors on attributes preceding visibility sections. +- Parsing errors on attributes preceding `var` sections in type bodies. + ## [1.21.0] - 2026-09-04 ### Added diff --git a/delphi-frontend/src/main/antlr3/au/com/integradev/delphi/antlr/Delphi.g b/delphi-frontend/src/main/antlr3/au/com/integradev/delphi/antlr/Delphi.g index b9f8ea956..5053f75ca 100644 --- a/delphi-frontend/src/main/antlr3/au/com/integradev/delphi/antlr/Delphi.g +++ b/delphi-frontend/src/main/antlr3/au/com/integradev/delphi/antlr/Delphi.g @@ -696,6 +696,7 @@ visibilitySectionItem : fieldSection | property | constSection | innerTypeSection + | attributeList ; fieldSectionKey : VAR | THREADVAR diff --git a/delphi-frontend/src/test/java/au/com/integradev/delphi/antlr/GrammarTest.java b/delphi-frontend/src/test/java/au/com/integradev/delphi/antlr/GrammarTest.java index cceac6062..e4bcb2106 100644 --- a/delphi-frontend/src/test/java/au/com/integradev/delphi/antlr/GrammarTest.java +++ b/delphi-frontend/src/test/java/au/com/integradev/delphi/antlr/GrammarTest.java @@ -91,6 +91,11 @@ void testAttributesUnit() { assertParsed("AttributesUnit.pas"); } + @Test + void testAttributesOnVisibilitySections() { + assertParsed("AttributesOnVisibilitySections.pas"); + } + @Test void testAttributesProgram() { assertParsed("AttributesProgram.dpr"); diff --git a/delphi-frontend/src/test/resources/au/com/integradev/delphi/grammar/AttributesOnVisibilitySections.pas b/delphi-frontend/src/test/resources/au/com/integradev/delphi/grammar/AttributesOnVisibilitySections.pas new file mode 100644 index 000000000..90c79595d --- /dev/null +++ b/delphi-frontend/src/test/resources/au/com/integradev/delphi/grammar/AttributesOnVisibilitySections.pas @@ -0,0 +1,37 @@ +unit AttributesOnVisibilitySections; + +interface + +type + TFoo = class(TObject) + [xyz] + private FBar: String; + + [xyz] + private var FBaz: String; + + [xyz] + [assembly: xyz] + private + [xyz] + var + [xyz] + FFlarp: String; + FFlimflam: String; + end; + + TBar = class(TObject) + [xyz] + private + [xyz] + var + [xyz] + + public + var + FBar: String; + end; + +implementation + +end.