diff --git a/src/content/docs/guides/getting-started.mdx b/src/content/docs/guides/getting-started.mdx index e5eb4f2..f796309 100644 --- a/src/content/docs/guides/getting-started.mdx +++ b/src/content/docs/guides/getting-started.mdx @@ -69,6 +69,10 @@ The annotation `#[tick]` tells the compiler that this function should be execute Every line that starts with a `/` is a command that will included in the output. You can add as many commands as you like. To begin with, you can change the message in the `/say` command to something else. +:::caution +Only functions annotated with `#[tick]`, `#[load]`, `#[deobfuscate]` or called from generated functions will be included in the output. +::: + ## Building the project 1. Navigate into the project directory. diff --git a/src/content/docs/guides/syntax.md b/src/content/docs/guides/syntax.md index ee02dab..43d7220 100644 --- a/src/content/docs/guides/syntax.md +++ b/src/content/docs/guides/syntax.md @@ -87,6 +87,45 @@ if ("block ~ ~-1 ~ minecraft:stone") { } ``` +## Execute Blocks +Execute blocks are used to execute a block of code in a specific context. +They consist of the keyword you would pass to the `/execute` command followed the argument as a string in parenthesis and a block of code. +```shulkerscript +as ("@a") { // execute as all players + /say Hello, world! +} +``` + +:::tip[Quality of Life] +You can use the `asat` keyword to combine the `as` and `at` keywords. It has the same effect as using `as("...")` and `at("@s")` in sequence. +::: + +Multiple execute blocks can be chained together by separating them with a comma. +```shulkerscript +positioned ("0 0 0"), in ("minecraft:overworld") { + /setblock ~ ~ ~ minecraft:stone +} +``` + +:::tip[Did you know?] +[Conditionals](#conditional-statements) are also implemented as execute blocks.Therefore you can chain them together with other execute blocks. Keep in mind that an if-else statement can only be used as the last execute block in a chain. +::: + +### Supported Execute Blocks + +- `align` +- `anchored` +- `as` +- `at` +- `asat` +- `facing` +- `in` +- `on` +- `positioned` +- `rotated` +- `store` +- `summon` + ## Groupings Groupings are used to group multiple commands into one `mcfunction` file without declaring a new function. This can be used for commands that need to be executed atomically. diff --git a/src/utils/shulkerscript-grammar.ts b/src/utils/shulkerscript-grammar.ts index 7664123..6132800 100644 --- a/src/utils/shulkerscript-grammar.ts +++ b/src/utils/shulkerscript-grammar.ts @@ -6,6 +6,9 @@ export const shulkerscriptGrammar = { fileTypes: ["shu"], scopeName: "source.shulkerscript", patterns: [ + { + include: "#namespaceKeyword", + }, { include: "#functionContents", }, @@ -28,9 +31,10 @@ export const shulkerscriptGrammar = { { include: "#groupBlock" }, { include: "#stringLiteral" }, { include: "#binaryOperator" }, - { include: "#ifKeyword" }, + { include: "#executeKeyword" }, { include: "#elseKeyword" }, { include: "#runKeyword" }, + { include: "#functionCall" }, ], }, @@ -48,8 +52,11 @@ export const shulkerscriptGrammar = { name: "comment.documentation.shulkerscript", match: "///.*$", }, + namespaceKeyword: { + name: "keyword.control.namespace.shulkerscript", + match: "\\bnamespace\\b", + }, functionDeclaration: { - name: "entity.name.function.shulkerscript", begin: "^\\s*(fn)\\s+(\\w+)\\(\\s*\\)\\s*{", end: "}", captures: { @@ -77,13 +84,21 @@ export const shulkerscriptGrammar = { }, }, }, + functionCall: { + match: "(\\w+)\\s*\\(\\s*(?:\\w+\\s*)?\\)", + captures: { + 1: { + name: "entity.name.function.shulkerscript", + }, + } + }, binaryOperator: { name: "punctuation.operator.binary.shulkerscript", match: "(&&|\\|\\|)", }, - ifKeyword: { - name: "keyword.control.if.shulkerscript", - match: "\\bif\\b", + executeKeyword: { + name: "keyword.control.execute.shulkerscript", + match: "\\b(if|align|as|asat|at|facing|in|on|positioned|rotated|store|summon)\\b", }, elseKeyword: { name: "keyword.control.else.shulkerscript", @@ -98,7 +113,7 @@ export const shulkerscriptGrammar = { match: "^\\s*(/\\w+)(.*)$", captures: { 1: { - name: "keyword.operator.literalcommand.shulkerscript", + name: "keyword.other.commandliteral.shulkerscript", }, 2: { name: "string.command.shulkerscript",