Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: constraints for segments #911

Merged
merged 4 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/safe-ds-lang/src/language/grammar/safe-ds.langium
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ fragment SdsPipelineFragment:
interface SdsSegment extends SdsCallable, SdsModuleMember {
visibility?: string
resultList?: SdsResultList
constraintList?: SdsConstraintList
body: SdsBlock
}

Expand All @@ -329,6 +330,7 @@ fragment SdsSegmentFragment:
name=ID
parameterList=SdsParameterList
resultList=SdsResultList?
constraintList=SdsConstraintList?
body=SdsBlock
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fun myFunction ( ) where { }
segment mySegment ( ) where { } { }

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

fun myFunction() where {}
segment mySegment() where {} {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// $TEST$ no_syntax_error

segment mySegment() where {} {}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
}« {}