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

[Proposal] Additional Kinds of Is Clauses #599

Open
AdamSpeight2008 opened this issue Jun 29, 2021 · 0 comments
Open

[Proposal] Additional Kinds of Is Clauses #599

AdamSpeight2008 opened this issue Jun 29, 2021 · 0 comments

Comments

@AdamSpeight2008
Copy link
Contributor

AdamSpeight2008 commented Jun 29, 2021

Proposal 1: Is/Isnot Type Clauses

I propose that we split out the Is typeand 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

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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant