CommandHelper

CommandHelper

46.5k Downloads

Keywords as keys in array()

Anatoliy057 opened this issue ยท 4 comments

commented

When initializing an associative array, using keywords as keys (without ['], ["]) thrown different errors:

array(static: 57) //native, final, public, private, package, etc.

COMPILE ERROR: Keyword not supported yet.
       at :C:\Users\A-y57\Dev\minecraft\plugins\CommandHelper\main.ms:19.13
array(class: 57)

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        at java.util.ArrayList.rangeCheck(Unknown Source)
        at java.util.ArrayList.get(Unknown Source)
        at com.laytonsmith.core.compiler.keywords.ObjectDefinitionKeyword.getClassName(ObjectDefinitionKeyword.java:133)
        at com.laytonsmith.core.compiler.keywords.ObjectDefinitionKeyword.process(ObjectDefinitionKeyword.java:48)
        at com.laytonsmith.core.MethodScriptCompiler.processKeywords(MethodScriptCompiler.java:2685)
        at com.laytonsmith.core.MethodScriptCompiler.processKeywords(MethodScriptCompiler.java:2673)
        at com.laytonsmith.core.MethodScriptCompiler.processKeywords(MethodScriptCompiler.java:2673)
        at com.laytonsmith.core.MethodScriptCompiler.compile(MethodScriptCompiler.java:1820)
        at com.laytonsmith.core.AliasCore$LocalPackage.compileMS(AliasCore.java:746)
        at com.laytonsmith.core.AliasCore.reload(AliasCore.java:384)
        at com.laytonsmith.commandhelper.CommandHelperPlugin.onCommand(CommandHelperPlugin.java:575)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141)
        at org.bukkit.craftbukkit.v1_13_R2.CraftServer.dispatchCommand(CraftServer.java:704)
        at org.bukkit.craftbukkit.v1_13_R2.CraftServer.dispatchServerCommand(CraftServer.java:689)
        at net.minecraft.server.v1_13_R2.DedicatedServer.handleCommandQueue(DedicatedServer.java:459)
        at net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:418)
        at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:831)
        at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:729)
        at java.lang.Thread.run(Unknown Source)
array(proc: 57)

COMPILE ERROR: Unexpected use of "proc" keyword
       at :C:\Users\A-y57\Dev\minecraft\plugins\CommandHelper\main.ms:19.13

If we use types of variable and names of error as keys, we get:

array(mixed: 57)

{ms.lang.mixed: 57}
commented

This is intended to be supported, as labels can unambiguously be determined due to the :. So what we need to do is move up label detection, and/or not send it to the keyword processor. I can't recall offhand what order those lexems are parsed, but one or the other needs to be done.

commented

When using labels (CLabel), would it ever be desired to interpret their value as a keyword? Or something other than a string even? If not, then removal of this line would fix it:
https://github.com/EngineHub/CommandHelper/blob/master/src/main/java/com/laytonsmith/core/MethodScriptCompiler.java#L2682

commented

Actually, after thinking about this some more, it's definitely more complicated. Consider for instance default: in a switch statement. We need to continue to consider that a keyword, as well as a label.

commented

This is exactly what postParseRewrite() should be used for. The switch() statement itself should look at its children and rewrite itself to its desugared version. Whether the parser left a CLabel with or without a keyword in it should not matter here.
Thinking more deeply about it, switch() is responsible for its own case and default labels. array() and associative_array() are responsible for their labels (rewriting them to centry()). I can't think of any 'standalone' labels (that are not part of a function's sugared syntax).