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

When Expressions #307

Closed
AdamSpeight2008 opened this issue May 30, 2018 · 3 comments
Closed

When Expressions #307

AdamSpeight2008 opened this issue May 30, 2018 · 3 comments
Labels
LDM Considering LDM has reviewed and we think this has merit

Comments

@AdamSpeight2008
Copy link
Contributor

When Expressions on Case Clause Statements

Within the language we are able to add a condition to a catch handler.

Catch ex As Expection When Retries < 3

I think we should also be able extend clause statement with a when expression.
So the body of the case it executed when both clause matches and the when expression evaluates to true.

Syntax

Select Case expr
  Case clause When expression
  Case Else
End Select

Syntax Node Layout

Syntax WhenExpression
  WhenKeyword  As WhenKeywordToken
  Expression   As ExpressionSyntax
End Syntax

The feature would also be useful, combined with #304
Eg

Select TypeOf obj
  Case Byte  Out value When value > 0
    '
  Case Int16 Out value When value > 0
  Case Int32 Out value When value < 0
  Case Else When
  Case Else
End Select
@bandleader
Copy link

100%, but I think this is anyway being considered as part of pattern matching.

@KathleenDollard
Copy link
Contributor

Seems reasonable.

@KathleenDollard KathleenDollard added the LDM Considering LDM has reviewed and we think this has merit label Aug 1, 2018
@AdamSpeight2008
Copy link
Contributor Author

@KathleenDollard An example of a parsing a digit of a some specific number base using Case ... When ....

Enum Base
  None = 0
  BIN  = 2
  OCT  = 8
  DEC  = 10
  HEX  = 16
End Enum

Function TryParse_Digit(OfBase As Base, Here As Int32, <Out> Output As Digit) As Boolean
  ' Presumption: The parsing is going to fail, unless proven otherwise.
  ' So set default value for output to nothing.
  Output = Nothing
  Select Case Ch When TryGet(Here, Out Ch)
    Case "0"c To "1"c When OfBase >= Base.BIN : Output = New Digit( Here, Ch, OfBase )
    Case "2"c To "7"c When OfBase >= Base.OCT : Output = New Digit( Here, Ch, OfBase )
    Case "8"c To "9"c When OfBase >= Base.DEC : Output = New Digit( Here, Ch, OfBase )
    Case "A"c To "F"c When OfBase >= Base.Hex : Output = New Digit( Here, Ch, OfBase )
    Case "a"c To "f"c When OfBase >= Base.Hex : Output = New Digit( Here, Ch, OfBase )
  End Select
  Return (Output IsNot Nothing)
End Function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LDM Considering LDM has reviewed and we think this has merit
Projects
None yet
Development

No branches or pull requests

3 participants