mirror of
https://github.com/alecthomas/chroma.git
synced 2025-03-19 21:10:15 +02:00
Add mcfunction lexer
This commit is contained in:
parent
59126c5b32
commit
c49d52b472
107
lexers/m/mcfunction.go
Normal file
107
lexers/m/mcfunction.go
Normal file
@ -0,0 +1,107 @@
|
||||
package m
|
||||
|
||||
import (
|
||||
. "github.com/alecthomas/chroma" // nolint
|
||||
"github.com/alecthomas/chroma/lexers/internal"
|
||||
)
|
||||
|
||||
// mcfunction lexer.
|
||||
var MCFunction = internal.Register(MustNewLexer(
|
||||
&Config{
|
||||
Name: "mcfunction",
|
||||
Aliases: []string{"mcfunction"},
|
||||
Filenames: []string{"*.mcfunction"},
|
||||
MimeTypes: []string{},
|
||||
NotMultiline: true,
|
||||
DotAll: true,
|
||||
},
|
||||
Rules{
|
||||
"simplevalue": {
|
||||
{`(true|false)`, KeywordConstant, nil},
|
||||
{`[01]b`, LiteralNumber, nil},
|
||||
{`-?(0|[1-9]\d*)(\.\d+[eE](\+|-)?\d+|[eE](\+|-)?\d+|\.\d+)`, LiteralNumberFloat, nil},
|
||||
{`(-?\d+)(\.\.)(-?\d+)`, ByGroups(LiteralNumberInteger, Punctuation, LiteralNumberInteger), nil},
|
||||
{`-?(0|[1-9]\d*)`, LiteralNumberInteger, nil},
|
||||
{`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
|
||||
{`'[^']+'`, LiteralStringSingle, nil},
|
||||
{`([!#]?)(\w+)`, ByGroups(Punctuation, Text), nil},
|
||||
},
|
||||
"nbtobjectattribute": {
|
||||
Include("nbtvalue"),
|
||||
{`:`, Punctuation, nil},
|
||||
{`,`, Punctuation, Pop(1)},
|
||||
{`\}`, Punctuation, Pop(2)},
|
||||
},
|
||||
"nbtobjectvalue": {
|
||||
{`("(\\\\|\\"|[^"])*"|[a-zA-Z0-9_]+)`, NameTag, Push("nbtobjectattribute")},
|
||||
{`\}`, Punctuation, Pop(1)},
|
||||
},
|
||||
"nbtarrayvalue": {
|
||||
Include("nbtvalue"),
|
||||
{`,`, Punctuation, nil},
|
||||
{`\]`, Punctuation, Pop(1)},
|
||||
},
|
||||
"nbtvalue": {
|
||||
Include("simplevalue"),
|
||||
{`\{`, Punctuation, Push("nbtobjectvalue")},
|
||||
{`\[`, Punctuation, Push("nbtarrayvalue")},
|
||||
},
|
||||
"argumentvalue": {
|
||||
Include("simplevalue"),
|
||||
{`,`, Punctuation, Pop(1)},
|
||||
{`[}\]]`, Punctuation, Pop(2)},
|
||||
},
|
||||
"argumentlist": {
|
||||
{`(nbt)(={)`, ByGroups(NameAttribute, Punctuation), Push("nbtobjectvalue")},
|
||||
{`([A-Za-z0-9/_!]+)(={)`, ByGroups(NameAttribute, Punctuation), Push("argumentlist")},
|
||||
{`([A-Za-z0-9/_!]+)(=)`, ByGroups(NameAttribute, Punctuation), Push("argumentvalue")},
|
||||
Include("simplevalue"),
|
||||
{`,`, Punctuation, nil},
|
||||
{`[}\]]`, Punctuation, Pop(1)},
|
||||
},
|
||||
"root": {
|
||||
{`#.*?\n`, CommentSingle, nil},
|
||||
{Words(`/?`, `\b`, `ability`, `attributes`, `advancement`,
|
||||
`ban`, `ban-ip`, `banlist`, `bossbar`,
|
||||
`camerashake`, `classroommode`, `clear`,
|
||||
`clearspawnpoint`, `clone`, `code`, `collect`,
|
||||
`createagent`, `data`, `datapack`, `debug`,
|
||||
`defaultgamemode`, `deop`, `destroy`, `detect`,
|
||||
`detectredstone`, `difficulty`, `dropall`,
|
||||
`effect`, `enchant`, `event`, `execute`,
|
||||
`experience`, `fill`, `flog`, `forceload`,
|
||||
`function`, `gamemode`, `gamerule`,
|
||||
`geteduclientinfo`, `give`, `help`, `item`,
|
||||
`immutableworld`, `kick`, `kill`, `list`,
|
||||
`locate`, `locatebiome`, `loot`, `me`, `mixer`,
|
||||
`mobevent`, `move`, `msg`, `music`, `op`,
|
||||
`pardon`, `particle`, `playanimation`,
|
||||
`playsound`, `position`, `publish`,
|
||||
`raytracefog`, `recipe`, `reload`, `remove`,
|
||||
`replaceitem`, `ride`, `save`, `save-all`,
|
||||
`save-off`, `save-on`, `say`, `schedule`,
|
||||
`scoreboard`, `seed`, `setblock`,
|
||||
`setidletimeout`, `setmaxplayers`,
|
||||
`setworldspawn`, `spawnpoint`, `spectate`,
|
||||
`spreadplayers`, `stop`, `stopsound`,
|
||||
`structure`, `summon`, `tag`, `team`, `teammsg`,
|
||||
`teleport`, `tell`, `tellraw`, `testfor`,
|
||||
`testforblock`, `testforblocks`, `tickingarea`,
|
||||
`time`, `title`, `toggledownfall`, `tp`,
|
||||
`tpagent`, `transfer`, `transferserver`,
|
||||
`trigger`, `turn`, `w`, `weather`, `whitelist`,
|
||||
`worldborder`, `worldbuilder`, `wsserver`, `xp`,
|
||||
), KeywordReserved, nil},
|
||||
{Words(``, ``, `@p`, `@r`, `@a`, `@e`, `@s`, `@c`, `@v`),
|
||||
KeywordConstant, nil},
|
||||
{`\[`, Punctuation, Push("argumentlist")},
|
||||
{`{`, Punctuation, Push("nbtobjectvalue")},
|
||||
{`~`, NameBuiltin, nil},
|
||||
{`([a-zA-Z_]+:)?[a-zA-Z_]+\b`, Text, nil},
|
||||
{`([a-z]+)(\.)([0-9]+)\b`, ByGroups(Text, Punctuation, LiteralNumber), nil},
|
||||
{`([<>=]|<=|>=)`, Punctuation, nil},
|
||||
Include("simplevalue"),
|
||||
{`\s+`, TextWhitespace, nil},
|
||||
},
|
||||
},
|
||||
))
|
13
lexers/testdata/mcfunction.actual
vendored
Normal file
13
lexers/testdata/mcfunction.actual
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
fill 29 4 26 ~ ~ ~ minecraft:air replace minecraft:water
|
||||
|
||||
# NBT (JSON-like) value.
|
||||
summon zombie ~ ~ ~ {NoAI:1b}
|
||||
|
||||
# Target selector
|
||||
gamemode creative @a
|
||||
|
||||
# With argument
|
||||
kill @e[type=chicken,nested={a0=0,a1=1}]
|
||||
|
||||
# Ragne
|
||||
kill @e[y_rotation=0..180]
|
78
lexers/testdata/mcfunction.expected
vendored
Normal file
78
lexers/testdata/mcfunction.expected
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
[
|
||||
{"type":"KeywordReserved","value":"fill"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"LiteralNumberInteger","value":"29"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"LiteralNumberInteger","value":"4"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"LiteralNumberInteger","value":"26"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"NameBuiltin","value":"~"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"NameBuiltin","value":"~"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"NameBuiltin","value":"~"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Text","value":"minecraft:air"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Text","value":"replace"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Text","value":"minecraft:water"},
|
||||
{"type":"TextWhitespace","value":"\n\n"},
|
||||
{"type":"CommentSingle","value":"# NBT (JSON-like) value.\n"},
|
||||
{"type":"KeywordReserved","value":"summon"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Text","value":"zombie"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"NameBuiltin","value":"~"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"NameBuiltin","value":"~"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"NameBuiltin","value":"~"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Punctuation","value":"{"},
|
||||
{"type":"NameTag","value":"NoAI"},
|
||||
{"type":"Punctuation","value":":"},
|
||||
{"type":"LiteralNumber","value":"1b"},
|
||||
{"type":"Punctuation","value":"}"},
|
||||
{"type":"TextWhitespace","value":"\n\n"},
|
||||
{"type":"CommentSingle","value":"# Target selector\n"},
|
||||
{"type":"KeywordReserved","value":"gamemode"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Text","value":"creative"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"KeywordConstant","value":"@a"},
|
||||
{"type":"TextWhitespace","value":"\n\n"},
|
||||
{"type":"CommentSingle","value":"# With argument\n"},
|
||||
{"type":"KeywordReserved","value":"kill"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"KeywordConstant","value":"@e"},
|
||||
{"type":"Punctuation","value":"["},
|
||||
{"type":"NameAttribute","value":"type"},
|
||||
{"type":"Punctuation","value":"="},
|
||||
{"type":"Text","value":"chicken"},
|
||||
{"type":"Punctuation","value":","},
|
||||
{"type":"NameAttribute","value":"nested"},
|
||||
{"type":"Punctuation","value":"={"},
|
||||
{"type":"NameAttribute","value":"a0"},
|
||||
{"type":"Punctuation","value":"="},
|
||||
{"type":"LiteralNumberInteger","value":"0"},
|
||||
{"type":"Punctuation","value":","},
|
||||
{"type":"NameAttribute","value":"a1"},
|
||||
{"type":"Punctuation","value":"="},
|
||||
{"type":"LiteralNumberInteger","value":"1"},
|
||||
{"type":"Punctuation","value":"}]"},
|
||||
{"type":"TextWhitespace","value":"\n\n"},
|
||||
{"type":"CommentSingle","value":"# Ragne\n"},
|
||||
{"type":"KeywordReserved","value":"kill"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"KeywordConstant","value":"@e"},
|
||||
{"type":"Punctuation","value":"["},
|
||||
{"type":"NameAttribute","value":"y_rotation"},
|
||||
{"type":"Punctuation","value":"="},
|
||||
{"type":"LiteralNumberInteger","value":"0"},
|
||||
{"type":"Punctuation","value":".."},
|
||||
{"type":"LiteralNumberInteger","value":"180"},
|
||||
{"type":"Punctuation","value":"]"},
|
||||
{"type":"TextWhitespace","value":"\n"}
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user