TriggerReactor

TriggerReactor

24.6k Downloads

Proposals: Add "SWITCH", "MATCH" statements

Sayakie opened this issue ยท 1 comments

commented

NOTE: This is a draft issue.

๐Ÿ’ก Motivation

Since TriggerReactor does not have statements similar to switch and match, I would like to suggest these.
Of course, you can even use if-else to challenge dealing with switch and/or match too, but I think it'd better to implement this for readability.

๐Ÿ“œ Example

Switch:

IMPORT org.bukkit.GameMode

SWITCH player.getGameMode()
  CASE GameMode.CREATIVE
    #MESSAGE "You are in creative mode!"
    #BREAK
  CASE GameMode.SURVIVAL
    #MESSAGE "You are in survival mode!"
    #BREAK
  DEFAULT
    #MESSAGE "You are not in creative or survival mode!"
    #BREAK
ENDSWITCH

Match:

IMPORT org.bukkit.GameMode

playerGameModeInNumeric = MATCH player.getGameMode()
  CASE GameMode.CREATIVE -> 1
  CASE GameMode.SURVIVAL -> 0
  DEFAULT -> -1
ENDMATCH

โ“ Why switch and match?

TODO

โž• What kinds of reserved words we should attention?

[ Shared reserved words ]

  • CASE: Represent branch which satisfying the conditions.
  • DEFAULT: Represent default branch which not satisfied with any conditions.

[ Switch reserved words ]

  • SWITCH: Startpoint of switch-case.
  • ENDSWITCH: Endpoint of switch-case. All possible values should be covered, or be provide DEFAULT case if any no matching arm is evaluated.

[ Match reserved words ]

  • MATCH: Startpoint of match statement.
  • ENDMATCH: Endpoint of match statement. All possible values should be covered, or be provide DEFAULT case if any no matching arm is evaluated.

[ Match operators ]

  • ->: A special operator match statement only for. Due to it should be designed as simple as possible, and LAMBDA(=>) statement only consumes factor-like tokens.
commented

As Switch statement, see #186 for more context.