mirror of
https://github.com/alecthomas/chroma.git
synced 2026-06-20 11:35:42 +02:00
pygments2chroma updates (#509)
This commit is contained in:
@@ -210,10 +210,10 @@ using the included Python 3 script `pygments2chroma.py`. I use something like
|
||||
the following:
|
||||
|
||||
```sh
|
||||
python3 ~/Projects/chroma/_tools/pygments2chroma.py \
|
||||
python3 _tools/pygments2chroma.py \
|
||||
pygments.lexers.jvm.KotlinLexer \
|
||||
> ~/Projects/chroma/lexers/kotlin.go \
|
||||
&& gofmt -s -w ~/Projects/chroma/lexers/*.go
|
||||
> lexers/k/kotlin.go \
|
||||
&& gofmt -s -w lexers/k/kotlin.go
|
||||
```
|
||||
|
||||
See notes in [pygments-lexers.txt](https://github.com/alecthomas/chroma/blob/master/pygments-lexers.txt)
|
||||
|
||||
@@ -12,7 +12,7 @@ from pygments.token import _TokenType
|
||||
|
||||
|
||||
TEMPLATE = r'''
|
||||
package lexers
|
||||
package {{package}}
|
||||
|
||||
import (
|
||||
. "github.com/alecthomas/chroma" // nolint
|
||||
@@ -23,9 +23,11 @@ import (
|
||||
var {{upper_name}} = internal.Register(MustNewLazyLexer(
|
||||
&Config{
|
||||
Name: "{{name}}",
|
||||
Aliases: []string{ {{#aliases}}"{{.}}", {{/aliases}} },
|
||||
Filenames: []string{ {{#filenames}}"{{.}}", {{/filenames}} },
|
||||
MimeTypes: []string{ {{#mimetypes}}"{{.}}", {{/mimetypes}} },
|
||||
{{=<% %>=}}
|
||||
Aliases: []string{<%#aliases%>"<%.%>", <%/aliases%>},
|
||||
Filenames: []string{<%#filenames%>"<%.%>", <%/filenames%>},
|
||||
MimeTypes: []string{<%#mimetypes%>"<%.%>", <%/mimetypes%>},
|
||||
<%={{ }}=%>
|
||||
{{#re_not_multiline}}
|
||||
NotMultiline: true,
|
||||
{{/re_not_multiline}}
|
||||
@@ -185,9 +187,10 @@ def main():
|
||||
assert issubclass(lexer_cls, pygments_lexer.RegexLexer), 'can only translate from RegexLexer'
|
||||
|
||||
print(pystache.render(TEMPLATE, TemplateView(
|
||||
package=lexer_cls.name.lower()[0],
|
||||
name=lexer_cls.name,
|
||||
regex_flags=lexer_cls.flags,
|
||||
upper_name=to_camel_case(lexer_cls.name),
|
||||
upper_name=to_camel_case(re.sub(r'\W', '_', lexer_cls.name)),
|
||||
aliases=lexer_cls.aliases,
|
||||
filenames=lexer_cls.filenames,
|
||||
mimetypes=lexer_cls.mimetypes,
|
||||
|
||||
Reference in New Issue
Block a user