SkyTemple / ExplorerScript

ExplorerScript and SSBScript: Script languages for decompiled SSB (Pokémon Mystery Dungeon Explorers of Sky)
MIT License
16 stars 6 forks source link

New syntax for targeted routines #50

Closed theCapypara closed 1 month ago

theCapypara commented 2 months ago

Summary

Replace the signature of targeted routines to be def INT for ENTITY ID instead of def INT for_ENTITY(ID) (where ENTITY is literally "object"/"actor"/"performer"). Keep and deprecate the old syntax.

Motivation

This syntax is much more consistent with the rest of ExplorerScript and doesn't require extra bespoke keywords (for_actor, etc.)

Examples

def 0 for actor FOOBAR {}

Example of the new syntax.

def 0 for_actor(FOOBAR) {}

Equivalent old syntax.

Language Changes

Parser and Lexer Changes

Change the parser as such:

for_target_def: DEF INTEGER for_target_def_target OPEN_PAREN? integer_like CLOSE_PAREN? func_suite;
for_target_def_target
  : (FOR IDENTIFIER)
  | (FOR_TARGET)  // DEPRECATED, use syntax above instead.
  ;

Note that the parenthesis would now be optional.

Since this will also need to be added to SsbScript, CTX_TYPE, ACTOR, OBJECT and PERFORMER could no longer be tokens, sice this would conflict with the object and performer operations. In this case CTX_TYPE would need to be replaced with IDENTIFIER wherever used and code needs to be adjusted in the compiler to handle this. FOR needs to also become a keyword in SsbScript.

Behaviour

No changes.

Compiler Implementation

Compiler Interface Changes

No changes.

Decompiler Changes

The decompiler should use this new syntax.

How to teach

Update the documentation to only mention this new syntax.

Alternatives

Backwards compatibility

The old syntax would still work but be deprecated and eventually removed.