Home

Awesome

language-mcfunction

Language grammars and syntax highlighting for mcfunction files.

github-license-badge vscode-version-badge discord-chat-badge

This project provides two types of grammars: the default, version-agnostic grammar (shown below), and WIP version-specific grammars.

Showcase

Install

Installing the VSCode extension

The extension language-mcfunction is available from the Marketplace: https://marketplace.visualstudio.com/items?itemName=arcensoth.language-mcfunction

Installing the SublimeText package

It is recommended you use Package Control to manage the package:

  1. Install Package Control if it is not already present.
  2. Run the Package Control: Add Repository command and enter https://github.com/Arcensoth/language-mcfunction to add the repository as a package.
  3. Run the Package Control: Install Package and search for language-mcfunction to install it as you would a normal package.

This will keep the package updated with the repository automatically.

Otherwise you can clone the repository into user packages (e.g. %appdata%\Sublime Text 3\Packages) and update it manually.

Features

Syntax highlighting

Here's an album with everything below.

Custom block comments

It's common for datapack developers to comment parts of their code with things like headings, parameters, return values, etc. To support these patterns for those who wish to use them, the grammar implements custom block comments. These types of comments are gated behind a vanilla-compatible alternate comment style.

The prefix #> can be used to initiate a block comment:

#> This is a block heading
# All adjacent comments will be considered part of the block.
#
# So long as you keep comments attached, they will remain part of the block.

# This line no longer attached to the block.

#> But we can start a new block here!

Click here for a detailed example.

As of writing there is no documentation standard, however the grammar has the capacity to support this via block comments and alternate comment styles.

Configure

Configuring the version-agnostic grammar

This is a generic "version-agnostic" grammar that does not target any particular version of Minecraft. As a result it may not be as accurate as version-specific grammars, however it will continue to work for multiple versions of the game.

The version-agnostic mcfunction language should be active by default. It provides a decent fallback for otherwise unsupported versions of Minecraft. In order to do this, it must not assume any particular version. Because it cannot assume a version, it cannot provide context-sensitive highlighting.

In the future, the version-specific grammars will be preferred when available.

Configuring the version-specific grammars

The version-specific grammars are currently under heavy development. These grammars are incomplete and experimental. They do not yet support the same feature set as the version-agnostic grammar. Please only use these grammars if you intend to contribute in some form, such as pull requests, bug reports, or general feedback. To use the version-specific grammars, you will need to build them and configure the extension yourself.

The version-specific grammars are partially generated based on Minecraft's generated data, which is available for Minecraft versions 1.13 and higher. They have context-sensitive highlighting and command validation comparable to the in-game command bar.

In VSCode, you can easily choose which version of mcfunction to use by changing the .mcfunction extension association in your workspace settings:

"files.associations": {
  "*.mcfunction": "mcfunction-snapshot"
}

This option can also be set on the user-level in settings.json or folder-level in .vscode/settings.json.

Customize

Currently available for the version-specific grammars.

Scopes have been assigned with user customization in mind. If your editor allows scope overrides, this will make it easy to customize your own colours for a variety of scopes.

Customizing errors

Short nameFull scope nameExamples
invalidinvalid.illegal._.invalid.mcfunctionexecute (foo)
underlinemarkup.underline._.underline.mcfunctionexecute (foo)

Customizing comments

