Add execute blocks to syntax documentation

This commit is contained in:
Moritz Hölting 2024-04-09 21:50:02 +02:00
parent 064bb0b0ad
commit 3fb12eb77c
3 changed files with 64 additions and 6 deletions

View File

@ -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. 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. 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 ## Building the project
<Steps> <Steps>
1. Navigate into the project directory. 1. Navigate into the project directory.

View File

@ -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
Groupings are used to group multiple commands into one `mcfunction` file without declaring a new function. 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. This can be used for commands that need to be executed atomically.

View File

@ -6,6 +6,9 @@ export const shulkerscriptGrammar = {
fileTypes: ["shu"], fileTypes: ["shu"],
scopeName: "source.shulkerscript", scopeName: "source.shulkerscript",
patterns: [ patterns: [
{
include: "#namespaceKeyword",
},
{ {
include: "#functionContents", include: "#functionContents",
}, },
@ -28,9 +31,10 @@ export const shulkerscriptGrammar = {
{ include: "#groupBlock" }, { include: "#groupBlock" },
{ include: "#stringLiteral" }, { include: "#stringLiteral" },
{ include: "#binaryOperator" }, { include: "#binaryOperator" },
{ include: "#ifKeyword" }, { include: "#executeKeyword" },
{ include: "#elseKeyword" }, { include: "#elseKeyword" },
{ include: "#runKeyword" }, { include: "#runKeyword" },
{ include: "#functionCall" },
], ],
}, },
@ -48,8 +52,11 @@ export const shulkerscriptGrammar = {
name: "comment.documentation.shulkerscript", name: "comment.documentation.shulkerscript",
match: "///.*$", match: "///.*$",
}, },
namespaceKeyword: {
name: "keyword.control.namespace.shulkerscript",
match: "\\bnamespace\\b",
},
functionDeclaration: { functionDeclaration: {
name: "entity.name.function.shulkerscript",
begin: "^\\s*(fn)\\s+(\\w+)\\(\\s*\\)\\s*{", begin: "^\\s*(fn)\\s+(\\w+)\\(\\s*\\)\\s*{",
end: "}", end: "}",
captures: { captures: {
@ -77,13 +84,21 @@ export const shulkerscriptGrammar = {
}, },
}, },
}, },
functionCall: {
match: "(\\w+)\\s*\\(\\s*(?:\\w+\\s*)?\\)",
captures: {
1: {
name: "entity.name.function.shulkerscript",
},
}
},
binaryOperator: { binaryOperator: {
name: "punctuation.operator.binary.shulkerscript", name: "punctuation.operator.binary.shulkerscript",
match: "(&&|\\|\\|)", match: "(&&|\\|\\|)",
}, },
ifKeyword: { executeKeyword: {
name: "keyword.control.if.shulkerscript", name: "keyword.control.execute.shulkerscript",
match: "\\bif\\b", match: "\\b(if|align|as|asat|at|facing|in|on|positioned|rotated|store|summon)\\b",
}, },
elseKeyword: { elseKeyword: {
name: "keyword.control.else.shulkerscript", name: "keyword.control.else.shulkerscript",
@ -98,7 +113,7 @@ export const shulkerscriptGrammar = {
match: "^\\s*(/\\w+)(.*)$", match: "^\\s*(/\\w+)(.*)$",
captures: { captures: {
1: { 1: {
name: "keyword.operator.literalcommand.shulkerscript", name: "keyword.other.commandliteral.shulkerscript",
}, },
2: { 2: {
name: "string.command.shulkerscript", name: "string.command.shulkerscript",