Skip to content

Commit

Permalink
Fix parsing errors on some semicolon-delimited generic type parameters
Browse files Browse the repository at this point in the history
Specifically, in routine implementation headers.
Previously, only comma-delimited type parameters were parsing correctly.
  • Loading branch information
Cirras committed Nov 22, 2024
1 parent 9063b07 commit dd36747
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Parsing errors on semicolon-delimited generic type parameters in routine implementation headers.
- Incorrect return types for `Length`, `High`, and `Low` on open/dynamic arrays depending on the
compiler version and toolchain.
- Name resolution failures on explicit references to default array properties with overloads on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,12 @@ genericConstraint : typeReference
| CONSTRUCTOR
;
genericArguments : '<' typeReferenceOrStringOrFile (',' typeReferenceOrStringOrFile)* '>'
-> ^(TkGenericArguments<GenericArgumentsNodeImpl> typeReferenceOrStringOrFile typeReferenceOrStringOrFile*)
-> ^(TkGenericArguments<GenericArgumentsNodeImpl> '<' typeReferenceOrStringOrFile (',' typeReferenceOrStringOrFile)* '>')
;
routineNameGenericArguments : '<' typeReferenceOrStringOrFile (commaOrSemicolon typeReferenceOrStringOrFile)* '>'
-> ^(TkGenericArguments<GenericArgumentsNodeImpl> '<' typeReferenceOrStringOrFile (commaOrSemicolon typeReferenceOrStringOrFile)* '>')
;
commaOrSemicolon : ',' | ';'
;

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -810,7 +815,7 @@ routineDeclarationName : (
)
-> ^(TkRoutineName<RoutineNameNodeImpl> $decl)
;
routineImplementationName : nameReference -> ^(TkRoutineName<RoutineNameNodeImpl> nameReference)
routineImplementationName : routineNameReference -> ^(TkRoutineName<RoutineNameNodeImpl> routineNameReference)
;
routineKey : PROCEDURE
| CONSTRUCTOR
Expand Down Expand Up @@ -1182,6 +1187,12 @@ simpleNameReference : ident
extendedNameReference : extendedIdent genericArguments? ('.' extendedNameReference)?
-> ^(TkNameReference<NameReferenceNodeImpl> extendedIdent genericArguments? ('.' extendedNameReference)?)
;
routineNameReference : ident routineNameGenericArguments? ('.' extendedRoutineNameReference)?
-> ^(TkNameReference<NameReferenceNodeImpl> ident routineNameGenericArguments? ('.' extendedRoutineNameReference)?)
;
extendedRoutineNameReference : extendedIdent routineNameGenericArguments? ('.' extendedRoutineNameReference)?
-> ^(TkNameReference<NameReferenceNodeImpl> extendedIdent routineNameGenericArguments? ('.' extendedRoutineNameReference)?)
;
extendedIdent : ident
| keywords -> ^({changeTokenType(TkIdentifier)})
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,9 @@ void testImmediatelyTerminatedComments() {
void testConditionalAsm() {
assertParsed("ConditionalAsm.pas");
}

@Test
void testSemicolonSeparatedGenericArguments() {
assertParsed("SemicolonSeparatedGenericArguments.pas");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
unit SemicolonSeparatedGenericArguments;

interface

implementation

type
TFoo = class
class procedure Bar<T; C>;
end;

class procedure TFoo.Bar<T; C>;
begin
// ...
end;

end.

0 comments on commit dd36747

Please # to comment.