Short nameFull scope nameExamples
comment.plaincomment._.plain.comment.mcfunction(# This is a plain comment)
comment.blockcomment.block._.block.comment.mcfunction(#> This is part of a block comment)
comment.block.symbolmarkup.list._.symbol.block.comment.mcfunction(#)> This is part of a block comment
comment.block.prefixmarkup.list._.prefix.block.comment.mcfunction#(>) This is part of a block comment
comment.block.heading_1markup.bold._.heading_1.block.comment.mcfunction#> (This is part of a block comment)
comment.block.heading_2markup.list._.heading_2.block.comment.mcfunction#> (This is part of a block comment)
comment.block.annotation.labelmarkup.heading._.label.annotation.block.comment.mcfunction#> (@annotation) some annotation
comment.block.annotation.textcomment.block._.text.annotation.block.comment.mcfunction#> @annotation (some annotation)

Customizing commands

Short nameFull scope nameExamples
commandkeyword.control._.command.mcfunction(execute) as @a run (function)
subcommandkeyword.other._.subcommand.mcfunctionexecute (as) @a (run) function
command.slashkeyword.control._.command.mcfunction/

Customizing selectors

Short nameFull scope nameExamples
target_selector.basesupport.class._.base.target_selector.mcfunction@a
target_selector.bracketsupport.class._.bracket.target_selector.mcfunction[]
target_selector.equalssupport.class._.equals.target_selector.mcfunction=
target_selector.commasupport.class._.comma.target_selector.mcfunction,
target_selector.notconstant.character.escape._.not.target_selector.mcfunction!
target_selector.paramkeyword.other._.param.target_selector.mcfunctiontag / type
score_map.bracketstorage._.bracket.score_map.mcfunction{}
score_map.equalsstorage._.equals.score_map.mcfunction=
score_map.commastorage._.comma.score_map.mcfunction,
advancement_map.bracketstorage._.bracket.advancement_map.mcfunction{}
advancement_map.equalsstorage._.equals.advancement_map.mcfunction=
advancement_map.commastorage._.comma.advancement_map.mcfunction,

Customizing NBT

Short nameFull scope nameExamples
nbt_compound.bracketstorage._.bracket.nbt_compound.mcfunction{}
nbt_compound.colonstorage._.colon.nbt_compound.mcfunction:
nbt_compound.commastorage._.comma.nbt_compound.mcfunction,
nbt_list.bracketstorage._.bracket.nbt_list.mcfunction[]
nbt_list.commastorage._.comma.nbt_list.mcfunction,

Customizing NBT paths

Short nameFull scope nameExamples
nbt_path.propertystring._.property.nbt_path.mcfunction(RecordItem)
nbt_path.dotstorage._.dot.nbt_path.mcfunctionRecordItem(.)tag
nbt_path.compound.bracketstorage._.bracket.compound.nbt_path.mcfunctionSelectedItem({)(})
nbt_path.index.bracketstorage._.bracket.index.nbt_path.mcfunctionInventory([)(])

Customizing text components

Short nameFull scope nameExamples
text_component.bracketstorage._.bracket.text_component.mcfunction{}[]
text_component.colonstorage._.colon.text_component.mcfunction:
text_component.commastorage._.comma.text_component.mcfunction,
text_component.propertystring._.property.text_component.mcfunctiontext / color / selector
text_component.property.colorstring._.color.property.text_component.mcfunctionred / green / blue
text_component.property.keybindstring._.keybind.property.text_component.mcfunctionkey.drop / key.use
text_component.property.eventstring._.event.property.text_component.mcfunctionrun_command / show_text

Customizing resource locations

Short nameFull scope nameExamples
resource_location.namespaceentity.name.function._.namespace.resource_location.mcfunction(mypack):some/resource
resource_location.colonentity.name.function._.colon.resource_location.mcfunctionmypack(:)some/resource
resource_location.pathentity.name.function._.path.resource_location.mcfunctionmypack:(some/resource)
tagged_resource_location.hashentity.name.function._.hash.tagged_resource_location.mcfunction(#)mypack:some/resource
tagged_resource_location.namespaceentity.name.function._.namespace.tagged_resource_location.mcfunction#(mypack):some/resource
tagged_resource_location.colonentity.name.function._.colon.tagged_resource_location.mcfunction#mypack(:)some/resource
tagged_resource_location.pathentity.name.function._.path.tagged_resource_location.mcfunction#mypack:(some/resource)

Customizing strings

Short nameFull scope nameExamples
stringstring._.string.mcfunction("hello world")
string_escapeconstant.character.escape._.string_escape.mcfunction"hello(\n)newline"
wordstring._.word.mcfunctionfoo / foo_bar
keywordkeyword._.word.mcfunctionnearest / creative

Customizing numbers

Short nameFull scope nameExamples
numberconstant.numeric._.number.mcfunction0 / 123 / -99
range.minimumconstant.numeric._.minimum.range.mcfunction(10)..20
range.maximumconstant.numeric._.maximum.range.mcfunction10..(20)
range.ellipsiskeyword.control._.ellipsis.range.mcfunction10(..)20
position.absolute.numberconstant.numeric._.number.absolute.position.mcfunction(10) ~20 (30)
position.relative.operatorkeyword.control._.operator.relative.position.mcfunction10 (~)20 30
position.relative.numberconstant.numeric._.number.relative.position.mcfunction10 ~(20) 30
position.local.operatorkeyword.control._.operator.local.position.mcfunction(^)10 (^)20 (^)30
position.local.numberconstant.numeric._.number.local.position.mcfunction^(10) ^(20) ^(30)

Customizing tags, teams, and objectives

Short nameFull scope nameExamples
entity_tagentity.other.attribute-name._.entity_tag.mcfunctionmypack.some.tag
scoreboard_team entity.other.attribute-name._.scoreboard_team.mcfunctionmypack.blue
scoreboard_objectiveentity.other.attribute-name._.scoreboard_objective.mcfunctionmypack.points
score_holder.allsupport.class._.all.score_holder.mcfunction*
score_holder.fakeplayer support.class._.fakeplayer.score_holder.mcfunction#temp / $mypack.calc

Other customizable scopes

Short nameFull scope nameExamples
booleanconstant.numeric._.boolean.mcfunctiontrue / false
entity_anchorconstant.numeric._.entity_anchor.mcfunctioneyes / feet
swizzleconstant.numeric._.swizzle.mcfunctiony / xz / xyz
target.uuidsupport.class._.uuid.target.mcfunctionf7a39418-72ca-4bf2-bc7e-ba9df67a4707 / 0-0-0-0-0
target.player_namesupport.class._.uuid.target.mcfunctionArcensoth / some_guy
generic.dict.bracketstorage._.bracket.dict.generic.mcfunction({) key: value (})
generic.dict.contentstring._.content.dict.generic.mcfunction{( key: value )}
generic.list.bracketstorage._.bracket.list.generic.mcfunction([) item, item (])
generic.list.contentstring._.content.list.generic.mcfunction[( item, item )]

Contribute

Contributions are welcome; see CONTRIBUTING.md.

Resources