Proposals: Add "SWITCH", "MATCH" statements
Sayakie opened this issue ยท 1 comments
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, andLAMBDA(=>)
statement only consumes factor-like tokens.
As Switch
statement, see #186 for more context.