SkyTemple / ExplorerScript

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

Replacing the macro variable prefix with % #53

Closed theCapypara closed 3 months ago

theCapypara commented 3 months ago

Summary

Replace the prefix for macro variables with % instead of $. If possible: still allow $ as a prefix for backwards compatibility but deprecate that.

Motivation

In the context of SkyTemple, SkyTemple's system-defined constants for game variables are already prefixed with a $. This can lead to confusion, since these are wildly different things. This also requires a big section in the manual to explain this at the moment.

Examples

macro foo(%bar) {
   myOperation(%bar);
}

This would be the new syntax.

macro foo($bar) {
   myOperation($bar);
}

Old syntax (equivalent).

Language Changes

Parser and Lexer Changes

VARIABLE needs to be changed to use this new prefix. If keeping backwards compatibility, the old prefix must still be allowed. If not, then IDENTIFIER must be changed to allow a $ prefix, otherwise SkyTemple's system-defined constants starting with "$" would now be invalid.

Behaviour

When keeping backwards-compatibility, variables would have the same name, regardless of prefix ($var and %var are the same label), this would be purely on parser level. If not keeping backwards-compatibility, code which currently falls back to interpreting VARIABLE as IDENTIFIER can be removed.

Compiler Implementation

Compiler Interface Changes

None.

Decompiler Changes

None.

How to teach

Update the documentation to only use this new prefix. Simplify the section on differences between the variable types.

Alternatives

Backwards compatibility

Ideally the old syntax is kept compatible by still allowing the old prefix, alternatively this would be backwards-incompatible, but the scope would be acceptable since this "just" affects macros which are not decompiled by default and are an advanced language feature.

irdkwia commented 3 months ago

https://github.com/SkyTemple/ExplorerScript/blob/bd55da784f95349004997f5fbbe76f2465eb3043/explorerscript/antlr/SsbCommon.g4#L100 Would changing this line in the language model to : [$%] IDENTIFIER_BASE work to allow both syntaxes in variables? I suppose this would apply to game variables too, but if the whole variable name is checked (with the leading $) this shouldn't be a problem

theCapypara commented 3 months ago

Could be all that is needed, yes. There's probably some code in the compiler as well that needs to be checked though.