From 7e2ae04341d2bd1ff677a065931ec11782580b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E6=B3=95=E6=94=BE=E5=AF=92=E5=81=87?= <40489495+MiemieMethod@users.noreply.github.com> Date: Tue, 29 Nov 2022 08:13:35 +0800 Subject: [PATCH] Add a lexer for Schemas for Minecraft Add-ons and 4 examples, merging lexers (#2276) --- pygments/lexers/_mapping.py | 5 +- .../lexers/{mcfunction.py => minecraft.py} | 104 +- .../mcschema/actor_animation.mcschema | 145 ++ .../mcschema/actor_animation.mcschema.output | 892 +++++++++++ .../examplefiles/mcschema/attribute.mcschema | 7 + .../mcschema/attribute.mcschema.output | 52 + tests/examplefiles/mcschema/geometry.mcschema | 225 +++ .../mcschema/geometry.mcschema.output | 1404 +++++++++++++++++ tests/examplefiles/mcschema/manifest.mcschema | 136 ++ .../mcschema/manifest.mcschema.output | 1158 ++++++++++++++ 10 files changed, 4117 insertions(+), 11 deletions(-) rename pygments/lexers/{mcfunction.py => minecraft.py} (72%) create mode 100644 tests/examplefiles/mcschema/actor_animation.mcschema create mode 100644 tests/examplefiles/mcschema/actor_animation.mcschema.output create mode 100644 tests/examplefiles/mcschema/attribute.mcschema create mode 100644 tests/examplefiles/mcschema/attribute.mcschema.output create mode 100644 tests/examplefiles/mcschema/geometry.mcschema create mode 100644 tests/examplefiles/mcschema/geometry.mcschema.output create mode 100644 tests/examplefiles/mcschema/manifest.mcschema create mode 100644 tests/examplefiles/mcschema/manifest.mcschema.output diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index c9640a1179..96db712fe9 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -275,7 +275,8 @@ 'LogosLexer': ('pygments.lexers.objective', 'Logos', ('logos',), ('*.x', '*.xi', '*.xm', '*.xmi'), ('text/x-logos',)), 'LogtalkLexer': ('pygments.lexers.prolog', 'Logtalk', ('logtalk',), ('*.lgt', '*.logtalk'), ('text/x-logtalk',)), 'LuaLexer': ('pygments.lexers.scripting', 'Lua', ('lua',), ('*.lua', '*.wlua'), ('text/x-lua', 'application/x-lua')), - 'MCFunctionLexer': ('pygments.lexers.mcfunction', 'MCFunction', ('mcfunction', 'mcf'), ('*.mcfunction',), ('text/mcfunction',)), + 'MCFunctionLexer': ('pygments.lexers.minecraft', 'MCFunction', ('mcfunction', 'mcf'), ('*.mcfunction',), ('text/mcfunction',)), + 'MCSchemaLexer': ('pygments.lexers.minecraft', 'MCSchema', ('mcschema',), ('*.mcschema',), ('text/mcschema',)), 'MIMELexer': ('pygments.lexers.mime', 'MIME', ('mime',), (), ('multipart/mixed', 'multipart/related', 'multipart/alternative')), 'MIPSLexer': ('pygments.lexers.mips', 'MIPS', ('mips',), ('*.mips', '*.MIPS'), ()), 'MOOCodeLexer': ('pygments.lexers.scripting', 'MOOCode', ('moocode', 'moo'), ('*.moo',), ('text/x-moocode',)), @@ -428,7 +429,7 @@ 'SASLexer': ('pygments.lexers.sas', 'SAS', ('sas',), ('*.SAS', '*.sas'), ('text/x-sas', 'text/sas', 'application/x-sas')), 'SLexer': ('pygments.lexers.r', 'S', ('splus', 's', 'r'), ('*.S', '*.R', '.Rhistory', '.Rprofile', '.Renviron'), ('text/S-plus', 'text/S', 'text/x-r-source', 'text/x-r', 'text/x-R', 'text/x-r-history', 'text/x-r-profile')), 'SMLLexer': ('pygments.lexers.ml', 'Standard ML', ('sml',), ('*.sml', '*.sig', '*.fun'), ('text/x-standardml', 'application/x-standardml')), - 'SNBTLexer': ('pygments.lexers.mcfunction', 'SNBT', ('snbt',), ('*.snbt',), ('text/snbt',)), + 'SNBTLexer': ('pygments.lexers.minecraft', 'SNBT', ('snbt',), ('*.snbt',), ('text/snbt',)), 'SarlLexer': ('pygments.lexers.jvm', 'SARL', ('sarl',), ('*.sarl',), ('text/x-sarl',)), 'SassLexer': ('pygments.lexers.css', 'Sass', ('sass',), ('*.sass',), ('text/x-sass',)), 'SaviLexer': ('pygments.lexers.savi', 'Savi', ('savi',), ('*.savi',), ()), diff --git a/pygments/lexers/mcfunction.py b/pygments/lexers/minecraft.py similarity index 72% rename from pygments/lexers/mcfunction.py rename to pygments/lexers/minecraft.py index d969d876ff..0506fdbb4c 100644 --- a/pygments/lexers/mcfunction.py +++ b/pygments/lexers/minecraft.py @@ -1,8 +1,19 @@ """ - pygments.lexers.mcfunction - ~~~~~~~~~~~~~~~~~~~~~~~~~~ - - Lexers for MCFunction and related languages. + pygments.lexers.minecraft + ~~~~~~~~~~~~~~~~~~~~~~~~~ + + Lexers for Minecraft related languages. + + SNBT. A data communication format used in Minecraft. + wiki: https://minecraft.fandom.com/wiki/NBT_format + + MCFunction. The Function file for Minecraft Data packs and Add-ons. + official: https://learn.microsoft.com/en-us/minecraft/creator/documents/functionsintroduction + wiki: https://minecraft.fandom.com/wiki/Function + + MCSchema. A kind of data Schema for Minecraft Add-on Development. + official: https://learn.microsoft.com/en-us/minecraft/creator/reference/content/schemasreference/ + community example: https://www.mcbe-dev.net/addons/data-driven/manifest.html :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. @@ -12,13 +23,13 @@ from pygments.token import Comment, Keyword, Literal, Name, Number, Operator, \ Punctuation, String, Text, Whitespace -__all__ = ['SNBTLexer', 'MCFunctionLexer'] +__all__ = ['SNBTLexer', 'MCFunctionLexer', 'MCSchemaLexer'] class SNBTLexer(RegexLexer): """Lexer for stringified NBT, a data format used in Minecraft - .. versionadded:: 2.12 + .. versionadded:: 2.12.0 """ name = "SNBT" @@ -127,8 +138,8 @@ class MCFunctionLexer(RegexLexer): include("resource-name"), # normal command names and scoreboards # there's no way to know the differences unfortuntely - (r"[A-Za-z_][A-Za-z0-9_.#%$]+", Keyword.Constant), - (r"[#%$][A-Za-z0-9_.#%$]+", Name.Variable.Magic), + (r"[A-Za-z_][\w.#%$]+", Keyword.Constant), + (r"[#%$][\w.#%$]+", Name.Variable.Magic), ], "resource-name": [ @@ -173,7 +184,7 @@ class MCFunctionLexer(RegexLexer): include("resource-name"), # Scoreboard player names - (r"[#%$][A-Za-z0-9_.#%$]+", Name.Variable.Magic), + (r"[#%$][\w.#%$]+", Name.Variable.Magic), ], "operators": [ @@ -306,3 +317,78 @@ class MCFunctionLexer(RegexLexer): default("#pop"), ], } + + +class MCSchemaLexer(RegexLexer): + """Lexer for Minecraft Add-ons data Schemas, an interface structure standard used in Minecraft + + .. versionadded:: 2.14.0 + """ + + name = 'MCSchema' + url = 'https://learn.microsoft.com/en-us/minecraft/creator/reference/content/schemasreference/' + aliases = ['mcschema'] + filenames = ['*.mcschema'] + mimetypes = ['text/mcschema'] + + tokens = { + 'commentsandwhitespace': [ + (r'\s+', Whitespace), + (r'//.*?$', Comment.Single), + (r'/\*.*?\*/', Comment.Multiline) + ], + 'slashstartsregex': [ + include('commentsandwhitespace'), + (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' + r'([gimuysd]+\b|\B)', String.Regex, '#pop'), + (r'(?=/)', Text, ('#pop', 'badregex')), + default('#pop') + ], + 'badregex': [ + (r'\n', Whitespace, '#pop') + ], + 'singlestring': [ + (r'\\.', String.Escape), + (r"'", String.Single, '#pop'), + (r"[^\\']+", String.Single), + ], + 'doublestring': [ + (r'\\.', String.Escape), + (r'"', String.Double, '#pop'), + (r'[^\\"]+', String.Double), + ], + 'root': [ + (r'^(?=\s|/|