[Proposal] Additional Kinds of Is Clauses
- Dominant language
- No language data
- Stars
- 328
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
Proposal 1: Is/Isnot Type Clauses
---------
I propose that we split out the `Is type`and `IsNot type` part from the `TypeOf expr Is type`, into it's own clause (`IsTypeClause`).
By doing this we'd gain additional forms, that are applicable to both `TypeOf expression` and a new `Select Case Clause`.
`IsTypeClause ::= ("Is / IsNot") TypeSyntax ;; `
Includee an optional declaration.
`IsTypeClause ::= ("Is" / "IsNot") (ident "As")? TypeSyntax ;; `
Extend the target type to include multiple target types.
`IsTypeClause ::= ("Is" / "IsNot") (ident "As")? (TypeArgumentListSyntax / TypeSyntax)`
Basic Syntax
----
```
Syntax IsTypeClause
Inherits ClauseSyntax
With
.KindOfIsKeyword As KeywordSyntax (Where .Kind IsOf {SyntaxKind.IsKeyword, SyntaxKind.IsNotKeyword})
.DeclarationAs As Optional(Of DeclarationAsClause)
.KIndOfTargetType As Union(Of TypeArgumentListSyntax, TypeSyntax)
End With
End Syntax
Syntax DeclarationAsClause
Inherits ClauseSyntax
With
.Declaration As IdentifierNameSyntax
.AsKeyword As KeywordSyntax (Where .Kind = SyntaxKind.AsKeyword)
End With
End Syntax
Syntax TypeOfExpression
Inherits Expression
With
.TypeOfKeyword As Keyword (Where .Kind = SyntaxKind.TypeOfKeyword)
.Operad As ExpressionSyntax
.IsTypeClause As IsTypeClauseSyntax
End With
End Syntax
```
KindOfIsKeyword | DeclarationAsClause | KindOfTarget | result
--- | ---- | ---- | ---
`Is` | | Type | Valid
`Is` | `id As` | Type | Valid
`Is` | | `(Of T0 .., Tn)` | Valid
`Is` | `id As ` | `(Of T0 .., Tn) ` | Error: DeclarationAsClause can not be used with TypeArgumentListSyntax.
`IsNot` | | Type | Valid
`IsNot` | `id As` | Type | Error: DeclarationAsClause can not be used with `IsNot`.
`IsNot` | | `(Of T0..,Tn)` | Valid
`IsNot` | `id As` | `(Of T0..,Tn)` | Error: DeclarationAsClause can not be used with TypeArgumentListSyntax.
Error: DeclarationAsClause can not be used with `IsNot`.
Examples
-------
```vbnet
Select Case obj
Case Is s As String
Select Case s
Case Is Nothing
Case "A"
Case "B"
Case Else
End Select
Case IsNot Double
Case Else
End Select
```
```vbnet
If (TypeOf obj Is s As String) AndAlso (String.IsNullOrWhiteSpace(s) = False) Then
Else
End If
```
-------------
Proposal 2: Is / IsNot Relational Clauses
--------
This is would be a natural extension to an existing clause, by the use of the keyword `IsNot` as well as `Is` in relational clauses.
```
ComparisionKind ::= ("<" / "<=" / "<>" / "=" / ">=" / ">") ;;
RelationalClauseSyntax :: ("Is" / "IsNot")? ComparisionKind Expression ;; ` Defaults to `Is` if not present, to preserve existing meaning
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.