mirror of
https://github.com/alecthomas/chroma.git
synced 2025-03-17 20:58:08 +02:00
Add lexer for Meson build system
Ported pygments' lexer using pygments2chroma.py.
This commit is contained in:
parent
a0e9618fbc
commit
f09329ae62
51
lexers/m/meson.go
Normal file
51
lexers/m/meson.go
Normal file
@ -0,0 +1,51 @@
|
||||
package m
|
||||
|
||||
import (
|
||||
. "github.com/alecthomas/chroma" // nolint
|
||||
"github.com/alecthomas/chroma/lexers/internal"
|
||||
)
|
||||
|
||||
// Meson lexer.
|
||||
var Meson = internal.Register(MustNewLazyLexer(
|
||||
&Config{
|
||||
Name: "Meson",
|
||||
Aliases: []string{"meson", "meson.build"},
|
||||
Filenames: []string{"meson.build", "meson_options.txt"},
|
||||
MimeTypes: []string{"text/x-meson"},
|
||||
},
|
||||
func() Rules {
|
||||
return Rules{
|
||||
"root": {
|
||||
{`#.*?$`, Comment, nil},
|
||||
{`'''.*'''`, LiteralStringSingle, nil},
|
||||
{`[1-9][0-9]*`, LiteralNumberInteger, nil},
|
||||
{`0o[0-7]+`, LiteralNumberOct, nil},
|
||||
{`0x[a-fA-F0-9]+`, LiteralNumberHex, nil},
|
||||
Include("string"),
|
||||
Include("keywords"),
|
||||
Include("expr"),
|
||||
{`[a-zA-Z_][a-zA-Z_0-9]*`, Name, nil},
|
||||
{`\s+`, TextWhitespace, nil},
|
||||
},
|
||||
"string": {
|
||||
{`[']{3}([']{0,2}([^\\']|\\(.|\n)))*[']{3}`, LiteralString, nil},
|
||||
{`'.*?(?<!\\)(\\\\)*?'`, LiteralString, nil},
|
||||
},
|
||||
"keywords": {
|
||||
{Words(``, `\b`, `if`, `elif`, `else`, `endif`, `foreach`, `endforeach`, `break`, `continue`), Keyword, nil},
|
||||
},
|
||||
"expr": {
|
||||
{`(in|and|or|not)\b`, OperatorWord, nil},
|
||||
{`(\*=|/=|%=|\+]=|-=|==|!=|\+|-|=)`, Operator, nil},
|
||||
{`[\[\]{}:().,?]`, Punctuation, nil},
|
||||
{Words(``, `\b`, `true`, `false`), KeywordConstant, nil},
|
||||
Include("builtins"),
|
||||
{Words(``, `\b`, `meson`, `build_machine`, `host_machine`, `target_machine`), NameVariableMagic, nil},
|
||||
},
|
||||
"builtins": {
|
||||
{Words(`(?<!\.)`, `\b`, `add_global_arguments`, `add_global_link_arguments`, `add_languages`, `add_project_arguments`, `add_project_link_arguments`, `add_test_setup`, `assert`, `benchmark`, `both_libraries`, `build_target`, `configuration_data`, `configure_file`, `custom_target`, `declare_dependency`, `dependency`, `disabler`, `environment`, `error`, `executable`, `files`, `find_library`, `find_program`, `generator`, `get_option`, `get_variable`, `include_directories`, `install_data`, `install_headers`, `install_man`, `install_subdir`, `is_disabler`, `is_variable`, `jar`, `join_paths`, `library`, `message`, `project`, `range`, `run_command`, `set_variable`, `shared_library`, `shared_module`, `static_library`, `subdir`, `subdir_done`, `subproject`, `summary`, `test`, `vcs_tag`, `warning`), NameBuiltin, nil},
|
||||
{`(?<!\.)import\b`, NameNamespace, nil},
|
||||
},
|
||||
}
|
||||
},
|
||||
))
|
11
lexers/testdata/meson.actual
vendored
Normal file
11
lexers/testdata/meson.actual
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
project('foo', 'cpp', default_options : ['warning_level=3'])
|
||||
|
||||
required_modules = ['gnome']
|
||||
|
||||
foreach mod in required_modules
|
||||
import(mod)
|
||||
endforeach
|
||||
|
||||
# Comment
|
||||
zlib_dep = dependency('zlib')
|
||||
executable('''bar''', 'main.cc', dependencies : zlib_dep)
|
67
lexers/testdata/meson.expected
vendored
Normal file
67
lexers/testdata/meson.expected
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
[
|
||||
{"type":"NameBuiltin","value":"project"},
|
||||
{"type":"Punctuation","value":"("},
|
||||
{"type":"LiteralString","value":"'foo'"},
|
||||
{"type":"Punctuation","value":","},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"LiteralString","value":"'cpp'"},
|
||||
{"type":"Punctuation","value":","},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Name","value":"default_options"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Punctuation","value":":"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Punctuation","value":"["},
|
||||
{"type":"LiteralString","value":"'warning_level=3'"},
|
||||
{"type":"Punctuation","value":"])"},
|
||||
{"type":"TextWhitespace","value":"\n\n"},
|
||||
{"type":"Name","value":"required_modules"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Operator","value":"="},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Punctuation","value":"["},
|
||||
{"type":"LiteralString","value":"'gnome'"},
|
||||
{"type":"Punctuation","value":"]"},
|
||||
{"type":"TextWhitespace","value":"\n\n"},
|
||||
{"type":"Keyword","value":"foreach"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Name","value":"mod"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"OperatorWord","value":"in"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Name","value":"required_modules"},
|
||||
{"type":"TextWhitespace","value":"\n "},
|
||||
{"type":"NameNamespace","value":"import"},
|
||||
{"type":"Punctuation","value":"("},
|
||||
{"type":"Name","value":"mod"},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"TextWhitespace","value":"\n"},
|
||||
{"type":"Keyword","value":"endforeach"},
|
||||
{"type":"TextWhitespace","value":"\n\n"},
|
||||
{"type":"Comment","value":"# Comment"},
|
||||
{"type":"TextWhitespace","value":"\n"},
|
||||
{"type":"Name","value":"zlib_dep"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Operator","value":"="},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"NameBuiltin","value":"dependency"},
|
||||
{"type":"Punctuation","value":"("},
|
||||
{"type":"LiteralString","value":"'zlib'"},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"TextWhitespace","value":"\n"},
|
||||
{"type":"NameBuiltin","value":"executable"},
|
||||
{"type":"Punctuation","value":"("},
|
||||
{"type":"LiteralStringSingle","value":"'''bar'''"},
|
||||
{"type":"Punctuation","value":","},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"LiteralString","value":"'main.cc'"},
|
||||
{"type":"Punctuation","value":","},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Name","value":"dependencies"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Punctuation","value":":"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Name","value":"zlib_dep"},
|
||||
{"type":"Punctuation","value":")"},
|
||||
{"type":"TextWhitespace","value":"\n"}
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user