How is skript parsing a sk file?

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Gamebuster

Addon Developer
Jan 25, 2017
26
3
3
124
Ur-Anus
So, I'm looking at the SkriptParser class (https://github.com/Njol/Skript/blob/master/src/main/java/ch/njol/skript/lang/SkriptParser.java).

I'm trying to figure out where exactly skript is parsing a string into whatever skript uses to execute code.

I.E.

Code:
on spawn of player:
    message "lel, %event-player%" to player

How does it determine that player is a valid entity for the on spawn event, or that %event-player% is actually a player? What's actually stopping nonsense like the below code from parsing:

Code:
on spawn of chest:
    teleport %event-chest% to water
 
So, I'm looking at the SkriptParser class (https://github.com/Njol/Skript/blob/master/src/main/java/ch/njol/skript/lang/SkriptParser.java).

I'm trying to figure out where exactly skript is parsing a string into whatever skript uses to execute code.

I.E.

Code:
on spawn of player:
    message "lel, %event-player%" to player

How does it determine that player is a valid entity for the on spawn event, or that %event-player% is actually a player? What's actually stopping nonsense like the below code from parsing:

Code:
on spawn of chest:
    teleport %event-chest% to water
Some of it is also done in.
https://github.com/Njol/Skript/blob/master/src/main/java/ch/njol/skript/ScriptLoader.java#L634-L740
This is where it detects an error and prints it such as "Don't understand condition/effect"
https://github.com/Njol/Skript/blob.../njol/skript/lang/SkriptParser.java#L171-L177
event-* are registered already, so Skript knows which ones are valid or not. Everything is parsed, but not everything matches what Skript expects.
 
I think it just like store something into an hashmap
Event can be the key , and the expression can be the value
if you wanna check the expression is valid on that event just check
if(hash.get(event).equals(expression))

i dunno what is exactly Skript doing but that's logic maybe still the same