vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
meson.lua
(5659B)
1 -- Copyright 2020-2025 Florian Fischer. See LICENSE.
2 -- Meson file LPeg lexer.
3
4 local lexer = lexer
5 local S = lpeg.S
6
7 local lex = lexer.new(..., {fold_by_indentation = true})
8
9 -- Keywords.
10 lex:add_rule('keyword', lex:tag(lexer.KEYWORD, lex:word_match(lexer.KEYWORD)))
11
12 -- Functions.
13 -- https://mesonbuild.com/Reference-manual.html#builtin-objects
14 -- https://mesonbuild.com/Reference-manual.html#returned-objects
15 local method = lex:tag(lexer.FUNCTION_METHOD, lex:word_match(lexer.FUNCTION_METHOD))
16 -- https://mesonbuild.com/Reference-manual.html#functions
17 local func = lex:tag(lexer.FUNCTION_BUILTIN, lex:word_match(lexer.FUNCTION_BUILTIN))
18 -- A function call must be followed by an opening parenthesis. The matching of function calls
19 -- instead of just their names is needed to not falsely highlight function names which can also
20 -- be keyword arguments. For example 'include_directories' can be a function call itself or a
21 -- keyword argument of an 'executable' or 'library' function call.
22 lex:add_rule('function', (method + func) * #(lexer.space^0 * '('))
23
24 -- Builtin objects.
25 -- https://mesonbuild.com/Reference-manual.html#builtin-objects
26 lex:add_rule('object', lex:tag(lexer.VARIABLE_BUILTIN, lex:word_match(lexer.VARIABLE_BUILTIN)))
27
28 -- Constants.
29 lex:add_rule('constant', lex:tag(lexer.CONSTANT_BUILTIN, lex:word_match(lexer.CONSTANT_BUILTIN)))
30
31 -- Identifiers.
32 lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.word))
33
34 -- Strings.
35 local str = lexer.range("'", true)
36 local multiline_str = lexer.range("'''")
37 lex:add_rule('string', lex:tag(lexer.STRING, multiline_str + str))
38
39 -- Comments.
40 lex:add_rule('comment', lex:tag(lexer.COMMENT, lexer.to_eol('#', true)))
41
42 -- Numbers.
43 local oct_num = '0o' * lpeg.R('07')
44 local integer = S('+-')^-1 * (lexer.hex_num + lexer.bin_num + oct_num + lexer.dec_num)
45 lex:add_rule('number', lex:tag(lexer.NUMBER, integer))
46
47 -- Operators.
48 lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('()[]{}-=+/%:.,?<>')))
49
50 -- Word lists
51 lex:set_word_list(lexer.KEYWORD, {
52 'and', 'or', 'not', 'if', 'elif', 'else', 'endif', 'foreach', 'break', 'continue', 'endforeach'
53 })
54
55 lex:set_word_list(lexer.FUNCTION_METHOD, {
56 -- array --
57 'contains', 'get', 'length',
58 -- boolean --
59 'to_int', 'to_string',
60 -- dictionary --
61 'has_key', 'get', 'keys',
62 -- disabler --
63 'found',
64 -- integer --
65 'is_even', 'is_odd',
66 -- string --
67 'contains', 'endswith', 'format', 'join', 'split', 'startswith', 'substring', 'strip', 'to_int',
68 'to_lower', 'to_upper', 'underscorify', 'version_compare',
69 -- meson object --
70 'add_dist_script', 'add_install_script', 'add_postconf_script', 'backend', 'build_root',
71 'source_root', 'project_build_root', 'project_source_root', 'current_build_dir',
72 'current_source_dir', 'get_compiler', 'get_cross_property', 'get_external_property',
73 'can_run_host_binaries', 'has_exe_wrapper', 'install_dependency_manifest', 'is_cross_build',
74 'is_subproject', 'is_unity', 'override_find_program', 'override_dependency', 'project_version',
75 'project_license', 'project_name', 'version',
76 -- *_machine object --
77 'cpu_family', 'cpu', 'system', 'endian',
78 -- compiler object --
79 'alignment', 'cmd_array', 'compiles', 'compute_int', 'find_library', 'first_supported_argument',
80 'first_supported_link_argument', 'get_define', 'get_id', 'get_argument_syntax', 'get_linker_id',
81 'get_supported_arguments', 'get_supported_link_arguments', 'has_argument', 'has_link_argument',
82 'has_function', 'check_header', 'has_header', 'has_header_symbol', 'has_member', 'has_members',
83 'has_multi_arguments', 'has_multi_link_arguments', 'has_type', 'links', 'run',
84 'symbols_have_underscore_prefix', 'sizeof', 'version', 'has_function_attribute',
85 'get_supported_function_attributes',
86 -- build target object --
87 'extract_all_objects', 'extract_objects', 'full_path', 'private_dir_include', 'name',
88 -- configuration data object --
89 'get', 'get_unquoted', 'has', 'keys', 'merge_from', 'set', 'set10', 'set_quoted',
90 -- custom target object --
91 'full_path', 'to_list',
92 -- dependency object --
93 'found', 'name', 'get_pkgconfig_variable', 'get_configtool_variable', 'type_name', 'version',
94 'include_type', 'as_system', 'as_link_whole', 'partial_dependency', 'found',
95 -- external program object --
96 'found', 'path', 'full_path',
97 -- environment object --
98 'append', 'prepend', 'set',
99 -- external library object --
100 'found', 'type_name', 'partial_dependency', 'enabled', 'disabled', 'auto',
101 -- generator object --
102 'process',
103 -- subproject object --
104 'found', 'get_variable',
105 -- run result object --
106 'compiled', 'returncode', 'stderr', 'stdout'
107 })
108
109 lex:set_word_list(lexer.FUNCTION_BUILTIN, {
110 'add_global_arguments', 'add_global_link_arguments', 'add_languages', 'add_project_arguments',
111 'add_project_link_arguments', 'add_test_setup', 'alias_targ', 'assert', 'benchmark',
112 'both_libraries', 'build_target', 'configuration_data', 'configure_file', 'custom_target',
113 'declare_dependency', 'dependency', 'disabler', 'error', 'environment', 'executable',
114 'find_library', 'find_program', 'files', 'generator', 'get_option', 'get_variable', 'import',
115 'include_directories', 'install_data', 'install_headers', 'install_man', 'install_subdir',
116 'is_disabler', 'is_variable', 'jar', 'join_paths', 'library', 'message', 'warning', 'summary',
117 'project', 'run_command', 'run_targ', 'set_variable', 'shared_library', 'shared_module',
118 'static_library', 'subdir', 'subdir_done', 'subproject', 'test', 'vcs_tag'
119 })
120
121 lex:set_word_list(lexer.VARIABLE_BUILTIN, {
122 'meson', 'build_machine', 'host_machine', 'target_machine'
123 })
124
125 lex:set_word_list(lexer.CONSTANT_BUILTIN, {'false', 'true'})
126
127 lexer.property['scintillua.comment'] = '#'
128
129 return lex