Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/meson.py: 100%
10 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
1"""
2 pygments.lexers.meson
3 ~~~~~~~~~~~~~~~~~~~~~
5 Pygments lexer for the Meson build system
7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
9"""
11from pygments.lexer import RegexLexer, words, include
12from pygments.token import Comment, Name, Number, Punctuation, Operator, \
13 Keyword, String, Whitespace
15__all__ = ['MesonLexer']
18class MesonLexer(RegexLexer):
19 """Meson language lexer.
21 The grammar definition use to transcribe the syntax was retrieved from
22 https://mesonbuild.com/Syntax.html#grammar for version 0.58.
23 Some of those definitions are improperly transcribed, so the Meson++
24 implementation was also checked: https://github.com/dcbaker/meson-plus-plus.
26 .. versionadded:: 2.10
27 """
29 # TODO String interpolation @VARNAME@ inner matches
30 # TODO keyword_arg: value inner matches
32 name = 'Meson'
33 url = 'https://mesonbuild.com/'
34 aliases = ['meson', 'meson.build']
35 filenames = ['meson.build', 'meson_options.txt']
36 mimetypes = ['text/x-meson']
38 tokens = {
39 'root': [
40 (r'#.*?$', Comment),
41 (r"'''.*'''", String.Single),
42 (r'[1-9][0-9]*', Number.Integer),
43 (r'0o[0-7]+', Number.Oct),
44 (r'0x[a-fA-F0-9]+', Number.Hex),
45 include('string'),
46 include('keywords'),
47 include('expr'),
48 (r'[a-zA-Z_][a-zA-Z_0-9]*', Name),
49 (r'\s+', Whitespace),
50 ],
51 'string': [
52 (r"[']{3}([']{0,2}([^\\']|\\(.|\n)))*[']{3}", String),
53 (r"'.*?(?<!\\)(\\\\)*?'", String),
54 ],
55 'keywords': [
56 (words((
57 'if',
58 'elif',
59 'else',
60 'endif',
61 'foreach',
62 'endforeach',
63 'break',
64 'continue',
65 ),
66 suffix=r'\b'), Keyword),
67 ],
68 'expr': [
69 (r'(in|and|or|not)\b', Operator.Word),
70 (r'(\*=|/=|%=|\+]=|-=|==|!=|\+|-|=)', Operator),
71 (r'[\[\]{}:().,?]', Punctuation),
72 (words(('true', 'false'), suffix=r'\b'), Keyword.Constant),
73 include('builtins'),
74 (words((
75 'meson',
76 'build_machine',
77 'host_machine',
78 'target_machine',
79 ),
80 suffix=r'\b'), Name.Variable.Magic),
81 ],
82 'builtins': [
83 # This list was extracted from the v0.58 reference manual
84 (words((
85 'add_global_arguments',
86 'add_global_link_arguments',
87 'add_languages',
88 'add_project_arguments',
89 'add_project_link_arguments',
90 'add_test_setup',
91 'assert',
92 'benchmark',
93 'both_libraries',
94 'build_target',
95 'configuration_data',
96 'configure_file',
97 'custom_target',
98 'declare_dependency',
99 'dependency',
100 'disabler',
101 'environment',
102 'error',
103 'executable',
104 'files',
105 'find_library',
106 'find_program',
107 'generator',
108 'get_option',
109 'get_variable',
110 'include_directories',
111 'install_data',
112 'install_headers',
113 'install_man',
114 'install_subdir',
115 'is_disabler',
116 'is_variable',
117 'jar',
118 'join_paths',
119 'library',
120 'message',
121 'project',
122 'range',
123 'run_command',
124 'set_variable',
125 'shared_library',
126 'shared_module',
127 'static_library',
128 'subdir',
129 'subdir_done',
130 'subproject',
131 'summary',
132 'test',
133 'vcs_tag',
134 'warning',
135 ),
136 prefix=r'(?<!\.)',
137 suffix=r'\b'), Name.Builtin),
138 (r'(?<!\.)import\b', Name.Namespace),
139 ],
140 }