From 40542a6255ad722f40ecd6df2d368fb4a9cd552c Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Sat, 9 Sep 2023 12:29:23 +1000 Subject: [PATCH] refactor: migrate a bunch more Go-based lexers to XML Also rename some existing XML lexers to their canonical XML name. --- .gitignore | 1 + Bitfile | 4 +- _tools/pygments2chroma.py | 202 ---------- bin/.watchexec-1.23.0.pkg | 1 + bin/watchexec | 1 + cmd/chroma/main.go | 5 +- lexer.go | 4 +- lexers/bash.go | 17 - lexers/chapel.go | 62 --- lexers/cheetah.go | 39 -- lexers/cql.go | 70 ---- lexers/docker.go | 32 -- lexers/embedded/{aql.xml => arangodb_aql.xml} | 17 +- lexers/embedded/bash.xml | 3 + .../{bashsession.xml => bash_session.xml} | 2 +- lexers/embedded/{csharp.xml => c#.xml} | 0 lexers/embedded/c++.xml | 2 +- lexers/embedded/c.xml | 2 +- lexers/embedded/cassandra_cql.xml | 137 +++++++ lexers/embedded/chapel.xml | 143 +++++++ lexers/embedded/cheetah.xml | 55 +++ lexers/embedded/docker.xml | 56 +++ lexers/embedded/fortranfixed.xml | 71 ++++ lexers/embedded/gdscript.xml | 2 +- lexers/embedded/gdscript3.xml | 2 +- lexers/embedded/go_template.xml | 4 +- lexers/embedded/html.xml | 159 ++++++++ ...pd.xml => lighttpd_configuration_file.xml} | 0 lexers/embedded/makefile.xml | 128 ++++++ lexers/embedded/mako.xml | 120 ++++++ lexers/embedded/mason.xml | 89 +++++ lexers/embedded/myghty.xml | 77 ++++ ...nginx.xml => nginx_configuration_file.xml} | 0 lexers/embedded/openedge_abl.xml | 101 +++++ lexers/embedded/org_mode.xml | 329 ++++++++++++++++ lexers/embedded/plaintext.xml | 21 + lexers/embedded/postgresql_sql_dialect.xml | 155 ++++++++ .../{protobuf.xml => protocol_buffer.xml} | 54 +-- lexers/embedded/smarty.xml | 79 ++++ lexers/embedded/typoscript.xml | 178 +++++++++ lexers/embedded/v.xml | 355 +++++++++++++++++ lexers/embedded/v_shell.xml | 365 ++++++++++++++++++ lexers/embedded/viml.xml | 85 ++++ .../{wgsl.xml => webgpu_shading_language.xml} | 165 ++++++-- lexers/embedded/z80.xml | 36 -- lexers/embedded/z80_assembly.xml | 74 ++++ lexers/fortran_fixed.go | 38 -- lexers/html.go | 56 +-- lexers/make.go | 56 --- lexers/mako.go | 62 --- lexers/mason.go | 44 --- lexers/myghty.go | 42 -- lexers/openedgeabl.go | 49 --- lexers/org.go | 99 ----- lexers/plaintext.go | 16 - lexers/postgres.go | 77 ---- lexers/smarty.go | 42 -- lexers/testdata/analysis/bash.actual | 3 + lexers/testdata/analysis/bash.expected | 1 + lexers/v.go | 173 --------- lexers/vim.go | 40 -- mutators.go | 2 +- serialise.go | 2 +- 63 files changed, 2963 insertions(+), 1343 deletions(-) delete mode 100644 _tools/pygments2chroma.py create mode 120000 bin/.watchexec-1.23.0.pkg create mode 120000 bin/watchexec delete mode 100644 lexers/bash.go delete mode 100644 lexers/chapel.go delete mode 100644 lexers/cheetah.go delete mode 100644 lexers/cql.go delete mode 100644 lexers/docker.go rename lexers/embedded/{aql.xml => arangodb_aql.xml} (96%) rename lexers/embedded/{bashsession.xml => bash_session.xml} (87%) rename lexers/embedded/{csharp.xml => c#.xml} (100%) create mode 100644 lexers/embedded/cassandra_cql.xml create mode 100644 lexers/embedded/chapel.xml create mode 100644 lexers/embedded/cheetah.xml create mode 100644 lexers/embedded/docker.xml create mode 100644 lexers/embedded/fortranfixed.xml create mode 100644 lexers/embedded/html.xml rename lexers/embedded/{lighttpd.xml => lighttpd_configuration_file.xml} (100%) create mode 100644 lexers/embedded/makefile.xml create mode 100644 lexers/embedded/mako.xml create mode 100644 lexers/embedded/mason.xml create mode 100644 lexers/embedded/myghty.xml rename lexers/embedded/{nginx.xml => nginx_configuration_file.xml} (100%) create mode 100644 lexers/embedded/openedge_abl.xml create mode 100644 lexers/embedded/org_mode.xml create mode 100644 lexers/embedded/plaintext.xml create mode 100644 lexers/embedded/postgresql_sql_dialect.xml rename lexers/embedded/{protobuf.xml => protocol_buffer.xml} (99%) create mode 100644 lexers/embedded/smarty.xml create mode 100644 lexers/embedded/typoscript.xml create mode 100644 lexers/embedded/v.xml create mode 100644 lexers/embedded/v_shell.xml create mode 100644 lexers/embedded/viml.xml rename lexers/embedded/{wgsl.xml => webgpu_shading_language.xml} (89%) delete mode 100644 lexers/embedded/z80.xml create mode 100644 lexers/embedded/z80_assembly.xml delete mode 100644 lexers/fortran_fixed.go delete mode 100644 lexers/make.go delete mode 100644 lexers/mako.go delete mode 100644 lexers/mason.go delete mode 100644 lexers/myghty.go delete mode 100644 lexers/openedgeabl.go delete mode 100644 lexers/org.go delete mode 100644 lexers/plaintext.go delete mode 100644 lexers/postgres.go delete mode 100644 lexers/smarty.go create mode 100644 lexers/testdata/analysis/bash.actual create mode 100644 lexers/testdata/analysis/bash.expected delete mode 100644 lexers/v.go delete mode 100644 lexers/vim.go diff --git a/.gitignore b/.gitignore index 742d38b71..8cbdd75ea 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ _models/ _examples/ *.min.* +build/ diff --git a/Bitfile b/Bitfile index 8b2426d77..bf158633a 100644 --- a/Bitfile +++ b/Bitfile @@ -12,10 +12,10 @@ README.md: lexers/*.go lexers/*/*.xml table.py implicit %{1}%{2}.min.%{3}: **/*.{css,js} build: esbuild --bundle %{IN} --minify --outfile=%{OUT} -implicit %{1}: cmd/* +implicit build/%{1}: cmd/* cd cmd/%{1} inputs: cmd/%{1}/**/* **/*.go - build: go build -ldflags="-X 'main.version=%{VERSION}'" -o ../../%{1} . + build: go build -ldflags="-X 'main.version=%{VERSION}'" -o ../../build/%{1} . #upload: chromad # build: diff --git a/_tools/pygments2chroma.py b/_tools/pygments2chroma.py deleted file mode 100644 index 11fc42082..000000000 --- a/_tools/pygments2chroma.py +++ /dev/null @@ -1,202 +0,0 @@ -import functools -import importlib -import json -import os -import re -import sys -import types - -import pystache -from pygments import lexer as pygments_lexer -from pygments.token import _TokenType - - -TEMPLATE = r''' -package {{package}} - -import ( - . "github.com/alecthomas/chroma/v2" // nolint - "github.com/alecthomas/chroma/v2/lexers/internal" -) - -// {{upper_name}} lexer. -var {{upper_name}} = internal.Register(MustNewLazyLexer( - &Config{ - Name: "{{name}}", - {{=<% %>=}} - Aliases: []string{<%#aliases%>"<%.%>", <%/aliases%>}, - Filenames: []string{<%#filenames%>"<%.%>", <%/filenames%>}, - MimeTypes: []string{<%#mimetypes%>"<%.%>", <%/mimetypes%>}, - <%={{ }}=%> -{{#re_not_multiline}} - NotMultiline: true, -{{/re_not_multiline}} -{{#re_dotall}} - DotAll: true, -{{/re_dotall}} -{{#re_ignorecase}} - CaseInsensitive: true, -{{/re_ignorecase}} - }, - func() Rules { - return Rules{ -{{#tokens}} - "{{state}}": { - {{#rules}} - {{{.}}}, - {{/rules}} - }, -{{/tokens}} - } - }, -)) -''' - - -def go_regex(s): - return go_string(s) - - -def go_string(s): - if '`' not in s: - return '`' + s + '`' - return json.dumps(s) - - -def to_camel_case(snake_str): - components = snake_str.split('_') - return ''.join(x.title() for x in components) - - -def warning(message): - print('warning: ' + message, file=sys.stderr) - - -def resolve_emitter(emitter): - if isinstance(emitter, types.FunctionType): - if repr(emitter).startswith('>=|<=>|<~>|\.\.|by|#|\.\.\.|&&|\|\||!|&|\||\^|~|<<|>>|==|!=|<=|>=|<|>|[+\-*/%]|\*\*)`, Operator, nil}, - {`[:;,.?()\[\]{}]`, Punctuation, nil}, - {`[a-zA-Z_][\w$]*`, NameOther, nil}, - }, - "classname": { - {`[a-zA-Z_][\w$]*`, NameClass, Pop(1)}, - }, - "procname": { - {`([a-zA-Z_][.\w$]*|\~[a-zA-Z_][.\w$]*|[+*/!~%<>=&^|\-:]{1,2})`, NameFunction, Pop(1)}, - {`\(`, Punctuation, Push("receivertype")}, - {`\)+\.`, Punctuation, nil}, - }, - "receivertype": { - {Words(``, `\b`, `atomic`, `single`, `sync`, `borrowed`, `owned`, `shared`, `unmanaged`), Keyword, nil}, - {Words(``, `\b`, `bool`, `bytes`, `complex`, `imag`, `int`, `locale`, `nothing`, `opaque`, `range`, `real`, `string`, `uint`, `void`), KeywordType, nil}, - {`[^()]*`, NameOther, Pop(1)}, - }, - } - }, -)) diff --git a/lexers/cheetah.go b/lexers/cheetah.go deleted file mode 100644 index 7eea429be..000000000 --- a/lexers/cheetah.go +++ /dev/null @@ -1,39 +0,0 @@ -package lexers - -import ( - . "github.com/alecthomas/chroma/v2" // nolint -) - -// Cheetah lexer. -var Cheetah = Register(MustNewLexer( - &Config{ - Name: "Cheetah", - Aliases: []string{"cheetah", "spitfire"}, - Filenames: []string{"*.tmpl", "*.spt"}, - MimeTypes: []string{"application/x-cheetah", "application/x-spitfire"}, - }, - cheetahRules, -)) - -func cheetahRules() Rules { - return Rules{ - "root": { - {`(##[^\n]*)$`, ByGroups(Comment), nil}, - {`#[*](.|\n)*?[*]#`, Comment, nil}, - {`#end[^#\n]*(?:#|$)`, CommentPreproc, nil}, - {`#slurp$`, CommentPreproc, nil}, - {`(#[a-zA-Z]+)([^#\n]*)(#|$)`, ByGroups(CommentPreproc, Using("Python"), CommentPreproc), nil}, - {`(\$)([a-zA-Z_][\w.]*\w)`, ByGroups(CommentPreproc, Using("Python")), nil}, - {`(\$\{!?)(.*?)(\})(?s)`, ByGroups(CommentPreproc, Using("Python"), CommentPreproc), nil}, - {`(?sx) - (.+?) # anything, followed by: - (?: - (?=\#[#a-zA-Z]*) | # an eval comment - (?=\$[a-zA-Z_{]) | # a substitution - \Z # end of string - ) - `, Other, nil}, - {`\s+`, Text, nil}, - }, - } -} diff --git a/lexers/cql.go b/lexers/cql.go deleted file mode 100644 index 32f7a2812..000000000 --- a/lexers/cql.go +++ /dev/null @@ -1,70 +0,0 @@ -package lexers - -import ( - . "github.com/alecthomas/chroma/v2" // nolint -) - -// CassandraCQL lexer. -var CassandraCQL = Register(MustNewLexer( - &Config{ - Name: "Cassandra CQL", - Aliases: []string{"cassandra", "cql"}, - Filenames: []string{"*.cql"}, - MimeTypes: []string{"text/x-cql"}, - NotMultiline: true, - CaseInsensitive: true, - }, - cassandraCQLRules, -)) - -func cassandraCQLRules() Rules { - return Rules{ - "root": { - {`\s+`, TextWhitespace, nil}, - {`(--|\/\/).*\n?`, CommentSingle, nil}, - {`/\*`, CommentMultiline, Push("multiline-comments")}, - {`(ascii|bigint|blob|boolean|counter|date|decimal|double|float|frozen|inet|int|list|map|set|smallint|text|time|timestamp|timeuuid|tinyint|tuple|uuid|varchar|varint)\b`, NameBuiltin, nil}, - {Words(``, `\b`, `ADD`, `AGGREGATE`, `ALL`, `ALLOW`, `ALTER`, `AND`, `ANY`, `APPLY`, `AS`, `ASC`, `AUTHORIZE`, `BATCH`, `BEGIN`, `BY`, `CLUSTERING`, `COLUMNFAMILY`, `COMPACT`, `CONSISTENCY`, `COUNT`, `CREATE`, `CUSTOM`, `DELETE`, `DESC`, `DISTINCT`, `DROP`, `EACH_QUORUM`, `ENTRIES`, `EXISTS`, `FILTERING`, `FROM`, `FULL`, `GRANT`, `IF`, `IN`, `INDEX`, `INFINITY`, `INSERT`, `INTO`, `KEY`, `KEYS`, `KEYSPACE`, `KEYSPACES`, `LEVEL`, `LIMIT`, `LOCAL_ONE`, `LOCAL_QUORUM`, `MATERIALIZED`, `MODIFY`, `NAN`, `NORECURSIVE`, `NOSUPERUSER`, `NOT`, `OF`, `ON`, `ONE`, `ORDER`, `PARTITION`, `PASSWORD`, `PER`, `PERMISSION`, `PERMISSIONS`, `PRIMARY`, `QUORUM`, `RENAME`, `REVOKE`, `SCHEMA`, `SELECT`, `STATIC`, `STORAGE`, `SUPERUSER`, `TABLE`, `THREE`, `TO`, `TOKEN`, `TRUNCATE`, `TTL`, `TWO`, `TYPE`, `UNLOGGED`, `UPDATE`, `USE`, `USER`, `USERS`, `USING`, `VALUES`, `VIEW`, `WHERE`, `WITH`, `WRITETIME`, `REPLICATION`, `OR`, `REPLACE`, `FUNCTION`, `CALLED`, `INPUT`, `RETURNS`, `LANGUAGE`, `ROLE`, `ROLES`, `TRIGGER`, `DURABLE_WRITES`, `LOGIN`, `OPTIONS`, `LOGGED`, `SFUNC`, `STYPE`, `FINALFUNC`, `INITCOND`, `IS`, `CONTAINS`, `JSON`, `PAGING`, `OFF`), Keyword, nil}, - {"[+*/<>=~!@#%^&|`?-]+", Operator, nil}, - { - `(?s)(java|javascript)(\s+)(AS)(\s+)('|\$\$)(.*?)(\5)`, - UsingByGroup(1, 6, - NameBuiltin, TextWhitespace, Keyword, TextWhitespace, - LiteralStringHeredoc, LiteralStringHeredoc, LiteralStringHeredoc), - nil, - }, - {`(true|false|null)\b`, KeywordConstant, nil}, - {`0x[0-9a-f]+`, LiteralNumberHex, nil}, - {`[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}`, LiteralNumberHex, nil}, - {`\.[0-9]+(e[+-]?[0-9]+)?`, Error, nil}, - {`-?[0-9]+(\.[0-9])?(e[+-]?[0-9]+)?`, LiteralNumberFloat, nil}, - {`[0-9]+`, LiteralNumberInteger, nil}, - {`'`, LiteralStringSingle, Push("string")}, - {`"`, LiteralStringName, Push("quoted-ident")}, - {`\$\$`, LiteralStringHeredoc, Push("dollar-string")}, - {`[a-z_]\w*`, Name, nil}, - {`:(['"]?)[a-z]\w*\b\1`, NameVariable, nil}, - {`[;:()\[\]\{\},.]`, Punctuation, nil}, - }, - "multiline-comments": { - {`/\*`, CommentMultiline, Push("multiline-comments")}, - {`\*/`, CommentMultiline, Pop(1)}, - {`[^/*]+`, CommentMultiline, nil}, - {`[/*]`, CommentMultiline, nil}, - }, - "string": { - {`[^']+`, LiteralStringSingle, nil}, - {`''`, LiteralStringSingle, nil}, - {`'`, LiteralStringSingle, Pop(1)}, - }, - "quoted-ident": { - {`[^"]+`, LiteralStringName, nil}, - {`""`, LiteralStringName, nil}, - {`"`, LiteralStringName, Pop(1)}, - }, - "dollar-string": { - {`[^\$]+`, LiteralStringHeredoc, nil}, - {`\$\$`, LiteralStringHeredoc, Pop(1)}, - }, - } -} diff --git a/lexers/docker.go b/lexers/docker.go deleted file mode 100644 index b48816ae3..000000000 --- a/lexers/docker.go +++ /dev/null @@ -1,32 +0,0 @@ -package lexers - -import ( - . "github.com/alecthomas/chroma/v2" // nolint -) - -// Docker lexer. -var Docker = Register(MustNewLexer( - &Config{ - Name: "Docker", - Aliases: []string{"docker", "dockerfile"}, - Filenames: []string{"Dockerfile", "Dockerfile.*", "*.docker"}, - MimeTypes: []string{"text/x-dockerfile-config"}, - CaseInsensitive: true, - }, - dockerRules, -)) - -func dockerRules() Rules { - return Rules{ - "root": { - {`#.*`, Comment, nil}, - {`(ONBUILD)((?:\s*\\?\s*))`, ByGroups(Keyword, Using("Bash")), nil}, - {`(HEALTHCHECK)(((?:\s*\\?\s*)--\w+=\w+(?:\s*\\?\s*))*)`, ByGroups(Keyword, Using("Bash")), nil}, - {`(VOLUME|ENTRYPOINT|CMD|SHELL)((?:\s*\\?\s*))(\[.*?\])`, ByGroups(Keyword, Using("Bash"), Using("JSON")), nil}, - {`(LABEL|ENV|ARG)((?:(?:\s*\\?\s*)\w+=\w+(?:\s*\\?\s*))*)`, ByGroups(Keyword, Using("Bash")), nil}, - {`((?:FROM|MAINTAINER|EXPOSE|WORKDIR|USER|STOPSIGNAL)|VOLUME)\b(.*)`, ByGroups(Keyword, LiteralString), nil}, - {`((?:RUN|CMD|ENTRYPOINT|ENV|ARG|LABEL|ADD|COPY))`, Keyword, nil}, - {`(.*\\\n)*.+`, Using("Bash"), nil}, - }, - } -} diff --git a/lexers/embedded/aql.xml b/lexers/embedded/arangodb_aql.xml similarity index 96% rename from lexers/embedded/aql.xml rename to lexers/embedded/arangodb_aql.xml index 665465a9a..e7119737e 100644 --- a/lexers/embedded/aql.xml +++ b/lexers/embedded/arangodb_aql.xml @@ -4,9 +4,9 @@ aql *.aql text/x-aql + true true true - true @@ -37,10 +37,10 @@ - + - + @@ -49,10 +49,10 @@ - + - + @@ -155,15 +155,14 @@ - + - + - @@ -172,4 +171,4 @@ - + \ No newline at end of file diff --git a/lexers/embedded/bash.xml b/lexers/embedded/bash.xml index 10c8dbe8d..d704a8ffa 100644 --- a/lexers/embedded/bash.xml +++ b/lexers/embedded/bash.xml @@ -26,6 +26,9 @@ PKGBUILD application/x-sh application/x-shellscript + + + diff --git a/lexers/embedded/bashsession.xml b/lexers/embedded/bash_session.xml similarity index 87% rename from lexers/embedded/bashsession.xml rename to lexers/embedded/bash_session.xml index 185974464..82c5fd6d0 100644 --- a/lexers/embedded/bashsession.xml +++ b/lexers/embedded/bash_session.xml @@ -10,7 +10,7 @@ - + diff --git a/lexers/embedded/csharp.xml b/lexers/embedded/c#.xml similarity index 100% rename from lexers/embedded/csharp.xml rename to lexers/embedded/c#.xml diff --git a/lexers/embedded/c++.xml b/lexers/embedded/c++.xml index a6bfb1140..ae25ad008 100644 --- a/lexers/embedded/c++.xml +++ b/lexers/embedded/c++.xml @@ -19,7 +19,7 @@ text/x-c++hdr text/x-c++src true - + diff --git a/lexers/embedded/c.xml b/lexers/embedded/c.xml index da57298e6..35ee32dce 100644 --- a/lexers/embedded/c.xml +++ b/lexers/embedded/c.xml @@ -11,7 +11,7 @@ image/x-xbitmap image/x-xpixmap true - + diff --git a/lexers/embedded/cassandra_cql.xml b/lexers/embedded/cassandra_cql.xml new file mode 100644 index 000000000..1a78f99a1 --- /dev/null +++ b/lexers/embedded/cassandra_cql.xml @@ -0,0 +1,137 @@ + + + Cassandra CQL + cassandra + cql + *.cql + text/x-cql + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/embedded/chapel.xml b/lexers/embedded/chapel.xml new file mode 100644 index 000000000..c89cafc6a --- /dev/null +++ b/lexers/embedded/chapel.xml @@ -0,0 +1,143 @@ + + + Chapel + chapel + chpl + *.chpl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/embedded/cheetah.xml b/lexers/embedded/cheetah.xml new file mode 100644 index 000000000..284457c6c --- /dev/null +++ b/lexers/embedded/cheetah.xml @@ -0,0 +1,55 @@ + + + Cheetah + cheetah + spitfire + *.tmpl + *.spt + application/x-cheetah + application/x-spitfire + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/embedded/docker.xml b/lexers/embedded/docker.xml new file mode 100644 index 000000000..77c893766 --- /dev/null +++ b/lexers/embedded/docker.xml @@ -0,0 +1,56 @@ + + + Docker + docker + dockerfile + Dockerfile + Dockerfile.* + *.docker + text/x-dockerfile-config + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/embedded/fortranfixed.xml b/lexers/embedded/fortranfixed.xml new file mode 100644 index 000000000..11343c0e7 --- /dev/null +++ b/lexers/embedded/fortranfixed.xml @@ -0,0 +1,71 @@ + + + FortranFixed + fortranfixed + *.f + *.F + text/x-fortran + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/embedded/gdscript.xml b/lexers/embedded/gdscript.xml index 242aa635b..350beac7a 100644 --- a/lexers/embedded/gdscript.xml +++ b/lexers/embedded/gdscript.xml @@ -7,7 +7,7 @@ text/x-gdscript application/x-gdscript 0.1 - + diff --git a/lexers/embedded/gdscript3.xml b/lexers/embedded/gdscript3.xml index 7045c54fd..ea78bb7ee 100644 --- a/lexers/embedded/gdscript3.xml +++ b/lexers/embedded/gdscript3.xml @@ -6,7 +6,7 @@ *.gd text/x-gdscript application/x-gdscript - + diff --git a/lexers/embedded/go_template.xml b/lexers/embedded/go_template.xml index 1e90943f4..09009220e 100644 --- a/lexers/embedded/go_template.xml +++ b/lexers/embedded/go_template.xml @@ -1,7 +1,7 @@ - Go HTML Template - go-html-template + Go Template + go-template diff --git a/lexers/embedded/html.xml b/lexers/embedded/html.xml new file mode 100644 index 000000000..2f1a8a979 --- /dev/null +++ b/lexers/embedded/html.xml @@ -0,0 +1,159 @@ + + + HTML + html + *.html + *.htm + *.xhtml + *.xslt + text/html + application/xhtml+xml + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/embedded/lighttpd.xml b/lexers/embedded/lighttpd_configuration_file.xml similarity index 100% rename from lexers/embedded/lighttpd.xml rename to lexers/embedded/lighttpd_configuration_file.xml diff --git a/lexers/embedded/makefile.xml b/lexers/embedded/makefile.xml new file mode 100644 index 000000000..81d189385 --- /dev/null +++ b/lexers/embedded/makefile.xml @@ -0,0 +1,128 @@ + + + Makefile + make + makefile + mf + bsdmake + *.mak + *.mk + Makefile + makefile + Makefile.* + GNUmakefile + BSDmakefile + text/x-makefile + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/embedded/mako.xml b/lexers/embedded/mako.xml new file mode 100644 index 000000000..782414087 --- /dev/null +++ b/lexers/embedded/mako.xml @@ -0,0 +1,120 @@ + + + Mako + mako + *.mao + application/x-mako + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/embedded/mason.xml b/lexers/embedded/mason.xml new file mode 100644 index 000000000..5873f2afc --- /dev/null +++ b/lexers/embedded/mason.xml @@ -0,0 +1,89 @@ + + + Mason + mason + *.m + *.mhtml + *.mc + *.mi + autohandler + dhandler + application/x-mason + 0.1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/embedded/myghty.xml b/lexers/embedded/myghty.xml new file mode 100644 index 000000000..6d03917e5 --- /dev/null +++ b/lexers/embedded/myghty.xml @@ -0,0 +1,77 @@ + + + Myghty + myghty + *.myt + autodelegate + application/x-myghty + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/embedded/nginx.xml b/lexers/embedded/nginx_configuration_file.xml similarity index 100% rename from lexers/embedded/nginx.xml rename to lexers/embedded/nginx_configuration_file.xml diff --git a/lexers/embedded/openedge_abl.xml b/lexers/embedded/openedge_abl.xml new file mode 100644 index 000000000..04a80f3ce --- /dev/null +++ b/lexers/embedded/openedge_abl.xml @@ -0,0 +1,101 @@ + + + OpenEdge ABL + openedge + abl + progress + openedgeabl + *.p + *.cls + *.w + *.i + text/x-openedge + application/x-openedge + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/embedded/org_mode.xml b/lexers/embedded/org_mode.xml new file mode 100644 index 000000000..3f227ad8d --- /dev/null +++ b/lexers/embedded/org_mode.xml @@ -0,0 +1,329 @@ + + + Org Mode + org + orgmode + *.org + text/org + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + 4 + + + + + + + + + + + + 2 + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/embedded/plaintext.xml b/lexers/embedded/plaintext.xml new file mode 100644 index 000000000..d5e3243ee --- /dev/null +++ b/lexers/embedded/plaintext.xml @@ -0,0 +1,21 @@ + + + plaintext + text + plain + no-highlight + *.txt + text/plain + -1 + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/embedded/postgresql_sql_dialect.xml b/lexers/embedded/postgresql_sql_dialect.xml new file mode 100644 index 000000000..e901c1855 --- /dev/null +++ b/lexers/embedded/postgresql_sql_dialect.xml @@ -0,0 +1,155 @@ + + + PostgreSQL SQL dialect + postgresql + postgres + text/x-postgresql + true + true + + + + + + + + + + + + + + + + + + + 6 + 12 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 12 + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/embedded/protobuf.xml b/lexers/embedded/protocol_buffer.xml similarity index 99% rename from lexers/embedded/protobuf.xml rename to lexers/embedded/protocol_buffer.xml index 98ae7c831..157d321f8 100644 --- a/lexers/embedded/protobuf.xml +++ b/lexers/embedded/protocol_buffer.xml @@ -6,6 +6,33 @@ *.proto + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -87,32 +114,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/lexers/embedded/smarty.xml b/lexers/embedded/smarty.xml new file mode 100644 index 000000000..dd7752c58 --- /dev/null +++ b/lexers/embedded/smarty.xml @@ -0,0 +1,79 @@ + + + Smarty + smarty + *.tpl + application/x-smarty + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/embedded/typoscript.xml b/lexers/embedded/typoscript.xml new file mode 100644 index 000000000..bc416d472 --- /dev/null +++ b/lexers/embedded/typoscript.xml @@ -0,0 +1,178 @@ + + + TypoScript + typoscript + *.ts + text/x-typoscript + true + 0.1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/embedded/v.xml b/lexers/embedded/v.xml new file mode 100644 index 000000000..e1af3d1cd --- /dev/null +++ b/lexers/embedded/v.xml @@ -0,0 +1,355 @@ + + + V + v + vlang + *.v + *.vv + v.mod + text/x-v + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/embedded/v_shell.xml b/lexers/embedded/v_shell.xml new file mode 100644 index 000000000..34ce61065 --- /dev/null +++ b/lexers/embedded/v_shell.xml @@ -0,0 +1,365 @@ + + + V shell + vsh + vshell + *.vsh + text/x-vsh + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/embedded/viml.xml b/lexers/embedded/viml.xml new file mode 100644 index 000000000..43e6bfa74 --- /dev/null +++ b/lexers/embedded/viml.xml @@ -0,0 +1,85 @@ + + + VimL + vim + *.vim + .vimrc + .exrc + .gvimrc + _vimrc + _exrc + _gvimrc + vimrc + gvimrc + text/x-vim + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/embedded/wgsl.xml b/lexers/embedded/webgpu_shading_language.xml similarity index 89% rename from lexers/embedded/wgsl.xml rename to lexers/embedded/webgpu_shading_language.xml index f583dfffa..ea2b6e1ef 100644 --- a/lexers/embedded/wgsl.xml +++ b/lexers/embedded/webgpu_shading_language.xml @@ -1,4 +1,3 @@ - WebGPU Shading Language @@ -8,54 +7,136 @@ - + + + - - - + + + + + + + + + + - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + - - + \ No newline at end of file diff --git a/lexers/embedded/z80.xml b/lexers/embedded/z80.xml deleted file mode 100644 index 410183261..000000000 --- a/lexers/embedded/z80.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - Z80 Assembly - z80 - *.z80 - *.asm - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/lexers/embedded/z80_assembly.xml b/lexers/embedded/z80_assembly.xml new file mode 100644 index 000000000..5bb77a9ad --- /dev/null +++ b/lexers/embedded/z80_assembly.xml @@ -0,0 +1,74 @@ + + + Z80 Assembly + z80 + *.z80 + *.asm + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lexers/fortran_fixed.go b/lexers/fortran_fixed.go deleted file mode 100644 index aa93ce07a..000000000 --- a/lexers/fortran_fixed.go +++ /dev/null @@ -1,38 +0,0 @@ -package lexers - -import ( - . "github.com/alecthomas/chroma/v2" // nolint -) - -// FortranFixed lexer. -var FortranFixed = Register(MustNewLexer( - &Config{ - Name: "FortranFixed", - Aliases: []string{"fortranfixed"}, - Filenames: []string{"*.f", "*.F"}, - MimeTypes: []string{"text/x-fortran"}, - NotMultiline: true, - CaseInsensitive: true, - }, - func() Rules { - return Rules{ - "root": { - {`[C*].*\n`, Comment, nil}, - {`#.*\n`, CommentPreproc, nil}, - {` {0,4}!.*\n`, Comment, nil}, - {`(.{5})`, NameLabel, Push("cont-char")}, - {`.*\n`, Using("Fortran"), nil}, - }, - "cont-char": { - {` `, TextWhitespace, Push("code")}, - {`.`, GenericStrong, Push("code")}, - }, - "code": { - {`(.{66})(.*)(\n)`, ByGroups(Using("Fortran"), Comment, TextWhitespace), Push("root")}, - {`(.*)(!.*)(\n)`, ByGroups(Using("Fortran"), Comment, TextWhitespace), Push("root")}, - {`(.*)(\n)`, ByGroups(Using("Fortran"), TextWhitespace), Push("root")}, - Default(Push("root")), - }, - } - }, -)) diff --git a/lexers/html.go b/lexers/html.go index 2fa5cc099..c858042bf 100644 --- a/lexers/html.go +++ b/lexers/html.go @@ -1,60 +1,8 @@ package lexers import ( - . "github.com/alecthomas/chroma/v2" // nolint + "github.com/alecthomas/chroma/v2" ) // HTML lexer. -var HTML = Register(MustNewLexer( - &Config{ - Name: "HTML", - Aliases: []string{"html"}, - Filenames: []string{"*.html", "*.htm", "*.xhtml", "*.xslt"}, - MimeTypes: []string{"text/html", "application/xhtml+xml"}, - NotMultiline: true, - DotAll: true, - CaseInsensitive: true, - }, - htmlRules, -)) - -func htmlRules() Rules { - return Rules{ - "root": { - {`[^<&]+`, Text, nil}, - {`&\S*?;`, NameEntity, nil}, - {`\<\!\[CDATA\[.*?\]\]\>`, CommentPreproc, nil}, - {``, Comment, Pop(1)}, - {`-`, Comment, nil}, - }, - "tag": { - {`\s+`, Text, nil}, - {`([\w:-]+\s*)(=)(\s*)`, ByGroups(NameAttribute, Operator, Text), Push("attr")}, - {`[\w:-]+`, NameAttribute, nil}, - {`(/?)(\s*)(>)`, ByGroups(Punctuation, Text, Punctuation), Pop(1)}, - }, - "script-content": { - {`(<)(\s*)(/)(\s*)(script)(\s*)(>)`, ByGroups(Punctuation, Text, Punctuation, Text, NameTag, Text, Punctuation), Pop(1)}, - {`.+?(?=<\s*/\s*script\s*>)`, Using("Javascript"), nil}, - }, - "style-content": { - {`(<)(\s*)(/)(\s*)(style)(\s*)(>)`, ByGroups(Punctuation, Text, Punctuation, Text, NameTag, Text, Punctuation), Pop(1)}, - {`.+?(?=<\s*/\s*style\s*>)`, Using("CSS"), nil}, - }, - "attr": { - {`".*?"`, LiteralString, Pop(1)}, - {`'.*?'`, LiteralString, Pop(1)}, - {`[^\s>]+`, LiteralString, Pop(1)}, - }, - } -} +var HTML = chroma.MustNewXMLLexer(embedded, "embedded/html.xml") diff --git a/lexers/make.go b/lexers/make.go deleted file mode 100644 index 1d2a5d326..000000000 --- a/lexers/make.go +++ /dev/null @@ -1,56 +0,0 @@ -package lexers - -import ( - . "github.com/alecthomas/chroma/v2" // nolint -) - -// Makefile lexer. -var Makefile = Register(MustNewLexer( - &Config{ - Name: "Makefile", - Aliases: []string{"make", "makefile", "mf", "bsdmake"}, - Filenames: []string{"*.mak", "*.mk", "Makefile", "makefile", "Makefile.*", "GNUmakefile", "BSDmakefile"}, - MimeTypes: []string{"text/x-makefile"}, - EnsureNL: true, - }, - makefileRules, -)) - -func makefileRules() Rules { - return Rules{ - "root": { - {`^(?:[\t ]+.*\n|\n)+`, Using("Bash"), nil}, - {`\$[<@$+%?|*]`, Keyword, nil}, - {`\s+`, Text, nil}, - {`#.*?\n`, Comment, nil}, - {`(export)(\s+)(?=[\w${}\t -]+\n)`, ByGroups(Keyword, Text), Push("export")}, - {`export\s+`, Keyword, nil}, - {`([\w${}().-]+)(\s*)([!?:+]?=)([ \t]*)((?:.*\\\n)+|.*\n)`, ByGroups(NameVariable, Text, Operator, Text, Using("Bash")), nil}, - {`(?s)"(\\\\|\\.|[^"\\])*"`, LiteralStringDouble, nil}, - {`(?s)'(\\\\|\\.|[^'\\])*'`, LiteralStringSingle, nil}, - {`([^\n:]+)(:+)([ \t]*)`, ByGroups(NameFunction, Operator, Text), Push("block-header")}, - {`\$\(`, Keyword, Push("expansion")}, - }, - "expansion": { - {`[^$a-zA-Z_()]+`, Text, nil}, - {`[a-zA-Z_]+`, NameVariable, nil}, - {`\$`, Keyword, nil}, - {`\(`, Keyword, Push()}, - {`\)`, Keyword, Pop(1)}, - }, - "export": { - {`[\w${}-]+`, NameVariable, nil}, - {`\n`, Text, Pop(1)}, - {`\s+`, Text, nil}, - }, - "block-header": { - {`[,|]`, Punctuation, nil}, - {`#.*?\n`, Comment, Pop(1)}, - {`\\\n`, Text, nil}, - {`\$\(`, Keyword, Push("expansion")}, - {`[a-zA-Z_]+`, Name, nil}, - {`\n`, Text, Pop(1)}, - {`.`, Text, nil}, - }, - } -} diff --git a/lexers/mako.go b/lexers/mako.go deleted file mode 100644 index 0de18fe90..000000000 --- a/lexers/mako.go +++ /dev/null @@ -1,62 +0,0 @@ -package lexers - -import ( - . "github.com/alecthomas/chroma/v2" // nolint -) - -// Mako lexer. -var Mako = Register(MustNewLexer( - &Config{ - Name: "Mako", - Aliases: []string{"mako"}, - Filenames: []string{"*.mao"}, - MimeTypes: []string{"application/x-mako"}, - }, - makoRules, -)) - -func makoRules() Rules { - return Rules{ - "root": { - {`(\s*)(%)(\s*end(?:\w+))(\n|\Z)`, ByGroups(Text, CommentPreproc, Keyword, Other), nil}, - {`(\s*)(%)([^\n]*)(\n|\Z)`, ByGroups(Text, CommentPreproc, Using("Python"), Other), nil}, - {`(\s*)(##[^\n]*)(\n|\Z)`, ByGroups(Text, CommentPreproc, Other), nil}, - {`(?s)<%doc>.*?`, CommentPreproc, nil}, - {`(<%)([\w.:]+)`, ByGroups(CommentPreproc, NameBuiltin), Push("tag")}, - {`()`, ByGroups(CommentPreproc, NameBuiltin, CommentPreproc), nil}, - {`<%(?=([\w.:]+))`, CommentPreproc, Push("ondeftags")}, - {`(<%(?:!?))(.*?)(%>)(?s)`, ByGroups(CommentPreproc, Using("Python"), CommentPreproc), nil}, - {`(\$\{)(.*?)(\})`, ByGroups(CommentPreproc, Using("Python"), CommentPreproc), nil}, - {`(?sx) - (.+?) # anything, followed by: - (?: - (?<=\n)(?=%|\#\#) | # an eval or comment line - (?=\#\*) | # multiline comment - (?=`, CommentPreproc, Pop(1)}, - {`\s+`, Text, nil}, - }, - "attr": { - {`".*?"`, LiteralString, Pop(1)}, - {`'.*?'`, LiteralString, Pop(1)}, - {`[^\s>]+`, LiteralString, Pop(1)}, - }, - } -} diff --git a/lexers/mason.go b/lexers/mason.go deleted file mode 100644 index 57e61205a..000000000 --- a/lexers/mason.go +++ /dev/null @@ -1,44 +0,0 @@ -package lexers - -import ( - . "github.com/alecthomas/chroma/v2" // nolint -) - -// Mason lexer. -var Mason = Register(MustNewLexer( - &Config{ - Name: "Mason", - Aliases: []string{"mason"}, - Filenames: []string{"*.m", "*.mhtml", "*.mc", "*.mi", "autohandler", "dhandler"}, - MimeTypes: []string{"application/x-mason"}, - Priority: 0.1, - }, - masonRules, -)) - -func masonRules() Rules { - return Rules{ - "root": { - {`\s+`, Text, nil}, - {`(<%doc>)(.*?)()(?s)`, ByGroups(NameTag, CommentMultiline, NameTag), nil}, - {`(<%(?:def|method))(\s*)(.*?)(>)(.*?)()(?s)`, ByGroups(NameTag, Text, NameFunction, NameTag, UsingSelf("root"), NameTag), nil}, - {`(<%\w+)(.*?)(>)(.*?)()(?s)`, ByGroups(NameTag, NameFunction, NameTag, Using("Perl"), NameTag), nil}, - {`(<&[^|])(.*?)(,.*?)?(&>)(?s)`, ByGroups(NameTag, NameFunction, Using("Perl"), NameTag), nil}, - {`(<&\|)(.*?)(,.*?)?(&>)(?s)`, ByGroups(NameTag, NameFunction, Using("Perl"), NameTag), nil}, - {``, NameTag, nil}, - {`(<%!?)(.*?)(%>)(?s)`, ByGroups(NameTag, Using("Perl"), NameTag), nil}, - {`(?<=^)#[^\n]*(\n|\Z)`, Comment, nil}, - {`(?<=^)(%)([^\n]*)(\n|\Z)`, ByGroups(NameTag, Using("Perl"), Other), nil}, - {`(?sx) - (.+?) # anything, followed by: - (?: - (?<=\n)(?=[%#]) | # an eval or comment line - (?=)(.*?)()(?s)`, ByGroups(NameTag, Text, NameFunction, NameTag, UsingSelf("root"), NameTag), nil}, - {`(<%\w+)(.*?)(>)(.*?)()(?s)`, ByGroups(NameTag, NameFunction, NameTag, Using("Python2"), NameTag), nil}, - {`(<&[^|])(.*?)(,.*?)?(&>)`, ByGroups(NameTag, NameFunction, Using("Python2"), NameTag), nil}, - {`(<&\|)(.*?)(,.*?)?(&>)(?s)`, ByGroups(NameTag, NameFunction, Using("Python2"), NameTag), nil}, - {``, NameTag, nil}, - {`(<%!?)(.*?)(%>)(?s)`, ByGroups(NameTag, Using("Python2"), NameTag), nil}, - {`(?<=^)#[^\n]*(\n|\Z)`, Comment, nil}, - {`(?<=^)(%)([^\n]*)(\n|\Z)`, ByGroups(NameTag, Using("Python2"), Other), nil}, - {`(?sx) - (.+?) # anything, followed by: - (?: - (?<=\n)(?=[%#]) | # an eval or comment line - (?=]+?> *)$`, ByGroups(Comment, CommentSpecial), nil}, // DEADLINE/SCHEDULED: - // DONE state CLOSED - {`(?i)^( *CLOSED: )(\[[^][]+?\] *)$`, ByGroups(Comment, CommentSpecial), nil}, // CLOSED: [datestamp] - // All other lines - Include("inline"), - }, - "inline": { - {`(\s)*(\*[^ \n*][^*]+?[^ \n*]\*)((?=\W|\n|$))`, ByGroups(Text, GenericStrong, Text), nil}, // Bold - {`(\s)*(/[^/]+?/)((?=\W|\n|$))`, ByGroups(Text, GenericEmph, Text), nil}, // Italic - {`(\s)*(=[^\n=]+?=)((?=\W|\n|$))`, ByGroups(Text, NameClass, Text), nil}, // Verbatim - {`(\s)*(~[^\n~]+?~)((?=\W|\n|$))`, ByGroups(Text, NameClass, Text), nil}, // Code - {`(\s)*(\+[^+]+?\+)((?=\W|\n|$))`, ByGroups(Text, GenericDeleted, Text), nil}, // Strikethrough - {`(\s)*(_[^_]+?_)((?=\W|\n|$))`, ByGroups(Text, GenericUnderline, Text), nil}, // Underline - {`(<)([^<>]+?)(>)`, ByGroups(Text, String, Text), nil}, // - {`[{]{3}[^}]+[}]{3}`, NameBuiltin, nil}, // {{{macro(foo,1)}}} - {`([^[])(\[fn:)([^]]+?)(\])([^]])`, ByGroups(Text, NameBuiltinPseudo, LiteralString, NameBuiltinPseudo, Text), nil}, // [fn:1] - // Links - {`(\[\[)([^][]+?)(\]\[)([^][]+)(\]\])`, ByGroups(Text, NameAttribute, Text, NameTag, Text), nil}, // [[link][descr]] - {`(\[\[)([^][]+?)(\]\])`, ByGroups(Text, NameAttribute, Text), nil}, // [[link]] - {`(<<)([^<>]+?)(>>)`, ByGroups(Text, NameAttribute, Text), nil}, // <> - // Tables - {`^( *)(\|[ -].*?[ -]\|)$`, ByGroups(Text, String), nil}, - // Blank lines, newlines - {`\n`, Text, nil}, - // Any other text - {`.`, Text, nil}, - }, - } -} diff --git a/lexers/plaintext.go b/lexers/plaintext.go deleted file mode 100644 index 8b32aa442..000000000 --- a/lexers/plaintext.go +++ /dev/null @@ -1,16 +0,0 @@ -package lexers - -import ( - . "github.com/alecthomas/chroma/v2" // nolint -) - -var Plaintext = Register(MustNewLexer( - &Config{ - Name: "plaintext", - Aliases: []string{"text", "plain", "no-highlight"}, - Filenames: []string{"*.txt"}, - MimeTypes: []string{"text/plain"}, - Priority: -1, - }, - PlaintextRules, -)) diff --git a/lexers/postgres.go b/lexers/postgres.go deleted file mode 100644 index 0ef96ef8f..000000000 --- a/lexers/postgres.go +++ /dev/null @@ -1,77 +0,0 @@ -package lexers - -import ( - . "github.com/alecthomas/chroma/v2" // nolint -) - -// Postgresql Sql Dialect lexer. -var PostgreSQL = Register(MustNewLexer( - &Config{ - Name: "PostgreSQL SQL dialect", - Aliases: []string{"postgresql", "postgres"}, - Filenames: []string{}, - MimeTypes: []string{"text/x-postgresql"}, - NotMultiline: true, - CaseInsensitive: true, - }, - postgreSQLRules, -)) - -func postgreSQLRules() Rules { - return Rules{ - "root": { - {`\s+`, Text, nil}, - {`--.*\n?`, CommentSingle, nil}, - {`/\*`, CommentMultiline, Push("multiline-comments")}, - {`(bigint|bigserial|bit|bit\s+varying|bool|boolean|box|bytea|char|character|character\s+varying|cidr|circle|date|decimal|double\s+precision|float4|float8|inet|int|int2|int4|int8|integer|interval|json|jsonb|line|lseg|macaddr|money|numeric|path|pg_lsn|point|polygon|real|serial|serial2|serial4|serial8|smallint|smallserial|text|time|timestamp|timestamptz|timetz|tsquery|tsvector|txid_snapshot|uuid|varbit|varchar|with\s+time\s+zone|without\s+time\s+zone|xml|anyarray|anyelement|anyenum|anynonarray|anyrange|cstring|fdw_handler|internal|language_handler|opaque|record|void)\b`, NameBuiltin, nil}, - { - `(?s)(DO)(\s+)(?:(LANGUAGE)?(\s+)('?)(\w+)?('?)(\s+))?(\$)([^$]*)(\$)(.*?)(\$)(\10)(\$)`, - UsingByGroup(6, 12, - Keyword, Text, Keyword, Text, // DO LANGUAGE - StringSingle, StringSingle, StringSingle, Text, // 'plpgsql' - StringHeredoc, StringHeredoc, StringHeredoc, // $tag$ - StringHeredoc, // (code block) - StringHeredoc, StringHeredoc, StringHeredoc), // $tag$ - nil, - }, - {Words(``, `\b`, `ABORT`, `ABSOLUTE`, `ACCESS`, `ACTION`, `ADD`, `ADMIN`, `AFTER`, `AGGREGATE`, `ALL`, `ALSO`, `ALTER`, `ALWAYS`, `ANALYSE`, `ANALYZE`, `AND`, `ANY`, `ARRAY`, `AS`, `ASC`, `ASSERTION`, `ASSIGNMENT`, `ASYMMETRIC`, `AT`, `ATTRIBUTE`, `AUTHORIZATION`, `BACKWARD`, `BEFORE`, `BEGIN`, `BETWEEN`, `BIGINT`, `BINARY`, `BIT`, `BOOLEAN`, `BOTH`, `BY`, `CACHE`, `CALLED`, `CASCADE`, `CASCADED`, `CASE`, `CAST`, `CATALOG`, `CHAIN`, `CHAR`, `CHARACTER`, `CHARACTERISTICS`, `CHECK`, `CHECKPOINT`, `CLASS`, `CLOSE`, `CLUSTER`, `COALESCE`, `COLLATE`, `COLLATION`, `COLUMN`, `COMMENT`, `COMMENTS`, `COMMIT`, `COMMITTED`, `CONCURRENTLY`, `CONFIGURATION`, `CONNECTION`, `CONSTRAINT`, `CONSTRAINTS`, `CONTENT`, `CONTINUE`, `CONVERSION`, `COPY`, `COST`, `CREATE`, `CROSS`, `CSV`, `CURRENT`, `CURRENT_CATALOG`, `CURRENT_DATE`, `CURRENT_ROLE`, `CURRENT_SCHEMA`, `CURRENT_TIME`, `CURRENT_TIMESTAMP`, `CURRENT_USER`, `CURSOR`, `CYCLE`, `DATA`, `DATABASE`, `DAY`, `DEALLOCATE`, `DEC`, `DECIMAL`, `DECLARE`, `DEFAULT`, `DEFAULTS`, `DEFERRABLE`, `DEFERRED`, `DEFINER`, `DELETE`, `DELIMITER`, `DELIMITERS`, `DESC`, `DICTIONARY`, `DISABLE`, `DISCARD`, `DISTINCT`, `DO`, `DOCUMENT`, `DOMAIN`, `DOUBLE`, `DROP`, `EACH`, `ELSE`, `ENABLE`, `ENCODING`, `ENCRYPTED`, `END`, `ENUM`, `ESCAPE`, `EVENT`, `EXCEPT`, `EXCLUDE`, `EXCLUDING`, `EXCLUSIVE`, `EXECUTE`, `EXISTS`, `EXPLAIN`, `EXTENSION`, `EXTERNAL`, `EXTRACT`, `FALSE`, `FAMILY`, `FETCH`, `FILTER`, `FIRST`, `FLOAT`, `FOLLOWING`, `FOR`, `FORCE`, `FOREIGN`, `FORWARD`, `FREEZE`, `FROM`, `FULL`, `FUNCTION`, `FUNCTIONS`, `GLOBAL`, `GRANT`, `GRANTED`, `GREATEST`, `GROUP`, `HANDLER`, `HAVING`, `HEADER`, `HOLD`, `HOUR`, `IDENTITY`, `IF`, `ILIKE`, `IMMEDIATE`, `IMMUTABLE`, `IMPLICIT`, `IN`, `INCLUDING`, `INCREMENT`, `INDEX`, `INDEXES`, `INHERIT`, `INHERITS`, `INITIALLY`, `INLINE`, `INNER`, `INOUT`, `INPUT`, `INSENSITIVE`, `INSERT`, `INSTEAD`, `INT`, `INTEGER`, `INTERSECT`, `INTERVAL`, `INTO`, `INVOKER`, `IS`, `ISNULL`, `ISOLATION`, `JOIN`, `KEY`, `LABEL`, `LANGUAGE`, `LARGE`, `LAST`, `LATERAL`, `LC_COLLATE`, `LC_CTYPE`, `LEADING`, `LEAKPROOF`, `LEAST`, `LEFT`, `LEVEL`, `LIKE`, `LIMIT`, `LISTEN`, `LOAD`, `LOCAL`, `LOCALTIME`, `LOCALTIMESTAMP`, `LOCATION`, `LOCK`, `MAPPING`, `MATCH`, `MATERIALIZED`, `MAXVALUE`, `MINUTE`, `MINVALUE`, `MODE`, `MONTH`, `MOVE`, `NAME`, `NAMES`, `NATIONAL`, `NATURAL`, `NCHAR`, `NEXT`, `NO`, `NONE`, `NOT`, `NOTHING`, `NOTIFY`, `NOTNULL`, `NOWAIT`, `NULL`, `NULLIF`, `NULLS`, `NUMERIC`, `OBJECT`, `OF`, `OFF`, `OFFSET`, `OIDS`, `ON`, `ONLY`, `OPERATOR`, `OPTION`, `OPTIONS`, `OR`, `ORDER`, `ORDINALITY`, `OUT`, `OUTER`, `OVER`, `OVERLAPS`, `OVERLAY`, `OWNED`, `OWNER`, `PARSER`, `PARTIAL`, `PARTITION`, `PASSING`, `PASSWORD`, `PLACING`, `PLANS`, `POLICY`, `POSITION`, `PRECEDING`, `PRECISION`, `PREPARE`, `PREPARED`, `PRESERVE`, `PRIMARY`, `PRIOR`, `PRIVILEGES`, `PROCEDURAL`, `PROCEDURE`, `PROGRAM`, `QUOTE`, `RANGE`, `READ`, `REAL`, `REASSIGN`, `RECHECK`, `RECURSIVE`, `REF`, `REFERENCES`, `REFRESH`, `REINDEX`, `RELATIVE`, `RELEASE`, `RENAME`, `REPEATABLE`, `REPLACE`, `REPLICA`, `RESET`, `RESTART`, `RESTRICT`, `RETURNING`, `RETURNS`, `REVOKE`, `RIGHT`, `ROLE`, `ROLLBACK`, `ROW`, `ROWS`, `RULE`, `SAVEPOINT`, `SCHEMA`, `SCROLL`, `SEARCH`, `SECOND`, `SECURITY`, `SELECT`, `SEQUENCE`, `SEQUENCES`, `SERIALIZABLE`, `SERVER`, `SESSION`, `SESSION_USER`, `SET`, `SETOF`, `SHARE`, `SHOW`, `SIMILAR`, `SIMPLE`, `SMALLINT`, `SNAPSHOT`, `SOME`, `STABLE`, `STANDALONE`, `START`, `STATEMENT`, `STATISTICS`, `STDIN`, `STDOUT`, `STORAGE`, `STRICT`, `STRIP`, `SUBSTRING`, `SYMMETRIC`, `SYSID`, `SYSTEM`, `TABLE`, `TABLES`, `TABLESPACE`, `TEMP`, `TEMPLATE`, `TEMPORARY`, `TEXT`, `THEN`, `TIME`, `TIMESTAMP`, `TO`, `TRAILING`, `TRANSACTION`, `TREAT`, `TRIGGER`, `TRIM`, `TRUE`, `TRUNCATE`, `TRUSTED`, `TYPE`, `TYPES`, `UNBOUNDED`, `UNCOMMITTED`, `UNENCRYPTED`, `UNION`, `UNIQUE`, `UNKNOWN`, `UNLISTEN`, `UNLOGGED`, `UNTIL`, `UPDATE`, `USER`, `USING`, `VACUUM`, `VALID`, `VALIDATE`, `VALIDATOR`, `VALUE`, `VALUES`, `VARCHAR`, `VARIADIC`, `VARYING`, `VERBOSE`, `VERSION`, `VIEW`, `VIEWS`, `VOLATILE`, `WHEN`, `WHERE`, `WHITESPACE`, `WINDOW`, `WITH`, `WITHIN`, `WITHOUT`, `WORK`, `WRAPPER`, `WRITE`, `XML`, `XMLATTRIBUTES`, `XMLCONCAT`, `XMLELEMENT`, `XMLEXISTS`, `XMLFOREST`, `XMLPARSE`, `XMLPI`, `XMLROOT`, `XMLSERIALIZE`, `YEAR`, `YES`, `ZONE`), Keyword, nil}, - {"[+*/<>=~!@#%^&|`?-]+", Operator, nil}, - {`::`, Operator, nil}, - {`\$\d+`, NameVariable, nil}, - {`([0-9]*\.[0-9]*|[0-9]+)(e[+-]?[0-9]+)?`, LiteralNumberFloat, nil}, - {`[0-9]+`, LiteralNumberInteger, nil}, - {`((?:E|U&)?)(')`, ByGroups(LiteralStringAffix, LiteralStringSingle), Push("string")}, - {`((?:U&)?)(")`, ByGroups(LiteralStringAffix, LiteralStringName), Push("quoted-ident")}, - { - `(?s)(\$)([^$]*)(\$)(.*?)(\$)(\2)(\$)(\s+)(LANGUAGE)?(\s+)('?)(\w+)?('?)`, - UsingByGroup(12, 4, - StringHeredoc, StringHeredoc, StringHeredoc, // $tag$ - StringHeredoc, // (code block) - StringHeredoc, StringHeredoc, StringHeredoc, // $tag$ - Text, Keyword, Text, // LANGUAGE - StringSingle, StringSingle, StringSingle), // 'type' - nil, - }, - {`(?s)(\$)([^$]*)(\$)(.*?)(\$)(\2)(\$)`, LiteralStringHeredoc, nil}, - {`[a-z_]\w*`, Name, nil}, - {`:(['"]?)[a-z]\w*\b\1`, NameVariable, nil}, - {`[;:()\[\]{},.]`, Punctuation, nil}, - }, - "multiline-comments": { - {`/\*`, CommentMultiline, Push("multiline-comments")}, - {`\*/`, CommentMultiline, Pop(1)}, - {`[^/*]+`, CommentMultiline, nil}, - {`[/*]`, CommentMultiline, nil}, - }, - "string": { - {`[^']+`, LiteralStringSingle, nil}, - {`''`, LiteralStringSingle, nil}, - {`'`, LiteralStringSingle, Pop(1)}, - }, - "quoted-ident": { - {`[^"]+`, LiteralStringName, nil}, - {`""`, LiteralStringName, nil}, - {`"`, LiteralStringName, Pop(1)}, - }, - } -} diff --git a/lexers/smarty.go b/lexers/smarty.go deleted file mode 100644 index 38e024565..000000000 --- a/lexers/smarty.go +++ /dev/null @@ -1,42 +0,0 @@ -package lexers - -import ( - . "github.com/alecthomas/chroma/v2" // nolint -) - -// Smarty lexer. -var Smarty = Register(MustNewLexer( - &Config{ - Name: "Smarty", - Aliases: []string{"smarty"}, - Filenames: []string{"*.tpl"}, - MimeTypes: []string{"application/x-smarty"}, - DotAll: true, - }, - smartyRules, -)) - -func smartyRules() Rules { - return Rules{ - "root": { - {`[^{]+`, Other, nil}, - {`(\{)(\*.*?\*)(\})`, ByGroups(CommentPreproc, Comment, CommentPreproc), nil}, - {`(\{php\})(.*?)(\{/php\})`, ByGroups(CommentPreproc, Using("PHP"), CommentPreproc), nil}, - {`(\{)(/?[a-zA-Z_]\w*)(\s*)`, ByGroups(CommentPreproc, NameFunction, Text), Push("smarty")}, - {`\{`, CommentPreproc, Push("smarty")}, - }, - "smarty": { - {`\s+`, Text, nil}, - {`\{`, CommentPreproc, Push()}, - {`\}`, CommentPreproc, Pop(1)}, - {`#[a-zA-Z_]\w*#`, NameVariable, nil}, - {`\$[a-zA-Z_]\w*(\.\w+)*`, NameVariable, nil}, - {`[~!%^&*()+=|\[\]:;,.<>/?@-]`, Operator, nil}, - {`(true|false|null)\b`, KeywordConstant, nil}, - {`[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?`, LiteralNumber, nil}, - {`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil}, - {`'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil}, - {`[a-zA-Z_]\w*`, NameAttribute, nil}, - }, - } -} diff --git a/lexers/testdata/analysis/bash.actual b/lexers/testdata/analysis/bash.actual new file mode 100644 index 000000000..9838bebe4 --- /dev/null +++ b/lexers/testdata/analysis/bash.actual @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "This is a bash script" diff --git a/lexers/testdata/analysis/bash.expected b/lexers/testdata/analysis/bash.expected new file mode 100644 index 000000000..d3827e75a --- /dev/null +++ b/lexers/testdata/analysis/bash.expected @@ -0,0 +1 @@ +1.0 diff --git a/lexers/v.go b/lexers/v.go deleted file mode 100644 index 11561b3af..000000000 --- a/lexers/v.go +++ /dev/null @@ -1,173 +0,0 @@ -package lexers - -import ( - "strings" - - . "github.com/alecthomas/chroma/v2" // nolint -) - -// V lexer. -var V = Register(MustNewLexer( - &Config{ - Name: "V", - Aliases: []string{"v", "vlang"}, - Filenames: []string{"*.v", "*.vv", "v.mod"}, - MimeTypes: []string{"text/x-v"}, - EnsureNL: true, - }, - vRules, -).SetAnalyser(func(text string) float32 { - if strings.Contains(text, "import ") && strings.Contains(text, "module ") { - return 0.2 - } - if strings.Contains(text, "module ") { - return 0.1 - } - return 0.0 -})) - -const ( - namePattern = `[^\W\d]\w*` - typeNamePattern = `[A-Z]\w*` - multiLineCommentPattern = `/\*(?:.|\n)*?\*/` -) - -func vRules() Rules { - return Rules{ - "root": { - {`\n`, Text, nil}, - {`\s+`, Text, nil}, - {`\\\n`, Text, nil}, - {`(?<=module\s+\w[^\n]*\s+)(//[^\n]+\n)+(?=\n)`, StringDoc, nil}, - {`(// *)(\w+)([^\n]+\n)(?=(?://[^\n]*\n)* *(?:pub +)?(?:fn|struct|union|type|interface|enum|const) +\2\b)`, ByGroups(StringDoc, GenericEmph, StringDoc), Push(`string-doc`)}, - {`//[^\n]*\n`, CommentSingle, nil}, - {`/\*(?:(?:` + multiLineCommentPattern + `)*|.|\n)*\*/`, CommentMultiline, nil}, - {`\b(import|module)\b`, KeywordNamespace, nil}, - {`\b(fn|struct|union|map|chan|type|interface|enum|const|mut|shared|pub|__global)\b`, KeywordDeclaration, nil}, - {`\?`, KeywordDeclaration, nil}, - {`(?<=\)\s*)!`, KeywordDeclaration, nil}, - {`[ \t]*#include[^\n]+`, Using(`c`), nil}, - {`[ \t]*#\w[^\n]*`, CommentPreproc, nil}, - {`(sql)(\s+)(\w+)(\s+)({)([^}]*?)(})`, ByGroups(Keyword, Text, Name, Text, Punctuation, Using(`sql`), Punctuation), nil}, - {`\$(?=\w)`, Operator, nil}, - {`(?<=\$)(?:embed_file|pkgconfig|tmpl|env|compile_error|compile_warn)`, NameBuiltin, nil}, - {`(asm)(\s+)(\w+)(\s*)({)([^}]*?)(})`, ByGroups(Keyword, Text, KeywordType, Text, Punctuation, Using(`nasm`), Punctuation), nil}, - {`\b_(?:un)?likely_(?=\()`, NameFunctionMagic, nil}, - {`(?<=\$if.+?(?:&&|\|\|)?)(` + Words(``, ``, `windows`, `linux`, `macos`, `mac`, `darwin`, `ios`, `android`, `mach`, `dragonfly`, `gnu`, `hpux`, `haiku`, `qnx`, `solaris`, `gcc`, `tinyc`, `clang`, `mingw`, `msvc`, `cplusplus`, `amd64`, `arm64`, `x64`, `x32`, `little_endian`, `big_endian`, `debug`, `prod`, `test`, `js`, `glibc`, `prealloc`, `no_bounds_checking`, `freestanding`, `no_segfault_handler`, `no_backtrace`, `no_main`) + `)+`, NameBuiltin, nil}, - {`@` + Words(``, `\b`, `FN`, `METHOD`, `MOD`, `STRUCT`, `FILE`, `LINE`, `COLUMN`, `VEXE`, `VEXEROOT`, `VHASH`, `VMOD_FILE`, `VMODROOT`), NameVariableMagic, nil}, - {Words(`\b(?>=|>>>=|>>>|<<|>>|<=|>=|\^=|\+=|-=|\*=|/=|%=|&=|\|=|&&|\|\||<-|\+\+|--|==|!=|:=|\.\.\.|\.\.|[+\-*/%&|^~=#@!])`, Operator, nil}, - {`[\d_]+(\.\d+e[+\-]?\d+|\.\d+|e[+\-]?\d+)`, LiteralNumberFloat, nil}, - {`\.\d+(e[+\-]?\d+)?`, LiteralNumberFloat, nil}, - {`0o[0-7_]+`, LiteralNumberOct, nil}, - {`0x[0-9a-fA-F_]+`, LiteralNumberHex, nil}, - {`0b[01_]+`, LiteralNumberBin, nil}, - {`(0|[1-9][0-9_]*)`, LiteralNumberInteger, nil}, - {"`", StringChar, Push(`char`)}, - Include(`strings`), - {`@?` + typeNamePattern, NameClass, nil}, - {`(?<=` + namePattern + `)(<)(` + typeNamePattern + `)(>)`, ByGroups(Punctuation, NameClass, Punctuation), nil}, - {`@?` + namePattern + `(?=\()`, NameFunction, nil}, - {`(?<=fn\s+)@?` + namePattern + `(?=\s*\()`, NameFunction, nil}, - {`(?<=(?:continue|break|goto)\s+)\w+`, NameLabel, nil}, - {`\b` + namePattern + `(?=:(?:$|\s+for))`, NameLabel, nil}, - {`[<>()\[\]{}.,;:]`, Punctuation, nil}, - {`@?` + namePattern, NameVariable, nil}, - }, - "strings": { - {`(c)?(")`, ByGroups(StringAffix, StringDouble), Push(`string-double`)}, - {`(c)?(')`, ByGroups(StringAffix, StringSingle), Push(`string-single`)}, - {`(r)("[^"]+")`, ByGroups(StringAffix, String), nil}, - {`(r)('[^']+')`, ByGroups(StringAffix, String), nil}, - }, - "string-double": { - {`"`, StringDouble, Pop(1)}, - Include(`char-escape`), - {`(\$)((?!\\){)`, ByGroups(Operator, Punctuation), Push(`string-curly-interpolation`)}, - {`\$`, Operator, Push(`string-interpolation`)}, - {`[^"]+?`, StringDouble, nil}, - }, - "string-single": { - {`'`, StringSingle, Pop(1)}, - Include(`char-escape`), - {`(\$)((?!\\){)`, ByGroups(Operator, Punctuation), Push(`string-curly-interpolation`)}, - {`\$`, Operator, Push(`string-interpolation`)}, - {`[^']+?`, StringSingle, nil}, - }, - "char": { - {"`", StringChar, Pop(1)}, - Include(`char-escape`), - {`[^\\]`, StringChar, nil}, - }, - "char-escape": { - {"\\\\[`'\"\\\\abfnrtv$]|\\\\x[0-9a-fA-F]{2}|\\\\[0-7]{1,3}|\\\\u[0-9a-fA-F]{4}|\\\\U[0-9a-fA-F]{8}", StringEscape, nil}, - }, - "string-doc": { - {`(// *)(#+ [^\n]+)(\n)`, ByGroups(StringDoc, GenericHeading, Text), nil}, - {`// *([=_*~-])\1{2,}\n`, StringDelimiter, nil}, - {`//[^\n]*\n`, StringDoc, nil}, - Default(Pop(1)), - }, - "string-interpolation": { - {`(\.)?(@)?(?:(` + namePattern + `)(\()([^)]*)(\))|(` + namePattern + `))`, ByGroups(Punctuation, Operator, NameFunction, Punctuation, UsingSelf(`root`), Punctuation, NameVariable), nil}, - Default(Pop(1)), - }, - "string-curly-interpolation": { - {`}`, Punctuation, Pop(1)}, - Include(`strings`), - {`(:)( *?)([ 0'#+-])?(?:(\.)?([0-9]+))?([fFgeEGxXobsd])?`, ByGroups(Punctuation, Text, Operator, Punctuation, Number, StringAffix), nil}, - {`[^}"':]+`, UsingSelf(`root`), nil}, - }, - "attribute": { - {`\]`, Punctuation, Pop(1)}, - {`'`, Punctuation, Push(`string-single`)}, - {`"`, Punctuation, Push(`string-double`)}, - {`[;:]`, Punctuation, nil}, - {`(?<=\[)if\b`, Keyword, nil}, - {`\s+`, Text, nil}, - {`(?<=: *)\w+`, String, nil}, - {namePattern, NameAttribute, nil}, - }, - } -} - -// V shell lexer. -var VSH = Register(MustNewLexer( - &Config{ - Name: "V shell", - Aliases: []string{"vsh", "vshell"}, - Filenames: []string{"*.vsh"}, - MimeTypes: []string{"text/x-vsh"}, - EnsureNL: true, - }, - vshRules, -).SetAnalyser(func(text string) float32 { - firstLine := strings.Split(text, "\n")[0] - if strings.Contains(firstLine, "#!/usr/bin/env") && strings.Contains(firstLine, "v run") { - return 1.0 - } - if strings.Contains(firstLine, "#!/") && strings.Contains(firstLine, "/v run") { - return 1.0 - } - return 0.0 -})) - -func vshRules() Rules { - vshRules := vRules() - vshRoot := []Rule{ - {`^#![^\n]*\n`, CommentHashbang, nil}, - {Words(`\b`, `\b`, `args`, `max_path_len`, `wd_at_startup`, `sys_write`, `sys_open`, `sys_close`, `sys_mkdir`, `sys_creat`, `path_separator`, `path_delimiter`, `s_ifmt`, `s_ifdir`, `s_iflnk`, `s_isuid`, `s_isgid`, `s_isvtx`, `s_irusr`, `s_iwusr`, `s_ixusr`, `s_irgrp`, `s_iwgrp`, `s_ixgrp`, `s_iroth`, `s_iwoth`, `s_ixoth`), NameConstant, nil}, - {Words(`\b`, `\b`, `ProcessState`, `SeekMode`, `Signal`, `Command`, `ExecutableNotFoundError`, `File`, `FileNotOpenedError`, `Process`, `Result`, `SizeOfTypeIs0Error`, `Uname`), NameBuiltin, nil}, - {Words(`\b`, `(?=\()`, `abs_path`, `args_after`, `args_before`, `base`, `cache_dir`, `chdir`, `chmod`, `chown`, `config_dir`, `cp`, `cp_all`, `create`, `debugger_present`, `dir`, `environ`, `executable`, `execute`, `execute_or_exit`, `execute_or_panic`, `execve`, `execvp`, `existing_path`, `exists`, `exists_in_system_path`, `expand_tilde_to_home`, `fd_close`, `fd_read`, `fd_slurp`, `fd_write`, `file_ext`, `file_last_mod_unix`, `file_name`, `file_size`, `fileno`, `find_abs_path_of_executable`, `flush`, `fork`, `get_error_msg`, `get_line`, `get_lines`, `get_lines_joined`, `get_raw_line`, `get_raw_lines_joined`, `get_raw_stdin`, `getegid`, `getenv`, `getenv_opt`, `geteuid`, `getgid`, `getpid`, `getppid`, `getuid`, `getwd`, `glob`, `home_dir`, `hostname`, `inode`, `input`, `input_opt`, `is_abs_path`, `is_atty`, `is_dir`, `is_dir_empty`, `is_executable`, `is_file`, `is_link`, `is_readable`, `is_writable`, `is_writable_folder`, `join_path`, `join_path_single`, `last_error`, `link`, `log`, `loginname`, `ls`, `mkdir`, `mkdir_all`, `mv`, `mv_by_cp`, `new_process`, `norm_path`, `open`, `open_append`, `open_file`, `open_uri`, `posix_get_error_msg`, `posix_set_permission_bit`, `quoted_path`, `read_bytes`, `read_file`, `read_file_array`, `read_lines`, `real_path`, `resource_abs_path`, `rm`, `rmdir`, `rmdir_all`, `setenv`, `sigint_to_signal_name`, `signal_opt`, `stderr`, `stdin`, `stdout`, `symlink`, `system`, `temp_dir`, `truncate`, `uname`, `unsetenv`, `user_os`, `utime`, `vfopen`, `vmodules_dir`, `vmodules_paths`, `wait`, `walk`, `walk_ext`, `walk_with_context`, `write_file`, `write_file_array`, `bitmask`, `close`, `read_line`, `start`, `msg`, `read`, `read_bytes_at`, `read_bytes_into`, `read_bytes_into_newline`, `read_from`, `read_into_ptr`, `read_raw`, `read_raw_at`, `read_struct`, `read_struct_at`, `seek`, `tell`, `write`, `write_raw`, `write_raw_at`, `write_string`, `write_struct`, `write_struct_at`, `write_to`, `writeln`, `is_alive`, `run`, `set_args`, `set_environment`, `set_redirect_stdio`, `signal_continue`, `signal_kill`, `signal_pgkill`, `signal_stop`, `stderr_read`, `stderr_slurp`, `stdin_write`, `stdout_read`, `stdout_slurp`), NameBuiltin, nil}, - } - - vshRules[`root`] = append(vshRoot, vshRules[`root`]...) - - return vshRules -} diff --git a/lexers/vim.go b/lexers/vim.go deleted file mode 100644 index 511306256..000000000 --- a/lexers/vim.go +++ /dev/null @@ -1,40 +0,0 @@ -package lexers - -import ( - . "github.com/alecthomas/chroma/v2" // nolint -) - -// Viml lexer. -var Viml = Register(MustNewLexer( - &Config{ - Name: "VimL", - Aliases: []string{"vim"}, - Filenames: []string{"*.vim", ".vimrc", ".exrc", ".gvimrc", "_vimrc", "_exrc", "_gvimrc", "vimrc", "gvimrc"}, - MimeTypes: []string{"text/x-vim"}, - }, - vimlRules, -)) - -func vimlRules() Rules { - return Rules{ - "root": { - {`^([ \t:]*)(py(?:t(?:h(?:o(?:n)?)?)?)?)([ \t]*)(<<)([ \t]*)(.*)((?:\n|.)*)(\6)`, ByGroups(UsingSelf("root"), Keyword, Text, Operator, Text, Text, Using("Python"), Text), nil}, - {`^([ \t:]*)(py(?:t(?:h(?:o(?:n)?)?)?)?)([ \t])(.*)`, ByGroups(UsingSelf("root"), Keyword, Text, Using("Python")), nil}, - {`^\s*".*`, Comment, nil}, - {`[ \t]+`, Text, nil}, - {`/(\\\\|\\/|[^\n/])*/`, LiteralStringRegex, nil}, - {`"(\\\\|\\"|[^\n"])*"`, LiteralStringDouble, nil}, - {`'(''|[^\n'])*'`, LiteralStringSingle, nil}, - {`(?<=\s)"[^\-:.%#=*].*`, Comment, nil}, - {`-?\d+`, LiteralNumber, nil}, - {`#[0-9a-f]{6}`, LiteralNumberHex, nil}, - {`^:`, Punctuation, nil}, - {`[()<>+=!|,~-]`, Punctuation, nil}, - {`\b(let|if|else|endif|elseif|fun|function|endfunction|set|map|autocmd|filetype|hi(ghlight)?|execute|syntax|colorscheme)\b`, Keyword, nil}, - {`\b(NONE|bold|italic|underline|dark|light)\b`, NameBuiltin, nil}, - {`\b\w+\b`, NameOther, nil}, - {`\n`, Text, nil}, - {`.`, Text, nil}, - }, - } -} diff --git a/mutators.go b/mutators.go index ae648aae4..e80ad97a5 100644 --- a/mutators.go +++ b/mutators.go @@ -69,7 +69,7 @@ func (m *multiMutator) MarshalXML(e *xml.Encoder, start xml.StartElement) error return e.EncodeToken(xml.EndElement{Name: name}) } -func (m *multiMutator) MutatorKind() string { return "multiple" } +func (m *multiMutator) MutatorKind() string { return "mutators" } func (m *multiMutator) Mutate(state *LexerState) error { for _, modifier := range m.Mutators { diff --git a/serialise.go b/serialise.go index f29dc5d7e..645a5faab 100644 --- a/serialise.go +++ b/serialise.go @@ -168,7 +168,7 @@ func NewXMLLexer(from fs.FS, path string) (*RegexLexer, error) { return 0 } - if ok && config.Analyse.Single { + if ok && config.Analyse.First { return float32(math.Min(float64(ra.score), 1.0)) }