Skip to content

Added syntax support for .mcfunction files (Minecraft functions)#3953

Open
BuriXon-code wants to merge 3 commits into
micro-editor:masterfrom
BuriXon-code:master
Open

Added syntax support for .mcfunction files (Minecraft functions)#3953
BuriXon-code wants to merge 3 commits into
micro-editor:masterfrom
BuriXon-code:master

Conversation

@BuriXon-code
Copy link
Copy Markdown

Pull Request: Add mcfunction Syntax Highlighting

Summary

This PR adds syntax highlighting support for Minecraft .mcfunction files in Micro editor.
It provides better readability for datapack and command development, including commands, selectors, effects, JSON-like arguments, and numbers.

Features

  • Commands (effect, execute, give, tp, scoreboard, etc.) highlighted as statements
  • Subcommands / operators (run, if, matches, modify, etc.) highlighted separately
  • Selectors (@s, @e, @a) clearly highlighted
  • Minecraft namespaces (minecraft:wither, minecraft:stone) highlighted as identifiers
  • Numbers and boolean values (true, false) highlighted
  • Dangerous commands (kill @e, tp @e, clear @a, etc.) highlighted as error (screaming red in most colorschemes)
  • JSON-like arguments ({"text":"Hello","color":"red"}) highlighted for better readability

Motivation

  • Micro lacks built-in support for .mcfunction files
  • Developers editing Minecraft datapacks, functions, and command scripts in Micro will benefit from immediate visual feedback
  • Dangerous commands and important effects are visually emphasized to prevent mistakes

Testing / Examples

Example mcfunction snippet highlighting all token types:

effect give @s minecraft:wither 5 1 true  
execute if score @s weapon_random matches 25 run item modify entity @s weapon.mainhand murder_weapon:mark25  
kill @e[type=zombie]
  • effect → statement
  • give → subcommand
  • @s → selector
  • minecraft:wither → identifier
  • Numbers (5 1) → numbers
  • true → boolean / constant
  • Dangerous commands (kill @e) → error / red

Notes

  • Only .mcfunction syntax is added
  • No changes to Micro core functionality or existing syntax files

@Jenny-hso
Copy link
Copy Markdown

I would not recommend highlighting commands like kill or clear as errors, as they are not invalid on their own.

In my opinion, special is going to work better, as they are "not really like the other ones" indeed.

@BuriXon-code
Copy link
Copy Markdown
Author

BuriXon-code commented May 16, 2026

The commands kill @e, kill @a, which may be dangerous, are highlighted as error.
This only applies to commands with @a or @e added.
They are correct, but I thought their use might be unwanted, accidental, etc.
I personally thought this might be interesting/useful. Anyone who writes datapacks knows how it works.

If it's a really big problem, I'll remove it. If it's just aesthetics, let it stay.

@Jenny-hso
Copy link
Copy Markdown

Oh, okay then, I see no problem with it!

Copy link
Copy Markdown

@Jenny-hso Jenny-hso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reviewed the syntax file and have a couple of suggestions:

  1. I'm not quite sure whether that was an intended behaviour or not, but the rules order make tokens appear highlighted even if they are placed inside comments
Image

Additinally, the kill command will appear highlighted as a command, even if it's a part of kill @p. I suggest placing error rules in bottom of all other rules, then consant.string, and then comment

With such approach, everything will be highlighted correctly:

Image
  1. The conventional rules for string and numeric literals and the ones that I recommend using are constant.string and constant.numeric instead of string and numeric. AFAIK, string and numeric are not supported by any colorscheme. Plus, you may consider changing the rule for the boolean literals to constant.bool
Image

@BuriXon-code
Copy link
Copy Markdown
Author

oh, okay.. I see problems.
I won't be working on it today as I'm a bit short on time, but I'll get to it soon!
Thank you!

@BuriXon-code
Copy link
Copy Markdown
Author

@Jenny-hso check now :))

Comment thread runtime/syntax/mcfunction.yaml Outdated
Comment on lines +13 to +14
# === DANGEROUS COMMANDS ===
- error: "^\\s*(kill|tp|teleport)\\s+@([ae])(\\s|$).*$"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one seems to have no effect, as it is repeated on lines 49-50. I suggest to remove it completely, while leaving the one at lines 49-50 untouched

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That junk on lines 13 and 14 is artifacts, sorry. I copied it from place to place and didn't clean it up.

I corrected numerical to number.

It should be ok :))
Thank you.


# === SYMBOLS ===
- symbol: "[{}\\[\\](),=]"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A blank line. Not critical, but a tiny little bit weird

Comment thread runtime/syntax/mcfunction.yaml Outdated
- error: "^\\s*(kill|tp|teleport)\\s+@([ae])(\\s|$).*$"

# === CONSTANTS ===
- constant.numeric: "\\b-?[0-9]+(?:\\.[0-9]+)?\\b"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being misleading in my previous review, actually the convenient rule is constant.number😅😅😅

Suggested change
- constant.numeric: "\\b-?[0-9]+(?:\\.[0-9]+)?\\b"
- constant.number: "\\b-?[0-9]+(?:\\.[0-9]+)?\\b"

BTW if change constant.numeric to constant.number, it works perfectly. I really like this change

IMG_20260518_125643.jpg

@Jenny-hso
Copy link
Copy Markdown

Everything seems okay now! I like it

@BuriXon-code
Copy link
Copy Markdown
Author

banner.gif

looks gorgeous!

Thanks for your help :)
You can also check out my profile -> there are more micro toys there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants