diff --git a/syntaxes/mcfunction.sublime-syntax b/syntaxes/mcfunction.sublime-syntax new file mode 100644 index 0000000..3956bd8 --- /dev/null +++ b/syntaxes/mcfunction.sublime-syntax @@ -0,0 +1,289 @@ +%YAML 1.2 +--- +# The following syntax definition is based on: +# https://github.com/MinecraftCommands/syntax-mcfunction/tree/51eb8bf4ca04355bb89f5538b7331cb0c0f3df2b + +name: mcfunction +file_extensions: [mcfunction] +scope: source.mcfunction + +contexts: + main: + - include: root + comments: + - match: '^\s*(#[>!#])(.+)$' + captures: + "1": comment.block.mcfunction + "2": markup.bold.mcfunction + push: + - meta_scope: meta.comments + - include: comments_block + - match: ^(?!#) + pop: true + - match: ^\s*#.*$ + scope: meta.comments + captures: + "0": comment.line.mcfunction + comments_block: + - match: '^\s*#[>!]' + push: + - meta_scope: meta.comments_block + - include: comments_block_emphasized + - match: $ + pop: true + - match: '^\s*#' + push: + - meta_scope: meta.comments_block + - include: comments_block_normal + - match: $ + pop: true + comments_block_emphasized: + - include: comments_block_special + - match: \S+ + scope: meta.comments_block_emphasized + captures: + "0": markup.bold.mcfunction + comments_block_normal: + - include: comments_block_special + - match: \S+ + scope: meta.comments_block_normal + captures: + "0": comment.block.mcfunction + comments_block_special: + - match: '@\S+' + scope: meta.comments_block_special + captures: + "0": markup.heading.mcfunction + - include: resource-name + - match: "[#%$][A-Za-z0-9_.#%$]+" + scope: meta.comments_block_special + captures: + "0": variable.other.mcfunction + comments_inline: + - match: "#.*$" + scope: meta.comments + captures: + "0": comment.line.mcfunction + literals: + - match: \b(true|false|True|False)\b + scope: meta.literals + captures: + "0": constant.numeric.boolean.mcfunction + - match: '\b[0-9a-fA-F]+(?:-[0-9a-fA-F]+){4}\b' + scope: meta.names + captures: + "0": variable.uuid.mcfunction + - match: '[+-]?\d*\.?\d+([eE]?[+-]?\d+)?[df]?\b' + scope: meta.literals + captures: + "0": constant.numeric.float.mcfunction + - match: '[+-]?\d+(b|B|L|l|s|S)?\b' + scope: meta.literals + captures: + "0": constant.numeric.integer.mcfunction + - match: \.\. + scope: meta.ellipse.literals + captures: + "0": variable.other.mcfunction + - match: '"' + push: + - meta_scope: string.quoted.double.mcfunction + - include: literals_string-double + - match: '"' + pop: true + - match: "'" + push: + - meta_scope: string.quoted.single.mcfunction + - include: literals_string-single + - match: "'" + pop: true + literals_string-double: + - match: \\. + scope: meta.literals_string-double + captures: + "0": constant.character.escape.mcfunction + - match: \\ + scope: meta.literals_string-double + captures: + "0": constant.character.escape.mcfunction + - include: macro-name + - match: '[^\\"]' + scope: meta.literals_string-double + captures: + "0": string.quoted.double.mcfunction + literals_string-single: + - match: \\. + scope: meta.literals_string-single + captures: + "0": constant.character.escape.mcfunction + - match: \\ + scope: meta.literals_string-double + captures: + "0": constant.character.escape.mcfunction + - include: macro-name + - match: '[^\\'']' + scope: meta.literals_string-single + captures: + "0": string.quoted.single.mcfunction + macro-name: + - match: '(\$\()([A-Za-z0-9_]*)(\))' + scope: meta.macro-name + captures: + "1": punctuation.definition.template-expression.begin.mcfunction + "2": variable.other.mcfunction + "3": punctuation.definition.template-expression.end.mcfunction + names: + - match: '^(\s*)([a-z_]+)(?=\s)' + scope: meta.names + captures: + "1": whitespace.mcfunction + "2": keyword.control.flow.mcfunction + - match: '^(\s*)(\$)( ?)([a-z_]*)' + scope: meta.names + captures: + "1": whitespace.mcfunction + "2": markup.italic.mcfunction + "3": whitespace.mcfunction + "4": keyword.control.flow.mcfunction + - match: '(run)(\s+)([a-z_]+)' + scope: meta.names + captures: + "1": entity.name.mcfunction + "2": whitespace.mcfunction + "3": keyword.control.flow.mcfunction + - include: resource-name + - match: '[A-Za-z]+(?=\W)' + scope: meta.names + captures: + "0": entity.name.mcfunction + - match: "[A-Za-z_][A-Za-z0-9_.#%$]*" + scope: meta.names + captures: + "0": string.unquoted.mcfunction + - include: macro-name + - match: '([#%$]|((?<=\s)\.))[A-Za-z0-9_.#%$\-]+' + scope: meta.names + captures: + "0": variable.other.mcfunction + operators: + - match: "[~^]" + scope: meta.operators + captures: + "0": constant.numeric.mcfunction + - match: '[\-%?!+*<>\\/|&=.:,;]' + scope: meta.operators + captures: + "0": keyword.operator.mcfunction + property: + - match: '\{' + push: + - meta_scope: meta.property.curly + - include: resource-name + - include: literals + - include: property_key + - include: operators + - include: property_value + - include: main + - match: '\}' + pop: true + - match: '\[' + push: + - meta_scope: meta.property.square + - include: resource-name + - include: literals + - include: property_key + - include: operators + - include: property_value + - include: main + - match: '\]' + pop: true + - match: \( + push: + - meta_scope: meta.property.paren + - include: resource-name + - include: literals + - include: property_key + - include: operators + - include: property_value + - include: main + - match: \) + pop: true + property_key: + - match: '#?[a-z_][a-z_\.\-]*\:[a-z0-9_\.\-/]+(?=\s*\=:)' + scope: meta.property_key + captures: + "0": variable.other.mcfunction + - match: '#?[a-z_][a-z0-9_\.\-/]+' + scope: meta.property_key + captures: + "0": variable.other.mcfunction + - match: '[A-Za-z_]+[A-Za-z_\-\+]*' + scope: meta.property_key + captures: + "0": variable.other.mcfunction + property_value: + - match: '#?[a-z_][a-z_\.\-]*\:[a-z0-9_\.\-/]+' + scope: meta.property_value + captures: + "0": string.unquoted.mcfunction + - match: '#?[a-z_][a-z0-9_\.\-/]+' + scope: meta.property_value + captures: + "0": string.unquoted.mcfunction + resource-name: + - match: "#?[a-z_][a-z0-9_.-]*:[a-z0-9_./-]+" + scope: meta.resource-name + captures: + "0": entity.name.function.mcfunction + - match: '#?[a-z0-9_\.\-]+\/[a-z0-9_\.\-\/]+' + scope: meta.resource-name + captures: + "0": entity.name.function.mcfunction + root: + - include: literals + - include: comments + - include: say + - include: names + - include: comments_inline + - include: subcommands + - include: property + - include: operators + - include: selectors + say: + - match: ^(\s*)(say) + captures: + "1": whitespace.mcfunction + "2": keyword.control.flow.mcfunction + push: + - meta_scope: meta.say.mcfunction + - match: \n + pop: true + - match: \\\s*\n + captures: + "0": constant.character.escape.mcfunction + - include: literals_string-double + - include: literals_string-single + - match: (run)(\s+)(say) + captures: + "1": entity.name.mcfunction + "2": whitespace.mcfunction + "3": keyword.control.flow.mcfunction + push: + - meta_scope: meta.say.mcfunction + - match: \n + pop: true + - match: \\\s*\n + captures: + "0": constant.character.escape.mcfunction + - include: literals_string-double + - include: literals_string-single + selectors: + - match: "@[a-z]+" + scope: meta.selectors + captures: + "0": support.class.mcfunction + subcommands: + - match: "[a-z_]+" + scope: meta.literals + captures: + "0": entity.name.class.mcfunction