diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5b2a697..fd02e89 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -106,7 +106,7 @@ packages: remark-parse: 11.0.0 remark-rehype: 11.1.0 remark-smartypants: 2.1.0 - shiki: 1.2.3 + shiki: 1.2.4 unified: 11.0.4 unist-util-remove-position: 5.0.0 unist-util-visit: 5.0.0 @@ -885,7 +885,7 @@ packages: resolution: {integrity: sha512-LWgttQTUrIPE1X+Lya1qFWiX47tH2AS2hkbj/cZoWkdiSjn6zUvtTypK/2Xn6Rgn6z6ClzpgHvkXRqFn7nAB4A==} dependencies: '@expressive-code/core': 0.33.5 - shiki: 1.2.3 + shiki: 1.2.4 dev: false /@expressive-code/plugin-text-markers@0.33.5: @@ -1141,8 +1141,8 @@ packages: dev: false optional: true - /@shikijs/core@1.2.3: - resolution: {integrity: sha512-SM+aiQVaEK2P53dEcsvhq9+LJPr0rzwezHbMQhHaSrPN4OlOB4vp1qTdhVEKfMg6atdq8s9ZotWW/CSCzWftwg==} + /@shikijs/core@1.2.4: + resolution: {integrity: sha512-ClaUWpt8oTzjcF0MM1P81AeWyzc1sNSJlAjMG80CbwqbFqXSNz+NpQVUC0icobt3sZn43Sn27M4pHD/Jmp3zHw==} dev: false /@types/acorn@4.0.6: @@ -1487,7 +1487,7 @@ packages: rehype: 13.0.1 resolve: 1.22.8 semver: 7.6.0 - shiki: 1.2.3 + shiki: 1.2.4 string-width: 7.1.0 strip-ansi: 7.1.0 tsconfck: 3.0.3(typescript@5.4.3) @@ -4033,10 +4033,10 @@ packages: engines: {node: '>=8'} dev: false - /shiki@1.2.3: - resolution: {integrity: sha512-+v7lO5cJMeV2N2ySK4l+51YX3wTh5I49SLjAOs1ch1DbUfeEytU1Ac9KaZPoZJCVBGycDZ09OBQN5nbcPFc5FQ==} + /shiki@1.2.4: + resolution: {integrity: sha512-Q9n9jKiOjJCRPztA9POn3/uZXNySHDNKAsPNpmtHDcFyi6ZQhx5vQKZW3Nhrwn8TWW3RudSRk66zqY603EZDeg==} dependencies: - '@shikijs/core': 1.2.3 + '@shikijs/core': 1.2.4 dev: false /signal-exit@3.0.7: diff --git a/src/content/docs/guides/syntax.md b/src/content/docs/guides/syntax.md index d005e2d..ee02dab 100644 --- a/src/content/docs/guides/syntax.md +++ b/src/content/docs/guides/syntax.md @@ -49,7 +49,8 @@ fn main() { This code defines a function called `main` that will be executed every tick. :::note -ShulkerScript always requires a `main` function to be present in the code. +ShulkerScript always requires at least one function annotated with `tick`, `load` or `deobfuscate`. +Otherwise no `.mcfunction` files will be generated. ::: ### Annotations @@ -110,7 +111,7 @@ In most cases, you can use [literal commands](#literal-commands) instead of the The `lua` keyword is used to embed Lua code in your ShulkerScript code. It can be combined with the `run` keyword to include the result of the Lua code in the output. ```shulkerscript run lua() { - // Lua code goes here + -- Lua code goes here return "Hello, Lua!"; -} +}; ``` \ No newline at end of file diff --git a/src/content/docs/reference/lua.md b/src/content/docs/reference/lua.md index a7f8f1c..30de189 100644 --- a/src/content/docs/reference/lua.md +++ b/src/content/docs/reference/lua.md @@ -16,7 +16,7 @@ Your Lua code should return a string value when used in combination with the run ## Syntax ```shulkerscript run lua() { - // Lua code goes here + -- Lua code goes here return "Hello, Lua!"; -} +}; ``` \ No newline at end of file diff --git a/src/utils/shiki.ts b/src/utils/shiki.ts index 752b3f9..7b94868 100644 --- a/src/utils/shiki.ts +++ b/src/utils/shiki.ts @@ -1,20 +1,10 @@ import type { PluginShikiOptions } from "@astrojs/starlight/expressive-code"; +import { shulkerscriptGrammar } from "./shulkerscript-grammar"; const config: PluginShikiOptions = { langs: [ - /*{ - name: 'shulkerscript', - aliases: ['shu'], - displayName: 'ShulkerScript', - fileTypes: ['shu'], - scopeName: 'source.shulkerscript', - patterns: [ - { - - } - ] - }*/ - ] + shulkerscriptGrammar, + ], }; -export default config; \ No newline at end of file +export default config; diff --git a/src/utils/shulkerscript-grammar.ts b/src/utils/shulkerscript-grammar.ts new file mode 100644 index 0000000..7664123 --- /dev/null +++ b/src/utils/shulkerscript-grammar.ts @@ -0,0 +1,145 @@ + +export const shulkerscriptGrammar = { + name: "shulkerscript", + aliases: ["shu"], + displayName: "ShulkerScript", + fileTypes: ["shu"], + scopeName: "source.shulkerscript", + patterns: [ + { + include: "#functionContents", + }, + { + include: "#functionDeclaration", + }, + { + include: "#functionAnnotation", + }, + ], + repository: { + // Groupings + functionContents: { + patterns: [ + { include: "#docComment" }, + { include: "#lineComment" }, + { include: "#blockComment" }, + { include: "#commandLiteral" }, + { include: "#lua" }, + { include: "#groupBlock" }, + { include: "#stringLiteral" }, + { include: "#binaryOperator" }, + { include: "#ifKeyword" }, + { include: "#elseKeyword" }, + { include: "#runKeyword" }, + ], + }, + + // Components + lineComment: { + name: "comment.line.shulkerscript", + match: "//.*$", + }, + blockComment: { + name: "comment.block.shulkerscript", + begin: "/\\*", + end: "\\*/", + }, + docComment: { + name: "comment.documentation.shulkerscript", + match: "///.*$", + }, + functionDeclaration: { + name: "entity.name.function.shulkerscript", + begin: "^\\s*(fn)\\s+(\\w+)\\(\\s*\\)\\s*{", + end: "}", + captures: { + 1: { + name: "keyword.control.function.shulkerscript", + }, + 2: { + name: "entity.name.function.shulkerscript", + }, + }, + patterns: [{ include: "#functionContents" }], + }, + functionAnnotation: { + name: "entity.annotation.function.shulkerscript", + match: '(#\\[)(\\w+)(?:\\s*=\\s*"[^"]+")?(\\])', + captures: { + 1: { + name: "keyword.operator.annotation.shulkerscript", + }, + 2: { + name: "entity.annotation.function.shulkerscript", + }, + 3: { + name: "keyword.operator.annotation.shulkerscript", + }, + }, + }, + binaryOperator: { + name: "punctuation.operator.binary.shulkerscript", + match: "(&&|\\|\\|)", + }, + ifKeyword: { + name: "keyword.control.if.shulkerscript", + match: "\\bif\\b", + }, + elseKeyword: { + name: "keyword.control.else.shulkerscript", + match: "\\belse\\b", + }, + runKeyword: { + name: "keyword.control.run.shulkerscript", + match: "\\brun\\b", + }, + commandLiteral: { + name: "string.commandliteral.shulkerscript", + match: "^\\s*(/\\w+)(.*)$", + captures: { + 1: { + name: "keyword.operator.literalcommand.shulkerscript", + }, + 2: { + name: "string.command.shulkerscript", + }, + }, + }, + stringLiteral: { + name: "string.quoted.double.shulkerscript", + begin: '"', + end: '"', + patterns: [ + { + name: "constant.character.escape.shulkerscript", + match: "\\\\.", + }, + ], + }, + lua: { + name: "entity.lua.shulkerscript", + begin: "(lua)\\s*\\(\\s*\\)\\s*{", + end: "}", + beginCaptures: { + 1: { + name: "keyword.control.lua.shulkerscript", + }, + }, + patterns: [{ include: "source.lua" }], + }, + groupBlock: { + name: "entity.group.shulkerscript", + begin: "^\\s*(group)\\s*{", + end: "}", + captures: { + 1: { + name: "keyword.control.group.shulkerscript", + }, + 2: { + name: "entity.name.group.shulkerscript", + }, + }, + patterns: [{ include: "#functionContents" }], + }, + }, +}; \ No newline at end of file