Skip to content

Commit

Permalink
feat: remove type arguments from calls (#581)
Browse files Browse the repository at this point in the history
### 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.
  • Loading branch information
lars-reimann authored Sep 29, 2023
1 parent 491d7b0 commit 3e88f02
Show file tree
Hide file tree
Showing 64 changed files with 9 additions and 595 deletions.
1 change: 0 additions & 1 deletion src/language/formatting/safe-ds-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,6 @@ export class SafeDsFormatter extends AbstractFormatter {
private formatSdsCall(node: ast.SdsCall) {
const formatter = this.getNodeFormatter(node);

formatter.property('typeArgumentList').prepend(noSpace());
formatter.property('argumentList').prepend(noSpace());
}

Expand Down
45 changes: 6 additions & 39 deletions src/language/grammar/safe-ds.langium
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ SdsComparisonExpression returns SdsExpression:
;

SdsComparisonOperator returns string:
LESS_THAN | '<=' | '>=' | '>'
'<' | '<=' | '>=' | '>'
;

SdsAdditiveExpression returns SdsExpression:
Expand Down Expand Up @@ -644,9 +644,7 @@ interface SdsChainedExpression extends SdsExpression {
receiver: SdsExpression
}

interface SdsCall extends SdsAbstractCall, SdsChainedExpression {
typeArgumentList?: SdsTypeArgumentList
}
interface SdsCall extends SdsAbstractCall, SdsChainedExpression {}

interface SdsIndexedAccess extends SdsChainedExpression {
index: SdsExpression
Expand All @@ -661,7 +659,6 @@ SdsChainedExpression returns SdsExpression:
SdsPrimaryExpression
(
{SdsCall.receiver=current}
typeArgumentList=SdsCallTypeArgumentList?
argumentList=SdsCallArgumentList

| {SdsIndexedAccess.receiver=current}
Expand Down Expand Up @@ -856,7 +853,7 @@ interface SdsLiteralList extends SdsObject {

SdsLiteralList returns SdsLiteralList:
{SdsLiteralList}
(LESS_THAN | CALL_TYPE_ARGUMENT_LIST_START)
'<'
(
literals+=SdsLiteral
(',' literals+=SdsLiteral)*
Expand Down Expand Up @@ -887,7 +884,7 @@ SdsUnionType returns SdsUnionType:

SdsUnionTypeArgumentList returns SdsTypeArgumentList:
{SdsTypeArgumentList}
(LESS_THAN | CALL_TYPE_ARGUMENT_LIST_START)
'<'
(
typeArguments+=SdsUnionTypeArgument
(',' typeArguments+=SdsUnionTypeArgument)*
Expand All @@ -914,7 +911,7 @@ interface SdsTypeParameterList extends SdsObject {

SdsTypeParameterList returns SdsTypeParameterList:
{SdsTypeParameterList}
(LESS_THAN | CALL_TYPE_ARGUMENT_LIST_START)
'<'
(
typeParameters+=SdsTypeParameter
(',' typeParameters+=SdsTypeParameter)*
Expand Down Expand Up @@ -943,14 +940,7 @@ interface SdsTypeArgumentList extends SdsObject {

SdsTypeArgumentList returns SdsTypeArgumentList:
{SdsTypeArgumentList}
(LESS_THAN | CALL_TYPE_ARGUMENT_LIST_START)
(typeArguments+=SdsTypeArgument (',' typeArguments+=SdsTypeArgument)* ','? )?
'>'
;

SdsCallTypeArgumentList returns SdsTypeArgumentList:
{SdsTypeArgumentList}
CALL_TYPE_ARGUMENT_LIST_START
'<'
(typeArguments+=SdsTypeArgument (',' typeArguments+=SdsTypeArgument)* ','? )?
'>'
;
Expand Down Expand Up @@ -1040,29 +1030,6 @@ terminal TEMPLATE_STRING_START returns string: STRING_START STRING_TEXT* TEMPLAT
terminal TEMPLATE_STRING_INNER returns string: TEMPLATE_EXPRESSION_END STRING_TEXT* TEMPLATE_EXPRESSION_START;
terminal TEMPLATE_STRING_END returns string: TEMPLATE_EXPRESSION_END STRING_TEXT* STRING_END;

// Resolves the ambiguity between the less than operator (<) and the start of a type argument list of a call (<).
// See also: https://github.com/langium/langium/discussions/921#discussioncomment-4943180
terminal CALL_TYPE_ARGUMENT_LIST_START:
'<'
(?=
/[\s»«]*/
( '*' // Star projection as positional type argument
| 'in' // Contravariant type projection as positional type argument
| 'out' // Covariant type projection as positional type argument
| 'literal' // Invariant literal type as positional type argument
| 'union' // Invariant union type as positional type argument
| '>' // Empty type argument list
| ID /[\s»«]*/
( '=' // Named type argument
| ('.' /[\s»«]*/ ID /[\s»«]*/)* (',' | '>') // Invariant type projection as positional type argument
)
)
)
;
terminal LESS_THAN:
'<'
;

hidden terminal ML_COMMENT: /\/\*[\s\S]*?\*\//;
hidden terminal SL_COMMENT: /\/\/[^\n\r]*/;
hidden terminal TEST_MARKER: /[»«]/;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pipeline myPipeline {
f < Int > ( );
f ( 1 , b = 2 );
}

// -----------------------------------------------------------------------------

pipeline myPipeline {
f<Int>();
f(1, b = 2);
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 3e88f02

Please sign in to comment.