From 15bf9224dee06e0a366fc6229330fdf5c5b72344 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Thu, 22 Feb 2024 18:41:59 +0100 Subject: [PATCH 1/4] feat(grammar): constraint lists for segments --- packages/safe-ds-lang/src/language/grammar/safe-ds.langium | 2 ++ .../declarations/segments/good-with constraint list.sdstest | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 packages/safe-ds-lang/tests/resources/grammar/declarations/segments/good-with constraint list.sdstest diff --git a/packages/safe-ds-lang/src/language/grammar/safe-ds.langium b/packages/safe-ds-lang/src/language/grammar/safe-ds.langium index a692319f8..1e134bedc 100644 --- a/packages/safe-ds-lang/src/language/grammar/safe-ds.langium +++ b/packages/safe-ds-lang/src/language/grammar/safe-ds.langium @@ -320,6 +320,7 @@ fragment SdsPipelineFragment: interface SdsSegment extends SdsCallable, SdsModuleMember { visibility?: string resultList?: SdsResultList + constraintList?: SdsConstraintList body: SdsBlock } @@ -329,6 +330,7 @@ fragment SdsSegmentFragment: name=ID parameterList=SdsParameterList resultList=SdsResultList? + constraintList=SdsConstraintList? body=SdsBlock ; diff --git a/packages/safe-ds-lang/tests/resources/grammar/declarations/segments/good-with constraint list.sdstest b/packages/safe-ds-lang/tests/resources/grammar/declarations/segments/good-with constraint list.sdstest new file mode 100644 index 000000000..028dd8438 --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/grammar/declarations/segments/good-with constraint list.sdstest @@ -0,0 +1,3 @@ +// $TEST$ no_syntax_error + +segment mySegment() where {} {} From 133a9fe06d3b1a37099cfa2a6e4b780cf44b3db3 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Thu, 22 Feb 2024 18:43:26 +0100 Subject: [PATCH 2/4] test(validation): constraint lists for segments --- .../unnecessary constraint list in segment/main.sdstest | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 packages/safe-ds-lang/tests/resources/validation/style/unnecessary constraint list in segment/main.sdstest diff --git a/packages/safe-ds-lang/tests/resources/validation/style/unnecessary constraint list in segment/main.sdstest b/packages/safe-ds-lang/tests/resources/validation/style/unnecessary constraint list in segment/main.sdstest new file mode 100644 index 000000000..45e9ca485 --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/validation/style/unnecessary constraint list in segment/main.sdstest @@ -0,0 +1,9 @@ +package tests.validation.style.unnecessaryConstraintListInSegment + +// $TEST$ info "This constraint list can be removed." +segment mySegment1() »where {}« {} + +// $TEST$ no info "This constraint list can be removed." +segment mySegment2(p: Int) »where { + p < 0 +}« {} From d86b3640f2dd64226cb65a7062775b6d79dffc33 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Thu, 22 Feb 2024 18:46:06 +0100 Subject: [PATCH 3/4] feat(formatter): constraint lists for segments --- packages/safe-ds-lang/src/language/lsp/safe-ds-formatter.ts | 1 + .../with constraint list.sdstest} | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) rename packages/safe-ds-lang/tests/resources/formatting/declarations/{functions/empty constraint list.sdstest => segments/with constraint list.sdstest} (53%) diff --git a/packages/safe-ds-lang/src/language/lsp/safe-ds-formatter.ts b/packages/safe-ds-lang/src/language/lsp/safe-ds-formatter.ts index b4b5112b7..3e184ebf5 100644 --- a/packages/safe-ds-lang/src/language/lsp/safe-ds-formatter.ts +++ b/packages/safe-ds-lang/src/language/lsp/safe-ds-formatter.ts @@ -484,6 +484,7 @@ export class SafeDsFormatter extends AbstractFormatter { formatter.property('name').prepend(oneSpace()); formatter.property('parameterList').prepend(noSpace()); formatter.property('resultList').prepend(oneSpace()); + formatter.property('constraintList').prepend(oneSpace()); formatter.property('body').prepend(oneSpace()); } diff --git a/packages/safe-ds-lang/tests/resources/formatting/declarations/functions/empty constraint list.sdstest b/packages/safe-ds-lang/tests/resources/formatting/declarations/segments/with constraint list.sdstest similarity index 53% rename from packages/safe-ds-lang/tests/resources/formatting/declarations/functions/empty constraint list.sdstest rename to packages/safe-ds-lang/tests/resources/formatting/declarations/segments/with constraint list.sdstest index a2d6bee0a..fc6c2ad76 100644 --- a/packages/safe-ds-lang/tests/resources/formatting/declarations/functions/empty constraint list.sdstest +++ b/packages/safe-ds-lang/tests/resources/formatting/declarations/segments/with constraint list.sdstest @@ -1,5 +1,5 @@ -fun myFunction ( ) where { } +segment mySegment ( ) where { } { } // ----------------------------------------------------------------------------- -fun myFunction() where {} +segment mySegment() where {} {} From f0a233524e6e0ace61a96aa882eb77cae384c2c6 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Thu, 22 Feb 2024 18:49:27 +0100 Subject: [PATCH 4/4] feat(scoping): constraint lists for segments --- .../scoping/safe-ds-scope-computation.ts | 2 ++ .../parameter bounds/in segment/main.sdstest | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 packages/safe-ds-lang/tests/resources/scoping/parameter bounds/in segment/main.sdstest diff --git a/packages/safe-ds-lang/src/language/scoping/safe-ds-scope-computation.ts b/packages/safe-ds-lang/src/language/scoping/safe-ds-scope-computation.ts index d55ce9dbe..68358ab96 100644 --- a/packages/safe-ds-lang/src/language/scoping/safe-ds-scope-computation.ts +++ b/packages/safe-ds-lang/src/language/scoping/safe-ds-scope-computation.ts @@ -130,6 +130,8 @@ export class SafeDsScopeComputation extends DefaultScopeComputation { this.addToScopesIfKeyIsDefined(scopes, containingCallable.constraintList, description); } else if (isSdsFunction(containingCallable)) { this.addToScopesIfKeyIsDefined(scopes, containingCallable.constraintList, description); + } else if (isSdsSegment(containingCallable)) { + this.addToScopesIfKeyIsDefined(scopes, containingCallable.constraintList, description); } } diff --git a/packages/safe-ds-lang/tests/resources/scoping/parameter bounds/in segment/main.sdstest b/packages/safe-ds-lang/tests/resources/scoping/parameter bounds/in segment/main.sdstest new file mode 100644 index 000000000..d426d269d --- /dev/null +++ b/packages/safe-ds-lang/tests/resources/scoping/parameter bounds/in segment/main.sdstest @@ -0,0 +1,27 @@ +package tests.scoping.parameterBounds.inSegment + +segment mySegment1(before: Int) {} + +segment mySegment2( + // $TEST$ target own + »own«: Int +) where { + // $TEST$ references own + »own« < 0, + + // $TEST$ unresolved + »before« < 0, + + // $TEST$ unresolved + »after« < 0, + + // $TEST$ unresolved + »notAParameter« < 0, + + // $TEST$ unresolved + »unresolved« < 0 +} {} + +segment mySegment3(after: Int) {} + +class notAParameter