From 386ee37ca7c09cdf6bf744b3bfea8981b2b0bbce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20H=C3=B6lting?= <87192362+moritz-hoelting@users.noreply.github.com> Date: Tue, 20 Aug 2024 22:27:14 +0200 Subject: [PATCH] add syntax highlighting for mcfunction & mcscript code blocks --- package.json | 1 + pnpm-lock.yaml | 15 +- src/utils/mcfunction-grammar.ts | 1389 ++++++++++++++++++++++++++++ src/utils/mcscript-grammar.ts | 87 ++ src/utils/shiki.ts | 7 +- src/utils/shulkerscript-grammar.ts | 5 +- 6 files changed, 1490 insertions(+), 14 deletions(-) create mode 100644 src/utils/mcfunction-grammar.ts create mode 100644 src/utils/mcscript-grammar.ts diff --git a/package.json b/package.json index 522e353..2b3c24e 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@astrojs/starlight": "^0.26.1", "astro": "^4.14.3", "sharp": "^0.33.5", + "shiki": "^1.14.1", "starlight-links-validator": "^0.10.1", "typescript": "^5.4.5" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0effa36..2d858a7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ dependencies: sharp: specifier: ^0.33.5 version: 0.33.5 + shiki: + specifier: ^1.14.1 + version: 1.14.1 starlight-links-validator: specifier: ^0.10.1 version: 0.10.1(@astrojs/starlight@0.26.1)(astro@4.14.3) @@ -696,7 +699,7 @@ packages: resolution: {integrity: sha512-xm+hzi9BsmhkDUGuyAWIydOAWer7Cs9cj8FM0t4HXaQ+qCubprT6wJZSKUxuvFJIUsIOqk1xXFaJzGJGnWtKMg==} dependencies: '@expressive-code/core': 0.35.6 - shiki: 1.6.4 + shiki: 1.14.1 dev: false /@expressive-code/plugin-text-markers@0.35.6: @@ -1166,10 +1169,6 @@ packages: '@types/hast': 3.0.4 dev: false - /@shikijs/core@1.6.4: - resolution: {integrity: sha512-WTU9rzZae1p2v6LOxMf6LhtmZOkIHYYW160IuahUyJy7YXPPjyWZLR1ag+SgD22ZMxZtz1gfU6Tccc8t0Il/XA==} - dev: false - /@types/acorn@4.0.6: resolution: {integrity: sha512-veQTnWP+1D/xbxVrPC3zHnCZRjSrKfhbMUlEA43iMZLu7EsnTtkJklIuwrCPbOi8YkvDQAiW05VQQFvvz9oieQ==} dependencies: @@ -3814,12 +3813,6 @@ packages: '@types/hast': 3.0.4 dev: false - /shiki@1.6.4: - resolution: {integrity: sha512-X88chM7w8jnadoZtjPTi5ahCJx9pc9f8GfEkZAEYUTlcUZIEw2D/RY86HI/LkkE7Nj8TQWkiBfaFTJ3VJT6ESg==} - dependencies: - '@shikijs/core': 1.6.4 - dev: false - /signal-exit@3.0.7: resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} dev: false diff --git a/src/utils/mcfunction-grammar.ts b/src/utils/mcfunction-grammar.ts new file mode 100644 index 0000000..5afda2a --- /dev/null +++ b/src/utils/mcfunction-grammar.ts @@ -0,0 +1,1389 @@ +import type { LanguageInput } from "shiki"; + +export const mcfunctionGrammar: LanguageInput = { + name: "mcfunction", + scopeName: "source.mcfunction", + displayName: "McFunction", + fileTypes: ["mcfunction"], + patterns: [ + { + include: "#comment", + }, + { + include: "#command", + }, + { + include: "#unknown", + }, + ], + repository: { + "$base": {}, + "$self": {}, + comment: { + patterns: [ + { + name: "meta.comment.block.mcfunction", + begin: "^[ \\t]*((#)([\\#\\>\\~\\!\\@\\$\\%\\^\\*]+)((.*)))$", + end: "^(?![ \\t]*#)", + beginCaptures: { + 1: { + name: "comment.block.mcfunction", + }, + 2: { + name: "markup.list.mcfunction", + }, + 3: { + name: "markup.list.mcfunction", + }, + 4: { + name: "markup.bold.mcfunction", + }, + 5: { + name: "markup.list.mcfunction", + }, + }, + patterns: [ + { + include: "#comment.block", + }, + ], + }, + { + name: "meta.comment.line.mcfunction", + match: "^[ \\t]*(#.*)$", + captures: { + 1: { + name: "comment.line.mcfunction", + }, + }, + }, + ], + }, + "comment.block": { + patterns: [ + { + name: "meta.comment.block_line.mcfunction", + begin: "^[ \\t]*((#)[ \\t]*)", + end: "$", + beginCaptures: { + 1: { + name: "comment.block.mcfunction", + }, + 2: { + name: "markup.list.mcfunction", + }, + }, + patterns: [ + { + include: "#comment.block.line", + }, + ], + }, + ], + }, + "comment.block.line": { + patterns: [ + { + name: "meta.comment.block.annotation.mcfunction", + match: "((\\@\\w*)\\b(.*))$", + captures: { + 1: { + name: "comment.block.mcfunction", + }, + 2: { + name: "markup.heading.mcfunction", + }, + 3: { + name: "comment.block.mcfunction", + }, + }, + }, + { + name: "meta.comment.block.heading.mcfunction", + match: "(([\\#\\>\\~\\!\\@\\$\\%\\^\\*]+)((.*)))$", + captures: { + 1: { + name: "comment.block.mcfunction", + }, + 2: { + name: "markup.list.mcfunction", + }, + 3: { + name: "markup.bold.mcfunction", + }, + 4: { + name: "markup.list.mcfunction", + }, + }, + }, + { + name: "meta.comment.block.text.mcfunction", + match: "(.*)$", + captures: { + 1: { + name: "comment.block.mcfunction", + }, + }, + }, + ], + }, + command: { + patterns: [ + { + name: "meta.command.mcfunction", + begin: "^\\s*([a-z_][a-z0-9_]*)[ \\n]", + end: "$", + beginCaptures: { + 1: { + name: "keyword.control.mcfunction", + }, + }, + patterns: [ + { + begin: "(?<= )", + end: "[ \\n]", + contentName: "meta.command.token.mcfunction", + patterns: [ + { + include: "#command.tokens", + }, + ], + }, + ], + }, + ], + }, + unknown: { + patterns: [ + { + name: "meta.unknown.mcfunction", + match: "^(.*)$", + captures: { + 1: { + name: "invalid.illegal.mcfunction", + }, + }, + }, + ], + }, + "command.tokens": { + patterns: [ + { + include: "#command.token.nbt_compound", + }, + { + include: "#command.token.nbt_list", + }, + { + include: "#command.token.selector_with_arguments", + }, + { + include: "#command.token.selector_without_arguments", + }, + { + include: "#command.token.block_predicate", + }, + { + include: "#command.token.block_predicate_without_namespace", + }, + { + include: "#command.token.resource_location", + }, + { + include: "#command.token.tagged_resource_location", + }, + { + include: "#command.token.range", + }, + { + include: "#command.token.number", + }, + { + include: "#command.token.coordinate", + }, + { + include: "#command.token.boolean", + }, + { + include: "#command.token.operation", + }, + { + include: "#command.token.root_redirect", + }, + { + include: "#command.token.greedy_parent", + }, + { + include: "#command.token.literal", + }, + { + include: "#command.token.uuid", + }, + { + include: "#command.token.fakeplayer", + }, + { + include: "#command.token.nbt_path", + }, + { + include: "#command.token.quoted_string", + }, + { + include: "#command.token.single_quoted_string", + }, + { + include: "#command.token.unquoted_string", + }, + { + include: "#command.token.unknown", + }, + ], + }, + "command.token.selector_without_arguments": { + name: "meta.command.token.selector_without_arguments.mcfunction", + match: "(?<= )(\\@[a-z])(?=[ \\n]|$)", + captures: { + 1: { + name: "support.class.mcfunction", + }, + }, + }, + "command.token.resource_location": { + name: "meta.command.token.resource_location.mcfunction", + match: "(?<= )([a-z0-9_\\.\\-]+)(\\:)([a-z0-9_\\.\\-\\/]+)(?=[ \\n]|$)", + captures: { + 1: { + name: "entity.name.function.mcfunction", + }, + 2: { + name: "entity.name.function.mcfunction", + }, + 3: { + name: "entity.name.function.mcfunction", + }, + }, + }, + "command.token.tagged_resource_location": { + name: "meta.command.token.tagged_resource_location.mcfunction", + match: "(?<= )(\\#)([a-z0-9_\\.\\-]+)(\\:)([a-z0-9_\\.\\-\\/]+)(?=[ \\n]|$)", + captures: { + 1: { + name: "entity.name.function.mcfunction", + }, + 2: { + name: "entity.name.function.mcfunction", + }, + 3: { + name: "entity.name.function.mcfunction", + }, + 4: { + name: "entity.name.function.mcfunction", + }, + }, + }, + "command.token.range": { + name: "meta.command.token.range.mcfunction", + match: "(?<= )(\\-?\\d*\\.?\\d+)?(\\.\\.)(\\-?\\d*\\.?\\d+)?(?=[ \\n]|$)", + captures: { + 1: { + name: "constant.numeric.mcfunction", + }, + 2: { + name: "keyword.control.mcfunction", + }, + 3: { + name: "constant.numeric.mcfunction", + }, + }, + }, + "command.token.number": { + name: "meta.command.token.number.mcfunction", + match: "(?<= )(\\-?\\d*\\.?\\d+)(?=[ \\n]|$)", + captures: { + 1: { + name: "constant.numeric.mcfunction", + }, + }, + }, + "command.token.coordinate": { + name: "meta.command.token.coordinate.mcfunction", + match: "(?<= )([\\~\\^])(\\-?\\d*\\.?\\d+)?(?=[ \\n]|$)", + captures: { + 1: { + name: "constant.numeric.mcfunction", + }, + 2: { + name: "constant.numeric.mcfunction", + }, + }, + }, + "command.token.boolean": { + name: "meta.command.token.boolean.mcfunction", + match: "(?<= )(true|false)(?=[ \\n]|$)", + captures: { + 1: { + name: "constant.numeric.mcfunction", + }, + }, + }, + "command.token.operation": { + name: "meta.command.token.operation.mcfunction", + match: "(?<= )(\\%\\=|\\*\\=|\\+\\=|\\-\\=|\\/\\=|\\<|\\=|\\>|\\>\\<|\\<\\=|\\>\\=)(?=[ \\n]|$)", + captures: { + 1: { + name: "constant.numeric.mcfunction", + }, + }, + }, + "command.token.literal": { + name: "meta.command.token.literal.mcfunction", + match: "(?<= )([a-z_][a-z0-9_]*)(?=[ \\n]|$)", + captures: { + 1: { + name: "entity.name.mcfunction", + }, + }, + }, + "command.token.uuid": { + name: "meta.command.token.uuid.mcfunction", + match: "(?<= )([0-9a-fA-F]+(?:(-)[0-9a-fA-F]+){4})(?=[ \\n]|$)", + captures: { + 1: { + name: "support.class.mcfunction", + }, + }, + }, + "command.token.fakeplayer": { + name: "meta.command.token.fakeplayer.mcfunction", + match: "(?<= )([\\#\\$\\%]\\S+)(?=[ \\n]|$)", + captures: { + 1: { + name: "support.class.mcfunction", + }, + }, + }, + "command.token.unquoted_string": { + name: "meta.command.token.unquoted_string.mcfunction", + match: "(?<= )(\\S+)(?=[ \\n]|$)", + captures: { + 1: { + name: "string.unquoted.mcfunction", + }, + }, + }, + "command.token.unknown": { + name: "meta.command.token.unknown.mcfunction", + match: "(?<= )([^ \\n]*)(?=[ \\n]|$)", + captures: { + 1: { + name: "invalid.illegal.mcfunction", + }, + }, + }, + "command.token.root_redirect": { + name: "meta.command.token.root_redirect.mcfunction", + match: "(?<= )(run) ([a-z_][a-z0-9_]*)?(?=[ \\n]|$)", + captures: { + 1: { + name: "entity.name.mcfunction", + }, + 2: { + name: "keyword.control.mcfunction", + }, + }, + }, + "command.token.greedy_parent": { + name: "meta.command.token.greedy_parent.mcfunction", + match: "((?<=^say | say ))(.*)$", + captures: { + 1: { + name: "entity.name.mcfunction", + }, + 2: { + name: "string.quoted.mcfunction", + }, + }, + }, + "command.token.nbt_compound": { + name: "meta.command.token.nbt_compound.mcfunction", + begin: "(?<= )(\\{)", + end: "(?=\\n)|(\\})([^ \\n]*)", + beginCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + 2: { + name: "invalid.illegal.mcfunction", + }, + }, + patterns: [ + { + include: "#nbt.compound", + }, + ], + }, + "command.token.nbt_list": { + name: "meta.command.token.nbt_list.mcfunction", + begin: "(?<= )(\\[)(\\w*;)?", + end: "(?=\\n)|(\\])([^ \\n]*)", + beginCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + 2: { + name: "variable.language.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + 2: { + name: "invalid.illegal.mcfunction", + }, + }, + patterns: [ + { + include: "#nbt.list", + }, + ], + }, + "nbt.compound": { + patterns: [ + { + match: " +", + }, + { + begin: '(,)? *([A-Za-z0-9_\\.\\-]+|\\"[^\\n\\"]+\\") *(\\:) *', + end: " *(?=[\\n\\}\\,])", + beginCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + 2: { + name: "string.interpolated.mcfunction", + }, + 3: { + name: "variable.language.mcfunction", + }, + }, + patterns: [ + { + include: "#nbt.value", + }, + ], + }, + { + match: "[^\\n\\}\\,]+", + name: "invalid.illegal.mcfunction", + }, + ], + }, + "nbt.list": { + patterns: [ + { + match: " +", + }, + { + begin: "(,)? *(?=[^\\n\\]\\,])", + end: " *(?=[\\n\\]\\,])", + beginCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + }, + patterns: [ + { + include: "#nbt.value", + }, + ], + }, + { + match: "[^\\n\\]\\,]+", + name: "invalid.illegal.mcfunction", + }, + ], + }, + "nbt.value": { + patterns: [ + { + begin: "(\\{)", + end: "(?=\\n)|(\\})", + beginCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + }, + patterns: [ + { + include: "#nbt.compound", + }, + ], + }, + { + begin: "(\\[)(\\w*;)?", + end: "(?=\\n)|(\\])", + beginCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + 2: { + name: "variable.language.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + }, + patterns: [ + { + include: "#nbt.list", + }, + ], + }, + { + begin: '(\\")', + end: '(?=\\n)|(\\")', + beginCaptures: { + 1: { + name: "string.quoted.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "string.quoted.mcfunction", + }, + }, + patterns: [ + { + include: "#common.quoted_string", + }, + ], + }, + { + begin: "(\\')", + end: "(?=\\n)|(\\')", + beginCaptures: { + 1: { + name: "string.quoted.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "string.quoted.mcfunction", + }, + }, + patterns: [ + { + include: "#common.single_quoted_string", + }, + ], + }, + { + match: "(true|false)", + name: "constant.numeric.mcfunction", + }, + { + match: "(\\-?\\d*\\.?\\d+)", + name: "constant.numeric.mcfunction", + }, + { + match: "([^\\s\\{\\}\\[\\]\\,\\:\\=]+)", + name: "string.unquoted.mcfunction", + }, + { + match: "[^\\n\\,\\]\\}]+", + name: "invalid.illegal.mcfunction", + }, + ], + }, + "command.token.quoted_string": { + name: "meta.command.token.quoted_string.mcfunction", + begin: '(?<= )(\\")', + end: '(?=\\n)|(\\")([^ \\n]*)', + beginCaptures: { + 1: { + name: "string.quoted.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "string.quoted.mcfunction", + }, + 2: { + name: "invalid.illegal.mcfunction", + }, + }, + patterns: [ + { + include: "#common.quoted_string", + }, + ], + }, + "command.token.single_quoted_string": { + name: "meta.command.token.single_quoted_string.mcfunction", + begin: "(?<= )(\\')", + end: "(?=\\n)|(\\')([^ \\n]*)", + beginCaptures: { + 1: { + name: "string.quoted.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "string.quoted.mcfunction", + }, + 2: { + name: "invalid.illegal.mcfunction", + }, + }, + patterns: [ + { + include: "#common.single_quoted_string", + }, + ], + }, + "command.token.block_predicate": { + name: "meta.command.token.block_predicate.mcfunction", + begin: "(?<= )(?=(\\#)?([a-z0-9_\\.\\-]+)(\\:)([a-z0-9_\\.\\-\\/]+)(\\[|\\{))", + end: "(?=\\n)|(?:(?<=\\])(?!\\{)|(?<=\\}))([^ \\n]*)", + endCaptures: { + 1: { + name: "invalid.illegal.mcfunction", + }, + }, + patterns: [ + { + include: "#block_predicate", + }, + ], + }, + "command.token.block_predicate_without_namespace": { + name: "meta.command.token.block_predicate_without_namespace.mcfunction", + begin: "(?<= )(?=(\\#)?([a-z0-9_\\.\\-\\/]+)(\\[ *([a-z_][a-z0-9_]*) *\\=))", + end: "(?=\\n)|(?:(?<=\\])(?!\\{)|(?<=\\}))([^ \\n]*)", + endCaptures: { + 1: { + name: "invalid.illegal.mcfunction", + }, + }, + patterns: [ + { + include: "#block_predicate", + }, + ], + }, + "command.token.selector_with_arguments": { + name: "meta.command.token.selector_with_arguments.mcfunction", + begin: "(?<= )(\\@[a-z])(\\[)", + end: "(?=\\n)|(\\])([^ \\n]*)", + beginCaptures: { + 1: { + name: "support.class.mcfunction", + }, + 2: { + name: "support.class.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "support.class.mcfunction", + }, + 2: { + name: "invalid.illegal.mcfunction", + }, + }, + patterns: [ + { + name: "meta.selector.argument_spacing.mcfunction", + match: " +", + }, + { + name: "meta.selector.argument.mcfunction", + begin: "((?:[a-z_][a-z0-9_]*)|(?:\"[^\"\n]*\")|(?:\\'[^\\'\n]*\\')) *(\\=) *(\\!)? *", + end: "( *\\,)(?=[\\]\\n])|( *\\,)|(?= *[\\]\\n])", + beginCaptures: { + 1: { + name: "variable.other.mcfunction", + }, + 2: { + name: "support.class.mcfunction", + }, + 3: { + name: "keyword.control.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "invalid.illegal.mcfunction", + }, + 2: { + name: "support.class.mcfunction", + }, + }, + patterns: [ + { + include: "#selector.argument.resource_location", + }, + { + include: + "#selector.argument.tagged_resource_location", + }, + { + include: "#selector.argument.range", + }, + { + include: "#selector.argument.number", + }, + { + include: "#selector.argument.boolean", + }, + { + include: "#selector.argument.property_map", + }, + { + include: "#selector.argument.nbt_compound", + }, + { + include: "#selector.argument.quoted_string", + }, + { + include: "#selector.argument.single_quoted_string", + }, + { + include: "#selector.argument.unquoted_string", + }, + { + include: "#selector.argument.unknown", + }, + ], + }, + { + name: "invalid.illegal.mcfunction", + match: "[^\\]\\n]+", + }, + ], + }, + "command.token.nbt_path": { + name: "meta.command.token.nbt_path.mcfunction", + begin: "(?<= )(?=\\w+[\\.\\[\\{])", + end: "(?=[ \\n]|$)", + patterns: [ + { + include: "#nbt_path.property", + }, + ], + }, + "nbt_path.property": { + patterns: [ + { + begin: "(\\.)?(\\w+)?(\\[)", + end: "(\\])|(?=\\n)", + beginCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + 2: { + name: "string.interpolated.mcfunction", + }, + 3: { + name: "variable.language.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + }, + patterns: [ + { + include: "#nbt_path.index", + }, + ], + }, + { + begin: "(\\.)?(\\w+)(\\{)", + end: "(\\})|(?=\\n)", + beginCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + 2: { + name: "string.interpolated.mcfunction", + }, + 3: { + name: "variable.language.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + }, + patterns: [ + { + include: "#nbt.compound", + }, + ], + }, + { + begin: '(\\")', + end: '(?=\\n)|(\\")([^\\. \\n]*)', + beginCaptures: { + 1: { + name: "string.quoted.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "string.quoted.mcfunction", + }, + 2: { + name: "invalid.illegal.mcfunction", + }, + }, + patterns: [ + { + include: "#common.quoted_string", + }, + ], + }, + { + match: "(\\.)?(\\w+)", + captures: { + 1: { + name: "variable.language.mcfunction", + }, + 2: { + name: "string.interpolated.mcfunction", + }, + }, + }, + { + match: "(\\.)(?=\\.)", + captures: { + 1: { + name: "invalid.illegal.mcfunction", + }, + }, + }, + { + match: "[^\\.\\s]+", + name: "invalid.illegal.mcfunction", + }, + ], + }, + "nbt_path.index": { + patterns: [ + { + match: "(?<=\\[)(\\-?\\d+)(?=\\])", + captures: { + 1: { + name: "constant.numeric.mcfunction", + }, + }, + }, + { + begin: "(\\{)", + end: "(?=\\n)|(\\})([^\\]\\,\\n]*)", + beginCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + 2: { + name: "invalid.illegal.mcfunction", + }, + }, + patterns: [ + { + include: "#nbt.compound", + }, + ], + }, + { + match: "[^\\n\\]]+", + name: "invalid.illegal.mcfunction", + }, + ], + }, + block_predicate: { + patterns: [ + { + match: "(\\#)([a-z0-9_\\.\\-]+)(\\:)([a-z0-9_\\.\\-\\/]+)", + captures: { + 1: { + name: "entity.name.function.mcfunction", + }, + 2: { + name: "entity.name.function.mcfunction", + }, + 3: { + name: "entity.name.function.mcfunction", + }, + 4: { + name: "entity.name.function.mcfunction", + }, + }, + }, + { + match: "([a-z0-9_\\.\\-]+)(\\:)([a-z0-9_\\.\\-\\/]+)", + captures: { + 1: { + name: "entity.name.function.mcfunction", + }, + 2: { + name: "entity.name.function.mcfunction", + }, + 3: { + name: "entity.name.function.mcfunction", + }, + }, + }, + { + match: "([a-z0-9_\\.\\-\\/]+)", + captures: { + 1: { + name: "entity.name.function.mcfunction", + }, + }, + }, + { + begin: "(\\[)", + end: "(\\])", + beginCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + }, + patterns: [ + { + include: "#block_predicate.arguments", + }, + ], + }, + { + begin: "(\\{)", + end: "(\\})", + beginCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + }, + patterns: [ + { + include: "#nbt.compound", + }, + ], + }, + ], + }, + "block_predicate.arguments": { + patterns: [ + { + name: "meta.block_predicate.argument_spacing.mcfunction", + match: " +", + }, + { + name: "meta.block_predicate.argument.mcfunction", + begin: "([a-z_][a-z0-9_]*) *(\\=) *", + end: "(\\,)(?=[\\]\\n])|(\\,)|(?=[\\]\\n])", + beginCaptures: { + 1: { + name: "variable.other.mcfunction", + }, + 2: { + name: "variable.language.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "invalid.illegal.mcfunction", + }, + 2: { + name: "variable.language.mcfunction", + }, + }, + patterns: [ + { + include: "#block_predicate.argument.number", + }, + { + include: "#block_predicate.argument.boolean", + }, + { + include: "#block_predicate.argument.literal", + }, + ], + }, + ], + }, + "block_predicate.argument.number": { + name: "meta.block_predicate.argument.number.mcfunction", + match: "(\\-?\\d*\\.?\\d+)(?= *[\\,\\]\\n])", + captures: { + 1: { + name: "constant.numeric.mcfunction", + }, + }, + }, + "block_predicate.argument.boolean": { + name: "meta.block_predicate.argument.boolean.mcfunction", + match: "(true|false)(?= *[\\,\\]\\n])", + captures: { + 1: { + name: "constant.numeric.mcfunction", + }, + }, + }, + "block_predicate.argument.literal": { + name: "meta.block_predicate.argument.literal.mcfunction", + match: "([a-z_][a-z0-9_]*)(?= *[\\,\\]\\n])", + captures: { + 1: { + name: "entity.name.mcfunction", + }, + }, + }, + "selector.argument.resource_location": { + name: "meta.selector.argument.resource_location.mcfunction", + match: "([a-z0-9_\\.\\-]+)(\\:)([a-z0-9_\\.\\-\\/]+)(?= *[\\,\\]\\n])", + captures: { + 1: { + name: "entity.name.function.mcfunction", + }, + 2: { + name: "entity.name.function.mcfunction", + }, + 3: { + name: "entity.name.function.mcfunction", + }, + }, + }, + "selector.argument.tagged_resource_location": { + name: "meta.selector.argument.tagged_resource_location.mcfunction", + match: "(\\#)([a-z0-9_\\.\\-]+)(\\:)([a-z0-9_\\.\\-\\/]+)(?= *[\\,\\]\\n])", + captures: { + 1: { + name: "entity.name.function.mcfunction", + }, + 2: { + name: "entity.name.function.mcfunction", + }, + 3: { + name: "entity.name.function.mcfunction", + }, + 4: { + name: "entity.name.function.mcfunction", + }, + }, + }, + "selector.argument.range": { + name: "meta.selector.argument.range.mcfunction", + match: "(\\-?\\d*\\.?\\d+)?(\\.\\.)(\\-?\\d*\\.?\\d+)?(?= *[\\,\\]\\n])", + captures: { + 1: { + name: "constant.numeric.mcfunction", + }, + 2: { + name: "keyword.control.mcfunction", + }, + 3: { + name: "constant.numeric.mcfunction", + }, + }, + }, + "selector.argument.number": { + name: "meta.selector.argument.number.mcfunction", + match: "(\\-?\\d*\\.?\\d+)(?= *[\\,\\]\\n])", + captures: { + 1: { + name: "constant.numeric.mcfunction", + }, + }, + }, + "selector.argument.boolean": { + name: "meta.selector.argument.boolean.mcfunction", + match: "(true|false)(?= *[\\,\\]\\n])", + captures: { + 1: { + name: "constant.numeric.mcfunction", + }, + }, + }, + "selector.argument.unquoted_string": { + name: "meta.selector.argument.unquoted_string.mcfunction", + match: "([^\\s\\{\\}\\[\\]\\,\\:\\=\\!]+)(?= *[\\,\\]\\n])", + captures: { + 1: { + name: "string.unquoted.mcfunction", + }, + }, + }, + "selector.argument.unknown": { + name: "meta.selector.argument.unknown.mcfunction", + match: "([^\\]\\n\\,]+)", + captures: { + 1: { + name: "invalid.illegal.mcfunction", + }, + }, + }, + "selector.argument.quoted_string": { + name: "meta.selector.argument.quoted_string.mcfunction", + begin: '(\\")', + end: '(?=\\n)|(\\") *([^\\]\\,\\n]*)', + beginCaptures: { + 1: { + name: "string.quoted.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "string.quoted.mcfunction", + }, + 2: { + name: "invalid.illegal.mcfunction", + }, + }, + patterns: [ + { + include: "#common.quoted_string", + }, + ], + }, + "selector.argument.single_quoted_string": { + name: "meta.selector.argument.single_quoted_string.mcfunction", + begin: "(\\')", + end: "(?=\\n)|(\\') *([^\\]\\,\\n]*)", + beginCaptures: { + 1: { + name: "string.quoted.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "string.quoted.mcfunction", + }, + 2: { + name: "invalid.illegal.mcfunction", + }, + }, + patterns: [ + { + include: "#common.single_quoted_string", + }, + ], + }, + "selector.argument.property_map": { + name: "meta.selector.argument.property_map.mcfunction", + begin: "(\\{)(?= *([a-z0-9_\\.\\-]+\\:[a-z0-9_\\.\\-\\/]+|[a-z0-9_\\.\\-\\/]+|([A-Za-z0-9_\\.\\-]+)) *(\\=))", + end: "(?=\\n)|(\\}) *([^\\]\\,\\n]*)", + beginCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + 2: { + name: "invalid.illegal.mcfunction", + }, + }, + patterns: [ + { + include: "#property_map", + }, + ], + }, + "selector.argument.nbt_compound": { + name: "meta.selector.argument.nbt_compound.mcfunction", + begin: "(\\{)", + end: "(?=\\n)|(\\}) *([^\\]\\,\\n]*)", + beginCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + 2: { + name: "invalid.illegal.mcfunction", + }, + }, + patterns: [ + { + include: "#nbt.compound", + }, + ], + }, + property_map: { + patterns: [ + { + match: " +", + }, + { + begin: "(,)? *([A-Za-z0-9_\\.\\-]+) *(\\=) *", + end: " *(?=[\\n\\}\\,])", + beginCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + 2: { + name: "entity.name.function.mcfunction", + }, + 3: { + name: "variable.language.mcfunction", + }, + }, + patterns: [ + { + include: "#property_map.values", + }, + ], + }, + { + begin: "(,)? *([a-z0-9_\\.\\-]+\\:[a-z0-9_\\.\\-\\/]+|[a-z0-9_\\.\\-\\/]+) *(\\=) *", + end: " *(?=[\\n\\}\\,])", + beginCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + 2: { + name: "entity.name.function.mcfunction", + }, + 3: { + name: "variable.language.mcfunction", + }, + }, + patterns: [ + { + include: "#property_map.values", + }, + ], + }, + { + match: "[^\\n\\}\\,]+", + name: "invalid.illegal.mcfunction", + }, + ], + }, + "property_map.values": { + patterns: [ + { + match: "(true|false)", + captures: { + 1: { + name: "constant.numeric.mcfunction", + }, + }, + }, + { + match: "(\\-?\\d*\\.?\\d+)?(\\.\\.)(\\-?\\d*\\.?\\d+)?", + captures: { + 1: { + name: "constant.numeric.mcfunction", + }, + 2: { + name: "keyword.control.mcfunction", + }, + 3: { + name: "constant.numeric.mcfunction", + }, + }, + }, + { + match: "(\\-?\\d*\\.?\\d+)", + captures: { + 1: { + name: "constant.numeric.mcfunction", + }, + }, + }, + { + begin: "(\\{) *", + end: "(?=\\n)|(\\}) *([^\\}\\,\\n]*)", + beginCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + }, + endCaptures: { + 1: { + name: "variable.language.mcfunction", + }, + 2: { + name: "invalid.illegal.mcfunction", + }, + }, + patterns: [ + { + include: "#property_map", + }, + ], + }, + ], + }, + "common.quoted_string": { + patterns: [ + { + match: '[^\\\\\\"\\n]', + name: "string.quoted.mcfunction", + }, + { + match: "\\\\[^\\n]", + name: "constant.character.escape.mcfunction", + }, + { + match: "\\\\", + name: "invalid.illegal.mcfunction", + }, + ], + }, + "common.single_quoted_string": { + patterns: [ + { + match: "[^\\\\\\'\\n]", + name: "string.quoted.mcfunction", + }, + { + match: "\\\\[^\\n]", + name: "constant.character.escape.mcfunction", + }, + { + match: "\\\\", + name: "invalid.illegal.mcfunction", + }, + ], + }, + }, +}; \ No newline at end of file diff --git a/src/utils/mcscript-grammar.ts b/src/utils/mcscript-grammar.ts new file mode 100644 index 0000000..0eec285 --- /dev/null +++ b/src/utils/mcscript-grammar.ts @@ -0,0 +1,87 @@ +import type { LanguageInput } from "shiki"; + +export const mcscriptGrammar: LanguageInput = { + name: "mcscript", + aliases: [], + displayName: "mcscript", + fileTypes: ["mcscript"], + scopeName: "source.mcscript", + patterns: [ + { + name: "comment.line.double-slash.mcscript", + match: "//.*", + }, + { + name: "comment.line.hash.mcscript", + match: "\\s*#.*", + }, + { + name: "constant.numeric.mcscript", + match: "\\b[0-9\\.\\-]+\\b", + }, + { + name: "entity.name.command.mcscript", + match: "\\b(?:advancement|ban|banlist|data|clear|clone|debug|defaultgamemode|deop|difficulty|effect|execute|experience|fill|function|gamemode|gamerule|give|help|kick|kill|list|locate|me|msg|op|pardon|pardon-ip|particle|playsound|publish|recipe|reload|replaceitem|save-all|save-off|save-on|say|scoreboard|seed|setblock|setidletimeout|setworldspawn|spawnpoint|spreadplayers|stop|stopsound|summon|tag|team|teleport|tell|tellraw|time|title|trigger|weather|whitelist|worldborder|xp)\\b", + }, + { + name: "keyword.control.mcscript", + match: "\\b(?:if|then|else|unless|true|false|as|at|asat|positioned|align|dimension|rotated|anchored|while|do|forEach|for|raycast|stop|continue|switch|case|default|var|bool|boolean|tag|score|const)\\b", + }, + { + name: "keyword.operator.mcscript", + match: "(\\=|\\+\\=|\\-\\=|\\*\\=|\\/\\=|\\%\\=|\\+\\+|\\-\\-|\\*|\\/|\\+|\\-|\\%|\\>|\\<|\\>\\=|\\<\\=)", + }, + { + name: "keyword.operator.file.mcscript", + match: "(\\s*#file:|\\s*#extend:)(\\s+)([\\w\\d$\\/\\._-]*)", + }, + { + name: "string.quoted.double.mcscript", + match: '"(?:[^\\\\]|\\\\.)*?"', + }, + { + name: "string.quoted.single.mcscript", + match: "'(?:[^\\\\]|\\\\.)*?'", + }, + { + name: "variable.mcscript", + match: "(\\$[\\w\\-]*)", + }, + { + name: "support.function.entity.mcscript", + match: "\\b(?:@a|@p|@s|@r|@e)\\b", + }, + { + name: "support.type.entity.mcscript", + match: "\\b(?:area_effect_cloud|armor_stand|arrow|bat|blaze|boat|cave_spider|chest_minecart|chicken|cod_mob|commandblock_minecart|cow|creeper|dolphin|donkey|dragon_fireball|drowned|egg|elder_guardian|ender_crystal|ender_dragon|ender_pearl|enderman|endermite|evocation_fangs|evocation_illager|eye_of_ender_signal|falling_block|fireball|fireworks_rocket|furnace_minecart|ghast|giant|guardian|hopper_minecart|horse|husk|illusion_illager|item|item_frame|leash_knot|lightning_bolt|llama|llama_spit|magma_cube|minecart|mooshroom|mule|ocelot|painting|parrot|phantom|pig|polar_bear|potion|puffer_fish|rabbit|salmon_mob|sheep|shulker|shulker_bullet|silverfish|skeleton|skeleton_horse|slime|small_fireball|snowball|snowman|spawner_minecart|spectral_arrow|spider|squid|stray|tnt|tnt_minecart|trident|tropical_fish|turtle|vex|villager|villager_golem|vindication_illager|witch|wither|wither_skeleton|wither_skull|wolf|xp_bottle|xp_orb|zombie|zombie_horse|zombie_pigman|zombie_villager)\\b", + }, + ], + repository: { + "$base": {}, + "$self": {}, + command: { + name: "entity.name.command.mcscript", + match: "\\/\\b(?:command1|command2|...)\\b", + }, + keyword: { + name: "keyword.control.mcscript", + match: "\\b(?:if|else|...)\\b", + }, + operator: { + name: "keyword.operator.mcscript", + match: "(\\+|\\-|\\*|\\/|...)", + }, + string: { + patterns: [ + { + name: "string.quoted.double.mcscript", + match: '"(?:[^\\\\]|\\\\.)*?"', + }, + { + name: "string.quoted.single.mcscript", + match: "'(?:[^\\\\]|\\\\.)*?'", + }, + ], + }, + }, +}; diff --git a/src/utils/shiki.ts b/src/utils/shiki.ts index 7b94868..58182df 100644 --- a/src/utils/shiki.ts +++ b/src/utils/shiki.ts @@ -1,9 +1,12 @@ -import type { PluginShikiOptions } from "@astrojs/starlight/expressive-code"; import { shulkerscriptGrammar } from "./shulkerscript-grammar"; +import { mcfunctionGrammar } from "./mcfunction-grammar"; +import { mcscriptGrammar } from "./mcscript-grammar"; -const config: PluginShikiOptions = { +const config = { langs: [ shulkerscriptGrammar, + mcfunctionGrammar, + mcscriptGrammar, ], }; diff --git a/src/utils/shulkerscript-grammar.ts b/src/utils/shulkerscript-grammar.ts index f23caae..409a7d8 100644 --- a/src/utils/shulkerscript-grammar.ts +++ b/src/utils/shulkerscript-grammar.ts @@ -1,5 +1,6 @@ +import type { LanguageInput } from "shiki"; -export const shulkerscriptGrammar = { +export const shulkerscriptGrammar: LanguageInput = { name: "shulkerscript", aliases: ["shu"], displayName: "ShulkerScript", @@ -23,6 +24,8 @@ export const shulkerscriptGrammar = { } ], repository: { + "$base": {}, + "$self": {}, // Groupings functionContents: { patterns: [