Skip to content

Commit 3e88f02

Browse files
authored
feat: remove type arguments from calls (#581)
### Summary of Changes Calls no longer have a type argument list. Since all objects we expose are assumed to be immutable, there is no reason to specify the type arguments of a call. We can always infer them from the parameters or set them to `Any`/`Nothing` if the parameters don't provide enough information. An added benefit of this is that our grammar now only requires a finite lookahead.
1 parent 491d7b0 commit 3e88f02

File tree

64 files changed

+9
-595
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+9
-595
lines changed

src/language/formatting/safe-ds-formatter.ts

-1
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,6 @@ export class SafeDsFormatter extends AbstractFormatter {
678678
private formatSdsCall(node: ast.SdsCall) {
679679
const formatter = this.getNodeFormatter(node);
680680

681-
formatter.property('typeArgumentList').prepend(noSpace());
682681
formatter.property('argumentList').prepend(noSpace());
683682
}
684683

src/language/grammar/safe-ds.langium

+6-39
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ SdsComparisonExpression returns SdsExpression:
597597
;
598598

599599
SdsComparisonOperator returns string:
600-
LESS_THAN | '<=' | '>=' | '>'
600+
'<' | '<=' | '>=' | '>'
601601
;
602602

603603
SdsAdditiveExpression returns SdsExpression:
@@ -644,9 +644,7 @@ interface SdsChainedExpression extends SdsExpression {
644644
receiver: SdsExpression
645645
}
646646

647-
interface SdsCall extends SdsAbstractCall, SdsChainedExpression {
648-
typeArgumentList?: SdsTypeArgumentList
649-
}
647+
interface SdsCall extends SdsAbstractCall, SdsChainedExpression {}
650648

651649
interface SdsIndexedAccess extends SdsChainedExpression {
652650
index: SdsExpression
@@ -661,7 +659,6 @@ SdsChainedExpression returns SdsExpression:
661659
SdsPrimaryExpression
662660
(
663661
{SdsCall.receiver=current}
664-
typeArgumentList=SdsCallTypeArgumentList?
665662
argumentList=SdsCallArgumentList
666663

667664
| {SdsIndexedAccess.receiver=current}
@@ -856,7 +853,7 @@ interface SdsLiteralList extends SdsObject {
856853

857854
SdsLiteralList returns SdsLiteralList:
858855
{SdsLiteralList}
859-
(LESS_THAN | CALL_TYPE_ARGUMENT_LIST_START)
856+
'<'
860857
(
861858
literals+=SdsLiteral
862859
(',' literals+=SdsLiteral)*
@@ -887,7 +884,7 @@ SdsUnionType returns SdsUnionType:
887884

888885
SdsUnionTypeArgumentList returns SdsTypeArgumentList:
889886
{SdsTypeArgumentList}
890-
(LESS_THAN | CALL_TYPE_ARGUMENT_LIST_START)
887+
'<'
891888
(
892889
typeArguments+=SdsUnionTypeArgument
893890
(',' typeArguments+=SdsUnionTypeArgument)*
@@ -914,7 +911,7 @@ interface SdsTypeParameterList extends SdsObject {
914911

915912
SdsTypeParameterList returns SdsTypeParameterList:
916913
{SdsTypeParameterList}
917-
(LESS_THAN | CALL_TYPE_ARGUMENT_LIST_START)
914+
'<'
918915
(
919916
typeParameters+=SdsTypeParameter
920917
(',' typeParameters+=SdsTypeParameter)*
@@ -943,14 +940,7 @@ interface SdsTypeArgumentList extends SdsObject {
943940

944941
SdsTypeArgumentList returns SdsTypeArgumentList:
945942
{SdsTypeArgumentList}
946-
(LESS_THAN | CALL_TYPE_ARGUMENT_LIST_START)
947-
(typeArguments+=SdsTypeArgument (',' typeArguments+=SdsTypeArgument)* ','? )?
948-
'>'
949-
;
950-
951-
SdsCallTypeArgumentList returns SdsTypeArgumentList:
952-
{SdsTypeArgumentList}
953-
CALL_TYPE_ARGUMENT_LIST_START
943+
'<'
954944
(typeArguments+=SdsTypeArgument (',' typeArguments+=SdsTypeArgument)* ','? )?
955945
'>'
956946
;
@@ -1040,29 +1030,6 @@ terminal TEMPLATE_STRING_START returns string: STRING_START STRING_TEXT* TEMPLAT
10401030
terminal TEMPLATE_STRING_INNER returns string: TEMPLATE_EXPRESSION_END STRING_TEXT* TEMPLATE_EXPRESSION_START;
10411031
terminal TEMPLATE_STRING_END returns string: TEMPLATE_EXPRESSION_END STRING_TEXT* STRING_END;
10421032

1043-
// Resolves the ambiguity between the less than operator (<) and the start of a type argument list of a call (<).
1044-
// See also: https://github.com/langium/langium/discussions/921#discussioncomment-4943180
1045-
terminal CALL_TYPE_ARGUMENT_LIST_START:
1046-
'<'
1047-
(?=
1048-
/[\s»«]*/
1049-
( '*' // Star projection as positional type argument
1050-
| 'in' // Contravariant type projection as positional type argument
1051-
| 'out' // Covariant type projection as positional type argument
1052-
| 'literal' // Invariant literal type as positional type argument
1053-
| 'union' // Invariant union type as positional type argument
1054-
| '>' // Empty type argument list
1055-
| ID /[\s»«]*/
1056-
( '=' // Named type argument
1057-
| ('.' /[\s»«]*/ ID /[\s»«]*/)* (',' | '>') // Invariant type projection as positional type argument
1058-
)
1059-
)
1060-
)
1061-
;
1062-
terminal LESS_THAN:
1063-
'<'
1064-
;
1065-
10661033
hidden terminal ML_COMMENT: /\/\*[\s\S]*?\*\//;
10671034
hidden terminal SL_COMMENT: /\/\/[^\n\r]*/;
10681035
hidden terminal TEST_MARKER: /[»«]/;

tests/resources/formatting/declarations/annotation calls/complex argument list (unchanged).sdstest

-11
This file was deleted.

tests/resources/formatting/declarations/annotations/complex parameter list (unchanged).sdstest

-11
This file was deleted.

tests/resources/formatting/declarations/classes/complex parameter list (unchanged).sdstest

-11
This file was deleted.

tests/resources/formatting/declarations/classes/long type parameter list (unchanged).sdstest

-15
This file was deleted.

tests/resources/formatting/declarations/enums/variants/complex parameter list (unchanged).sdstest

-15
This file was deleted.

tests/resources/formatting/declarations/enums/variants/long type parameter list (unchanged).sdstest

-19
This file was deleted.

tests/resources/formatting/declarations/functions/complex parameter list (unchanged).sdstest

-11
This file was deleted.

tests/resources/formatting/declarations/functions/complex result list (unchanged).sdstest

-11
This file was deleted.

tests/resources/formatting/declarations/functions/long type parameter list (unchanged).sdstest

-15
This file was deleted.

tests/resources/formatting/declarations/segments/complex parameter list (unchanged).sdstest

-11
This file was deleted.

tests/resources/formatting/declarations/segments/complex result list (unchanged).sdstest

-11
This file was deleted.

tests/resources/formatting/expressions/block lambdas/complex parameter list (unchanged).sdstest

-15
This file was deleted.

tests/resources/formatting/expressions/calls/complex argument list (unchanged).sdstest

-15
This file was deleted.

tests/resources/formatting/expressions/calls/complex call.sdstest

-9
This file was deleted.

tests/resources/formatting/expressions/calls/contravariant type argument.sdstest

-9
This file was deleted.

tests/resources/formatting/expressions/calls/covariant type argument.sdstest

-9
This file was deleted.

tests/resources/formatting/expressions/calls/empty type argument list and no arguments.sdstest

-9
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
pipeline myPipeline {
2-
f < Int > ( );
2+
f ( 1 , b = 2 );
33
}
44

55
// -----------------------------------------------------------------------------
66

77
pipeline myPipeline {
8-
f<Int>();
8+
f(1, b = 2);
99
}

tests/resources/formatting/expressions/calls/named type argument.sdstest

-9
This file was deleted.

tests/resources/formatting/expressions/calls/nested type argument lists (named type argument).sdstest

-9
This file was deleted.

0 commit comments

Comments
 (0)