I am currently developing an extension for VS Code that will enhance Skript syntax support.
One challenge I am facing is the inability to select the body of the code block. Skript syntax includes various blocks such as commands, functions, and events, each starting with zero indentation. Below is an example of Skript syntax:
on join:
set the player's gamemode to spectator
join_player(player)
command /join [<player>]:
trigger:
if arg-1 is not set:
join_player(player)
else:
player has permission "op"
join_player(arg-1)
function reset_arena():
set all blocks within {loc1} and {loc2} to snow block
The original author of this extension used a specific construction which fails when there are odd line breaks (\r\n|\r|\n). It also does not properly handle the last line of the document as unrelated to the last component.
if (search = component.match(/^(?<component>(command\s?(?<head>[^\:]*))\:?(.*)(?<body>((\r\n|\r|\n)([^a-zA-Z][^\r\n]*)?)*))/i)?.groups) {
return this._createCommand(skDocument, range, search.component, search.head, search.body);
}
I would appreciate guidance on creating a regex pattern to accurately select the body of the component. Thank you in advance!