diff options
| author | qiu-x <alex@alexslomka.xyz> | 2022-06-29 07:56:51 +0200 |
|---|---|---|
| committer | Felix Van der Jeugt <felix.vanderjeugt@posteo.net> | 2022-11-29 21:57:18 +0100 |
| commit | 8a420ecc4c1ed50111464ec66901bd983eaf2dbd (patch) | |
| tree | f31d2186cafaee6e7f18d32fe99144c3e8148c00 /lua/lexers/meson.lua | |
| parent | 981b90a203484182feace48471fe2b53dae7676f (diff) | |
| download | vis-8a420ecc4c1ed50111464ec66901bd983eaf2dbd.tar.gz vis-8a420ecc4c1ed50111464ec66901bd983eaf2dbd.tar.xz | |
Resync the lexers with Scintillua
- Resync the lexers with Scintillua
- Update the lexer readme
- Update `zenburn` theme to fix some highlighting issues
- lexers: redirect print function to vis:info()
- Fix support for custom style names
- As per error message "lexer.delimited_range() is deprecated, use lexer.range()".
- Remove remaining `lexer.delimited_range()` call
- Set syntax to `nil` if the file type has no matching lexer
- Updated Go lexer for Go 1.18.
- lexers/dsv: convert to new lexer format
(cherry picked from commit 9edbc3cd9ea1d7142b1305840432a3d2739e755a)
- lexers/gemini: disable legacy gemini lexer
This reverts commit 468f9ee1b027a7ce98b1a249fa1af5888feeb989.
It is in legacy format and of questionable quality. Ideally it
should be contributed upstream from where it will eventually
trickle down to us.
- lexers/git-rebase: convert to new lexer format
(cherry picked from commit 4000a4cc9ac4a4c2869dfae772b977a82aee8d8c)
- lexers/strace: convert to new lexer format
(cherry picked from commit e420451320d97eb164f5629c1bcfab0b595be29d)
- lexers/typescript: add new upstream lexer revision 28e2b60
(cherry picked from commit 7326e6deecdaa75fa94ae9ebdb653f9f907b33f2)
- use `package.searchpath` instead of a local `searchpath` function
- Restore `filetype: support filetype detection via hashbang`
- Remove redundant comment
- Restore gemini lexer
Diffstat (limited to 'lua/lexers/meson.lua')
| -rw-r--r-- | lua/lexers/meson.lua | 163 |
1 files changed, 64 insertions, 99 deletions
diff --git a/lua/lexers/meson.lua b/lua/lexers/meson.lua index b6cbe15..c224f82 100644 --- a/lua/lexers/meson.lua +++ b/lua/lexers/meson.lua @@ -1,36 +1,18 @@ --- Copyright 2020 Florian Fischer. See LICENSE. +-- Copyright 2020-2022 Florian Fischer. See LICENSE. -- Meson file LPeg lexer. -local l = require('lexer') -local token, word_match = l.token, l.word_match +local lexer = require('lexer') +local token, word_match = lexer.token, lexer.word_match local P, R, S = lpeg.P, lpeg.R, lpeg.S -local M = {_NAME = 'meson'} +local lex = lexer.new('meson', {fold_by_indentation = true}) -- Whitespace. -local ws = token(l.WHITESPACE, l.space^1) - --- Comments. -local comment = token(l.COMMENT, '#' * l.nonnewline_esc^0) - --- Strings. -local str = l.delimited_range("'", true) -local multiline_str = "'''" * (l.any - "'''")^0 * P("'''")^-1 -local string = token(l.STRING, multiline_str + str) - --- Numbers. -local dec = R('19')^1 * R('09')^0 -local bin = '0b' * S('01')^1 -local oct = '0o' * R('07')^1 -local integer = S('+-')^-1 * (bin + l.hex_num + oct + dec) -local number = token(l.NUMBER, integer) +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -local keyword = token(l.KEYWORD, word_match{ - 'and', 'or', 'not', - 'if', 'elif', 'else', 'endif', - 'foreach', 'break', 'continue', 'endforeach', -}) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match( + 'and or not if elif else endif foreach break continue endforeach'))) -- Methods. -- https://mesonbuild.com/Reference-manual.html#builtin-objects @@ -47,40 +29,34 @@ local method_names = word_match{ -- integer -- 'is_even', 'is_odd', -- string -- - 'contains', 'endswith', 'format', 'join', 'split', 'startswith', 'substring', - 'strip', 'to_int', 'to_lower', 'to_upper', 'underscorify', 'version_compare', + 'contains', 'endswith', 'format', 'join', 'split', 'startswith', 'substring', 'strip', 'to_int', + 'to_lower', 'to_upper', 'underscorify', 'version_compare', -- meson object -- - 'add_dist_script', 'add_install_script', 'add_postconf_script', 'backend', - 'build_root', 'source_root', 'project_build_root', 'project_source_root', - 'current_build_dir', 'current_source_dir', 'get_compiler', - 'get_cross_property', 'get_external_property', 'can_run_host_binaries', - 'has_exe_wrapper', 'install_dependency_manifest', 'is_cross_build', - 'is_subproject', 'is_unity', 'override_find_program', 'override_dependency', - 'project_version', 'project_license', 'project_name', 'version', + 'add_dist_script', 'add_install_script', 'add_postconf_script', 'backend', 'build_root', + 'source_root', 'project_build_root', 'project_source_root', 'current_build_dir', + 'current_source_dir', 'get_compiler', 'get_cross_property', 'get_external_property', + 'can_run_host_binaries', 'has_exe_wrapper', 'install_dependency_manifest', 'is_cross_build', + 'is_subproject', 'is_unity', 'override_find_program', 'override_dependency', 'project_version', + 'project_license', 'project_name', 'version', -- *_machine object -- 'cpu_family', 'cpu', 'system', 'endian', -- compiler object -- - 'alignment', 'cmd_array', 'compiles', 'compute_int', 'find_library', - 'first_supported_argument', 'first_supported_link_argument', 'get_define', - 'get_id', 'get_argument_syntax', 'get_linker_id', 'get_supported_arguments', - 'get_supported_link_arguments', 'has_argument', 'has_link_argument', - 'has_function', 'check_header', 'has_header', 'has_header_symbol', - 'has_member', 'has_members', 'has_multi_arguments', - 'has_multi_link_arguments', 'has_type', 'links', 'run', - 'symbols_have_underscore_prefix', 'sizeof', 'version', - 'has_function_attribute', 'get_supported_function_attributes', + 'alignment', 'cmd_array', 'compiles', 'compute_int', 'find_library', 'first_supported_argument', + 'first_supported_link_argument', 'get_define', 'get_id', 'get_argument_syntax', 'get_linker_id', + 'get_supported_arguments', 'get_supported_link_arguments', 'has_argument', 'has_link_argument', + 'has_function', 'check_header', 'has_header', 'has_header_symbol', 'has_member', 'has_members', + 'has_multi_arguments', 'has_multi_link_arguments', 'has_type', 'links', 'run', + 'symbols_have_underscore_prefix', 'sizeof', 'version', 'has_function_attribute', + 'get_supported_function_attributes', -- build target object -- - 'extract_all_objects', 'extract_objects', 'full_path', 'private_dir_include', - 'name', + 'extract_all_objects', 'extract_objects', 'full_path', 'private_dir_include', 'name', -- configuration data object -- - 'get', 'get_unquoted', 'has', 'keys', 'merge_from', 'set', 'set10', - 'set_quoted', + 'get', 'get_unquoted', 'has', 'keys', 'merge_from', 'set', 'set10', 'set_quoted', -- custom target object -- 'full_path', 'to_list', -- dependency object -- - 'found', 'name', 'get_pkgconfig_variable', 'get_configtool_variable', - 'type_name', 'version', 'include_type', 'as_system', 'as_link_whole', - 'partial_dependency', 'found', + 'found', 'name', 'get_pkgconfig_variable', 'get_configtool_variable', 'type_name', 'version', + 'include_type', 'as_system', 'as_link_whole', 'partial_dependency', 'found', -- external program object -- 'found', 'path', 'full_path', -- environment object -- @@ -92,70 +68,59 @@ local method_names = word_match{ -- subproject object -- 'found', 'get_variable', -- run result object -- - 'compiled', 'returncode', 'stderr', 'stdout', + 'compiled', 'returncode', 'stderr', 'stdout' } -- A method call must be followed by an opening parenthesis. -local method = token('method', method_names * #P(l.space^0 * S('('))) +lex:add_rule('method', token('method', method_names * #(lexer.space^0 * '('))) +lex:add_style('method', lexer.styles['function']) -- Function. -- https://mesonbuild.com/Reference-manual.html#functions -local func_names = word_match{ - 'add_global_arguments', 'add_global_link_arguments', 'add_languages', - 'add_project_arguments', 'add_project_link_arguments', 'add_test_setup', - 'alias_targ', 'assert', 'benchmark', 'both_libraries', 'build_target', - 'configuration_data', 'configure_file', 'custom_target', 'declare_dependency', - 'dependency', 'disabler', 'error', 'environment', 'executable', - 'find_library', 'find_program', 'files', 'generator', 'get_option', - 'get_variable', 'import', 'include_directories', 'install_data', - 'install_headers', 'install_man', 'install_subdir', 'is_disabler', - 'is_variable', 'jar', 'join_paths', 'library', 'message', 'warning', - 'summary', 'project', 'run_command', 'run_targ', 'set_variable', - 'shared_library', 'shared_module', 'static_library', 'subdir', 'subdir_done', - 'subproject', 'test', 'vcs_tag', +local func_names = word_match{ + 'add_global_arguments', 'add_global_link_arguments', 'add_languages', 'add_project_arguments', + 'add_project_link_arguments', 'add_test_setup', 'alias_targ', 'assert', 'benchmark', + 'both_libraries', 'build_target', 'configuration_data', 'configure_file', 'custom_target', + 'declare_dependency', 'dependency', 'disabler', 'error', 'environment', 'executable', + 'find_library', 'find_program', 'files', 'generator', 'get_option', 'get_variable', 'import', + 'include_directories', 'install_data', 'install_headers', 'install_man', 'install_subdir', + 'is_disabler', 'is_variable', 'jar', 'join_paths', 'library', 'message', 'warning', 'summary', + 'project', 'run_command', 'run_targ', 'set_variable', 'shared_library', 'shared_module', + 'static_library', 'subdir', 'subdir_done', 'subproject', 'test', 'vcs_tag' } --- A function call must be followed by an opening parenthesis. --- The matching of function calls instead of just their names is needed to not --- falsely highlight function names which can also be keyword arguments. --- For example 'include_directories' can be a function call itself or a keyword --- argument of an 'executable' or 'library' function call. -local func = token(l.FUNCTION, func_names * #P(l.space^0 * S('('))) +-- A function call must be followed by an opening parenthesis. The matching of function calls +-- instead of just their names is needed to not falsely highlight function names which can also +-- be keyword arguments. For example 'include_directories' can be a function call itself or a +-- keyword argument of an 'executable' or 'library' function call. +lex:add_rule('function', token(lexer.FUNCTION, func_names * #(lexer.space^0 * '('))) -- Builtin objects. -- https://mesonbuild.com/Reference-manual.html#builtin-objects -local object = token('object', word_match{ - 'meson', 'build_machine', 'host_machine', 'target_machine', -}) +lex:add_rule('object', + token('object', word_match('meson build_machine host_machine target_machine'))) +lex:add_style('object', lexer.styles.type) -- Constants. -local constant = token(l.CONSTANT, word_match{ - 'false', 'true', -}) +lex:add_rule('constant', token(lexer.CONSTANT, word_match('false true'))) -- Identifiers. -local identifier = token(l.IDENTIFIER, l.word) +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) --- Operators. -local operator = token(l.OPERATOR, S('()[]{}-=+/%:.,?<>')) +-- Strings. +local str = lexer.range("'", true) +local multiline_str = lexer.range("'''") +lex:add_rule('string', token(lexer.STRING, multiline_str + str)) -M._rules = { - {'whitespace', ws}, - {'keyword', keyword}, - {'method', method}, - {'function', func}, - {'object', object}, - {'constant', constant}, - {'identifier', identifier}, - {'comment', comment}, - {'string', string}, - {'number', number}, - {'operator', operator}, -} +-- Comments. +lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#', true))) -M._tokenstyles = { - method = l.STYLE_FUNCTION, - object = l.STYLE_TYPE, -} +-- Numbers. +local dec = R('19')^1 * R('09')^0 +local bin = '0b' * S('01')^1 +local oct = '0o' * R('07')^1 +local integer = S('+-')^-1 * (bin + lexer.hex_num + oct + dec) +lex:add_rule('number', token(lexer.NUMBER, integer)) -M._FOLDBYINDENTATION = true +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, S('()[]{}-=+/%:.,?<>'))) -return M +return lex |
