aboutsummaryrefslogtreecommitdiff
path: root/lua/lexers/matlab.lua
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2023-08-11 01:27:32 +0200
committerRandy Palamar <randy@rnpnr.xyz>2024-03-27 06:04:21 -0600
commit4c4392d29df777ff702dfe99b4f3c23142976e05 (patch)
tree5355324abe18952f7d19d6cfc5dbeb5d6cb72b84 /lua/lexers/matlab.lua
parent95bf9f59f8a9a37148bdc0787db378d62c7cd032 (diff)
downloadvis-4c4392d29df777ff702dfe99b4f3c23142976e05.tar.gz
vis-4c4392d29df777ff702dfe99b4f3c23142976e05.tar.xz
update lexers to orbitalquark/scintillua@b789dde
Rather than cherry pick patches from after 6.2 we will just grab everything as is.
Diffstat (limited to 'lua/lexers/matlab.lua')
-rw-r--r--lua/lexers/matlab.lua101
1 files changed, 54 insertions, 47 deletions
diff --git a/lua/lexers/matlab.lua b/lua/lexers/matlab.lua
index b4871b3..5a26d27 100644
--- a/lua/lexers/matlab.lua
+++ b/lua/lexers/matlab.lua
@@ -1,73 +1,45 @@
--- Copyright 2006-2022 Martin Morawetz. See LICENSE.
+-- Copyright 2006-2024 Martin Morawetz. See LICENSE.
-- Matlab LPeg lexer.
-- Based off of lexer code by Mitchell.
-local lexer = require('lexer')
-local token, word_match = lexer.token, lexer.word_match
-local P, S = lpeg.P, lpeg.S
+local lexer = lexer
+local P, B, S = lpeg.P, lpeg.B, lpeg.S
-local lex = lexer.new('matlab')
-
--- Whitespace.
-lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
+local lex = lexer.new(...)
-- Keywords.
-lex:add_rule('keyword', token(lexer.KEYWORD, word_match({
- 'break', 'case', 'catch', 'continue', 'do', 'else', 'elseif', 'end', 'end_try_catch',
- 'end_unwind_protect', 'endfor', 'endif', 'endswitch', 'endwhile', 'for', 'function',
- 'endfunction', 'global', 'if', 'otherwise', 'persistent', 'replot', 'return', 'static', 'switch',
- 'try', 'until', 'unwind_protect', 'unwind_protect_cleanup', 'varargin', 'varargout', 'while'
-}, true)))
+lex:add_rule('keyword', lex:tag(lexer.KEYWORD, lex:word_match(lexer.KEYWORD)))
-- Functions.
-lex:add_rule('function', token(lexer.FUNCTION, word_match{
- 'abs', 'any', 'argvatan2', 'axes', 'axis', 'ceil', 'cla', 'clear', 'clf', 'columns', 'cos',
- 'delete', 'diff', 'disp', 'doc', 'double', 'drawnow', 'exp', 'figure', 'find', 'fix', 'floor',
- 'fprintf', 'gca', 'gcf', 'get', 'grid', 'help', 'hist', 'hold', 'isempty', 'isnull', 'length',
- 'load', 'log', 'log10', 'loglog', 'max', 'mean', 'median', 'min', 'mod', 'ndims', 'numel',
- 'num2str', 'ones', 'pause', 'plot', 'printf', 'quit', 'rand', 'randn', 'rectangle', 'rem',
- 'repmat', 'reshape', 'round', 'rows', 'save', 'semilogx', 'semilogy', 'set', 'sign', 'sin',
- 'size', 'sizeof', 'size_equal', 'sort', 'sprintf', 'squeeze', 'sqrt', 'std', 'strcmp', 'subplot',
- 'sum', 'tan', 'tic', 'title', 'toc', 'uicontrol', 'who', 'xlabel', 'ylabel', 'zeros'
-}))
-
--- Constants.
-lex:add_rule('constant', token(lexer.CONSTANT, word_match(
- 'EDITOR I IMAGEPATH INFO_FILE J LOADPATH OCTAVE_VERSION PAGER PS1 PS2 PS4 PWD')))
+-- Note: cannot tag normal functions because indexing variables uses the same syntax.
+local builtin_func = lex:tag(lexer.FUNCTION_BUILTIN, lex:word_match(lexer.FUNCTION_BUILTIN))
+lex:add_rule('function', builtin_func * #(lexer.space^0 * S('(')))
-- Variable.
-lex:add_rule('variable', token(lexer.VARIABLE, word_match{
- 'ans', 'automatic_replot', 'default_return_value', 'do_fortran_indexing',
- 'define_all_return_values', 'empty_list_elements_ok', 'eps', 'false', 'gnuplot_binary',
- 'ignore_function_time_stamp', 'implicit_str_to_num_ok', 'Inf', 'inf', 'NaN', 'nan',
- 'ok_to_lose_imaginary_part', 'output_max_field_width', 'output_precision', 'page_screen_output',
- 'pi', 'prefer_column_vectors', 'prefer_zero_one_indexing', 'print_answer_id_name',
- 'print_empty_dimensions', 'realmax', 'realmin', 'resize_on_range_error',
- 'return_last_computed_value', 'save_precision', 'silent_functions', 'split_long_rows',
- 'suppress_verbose_help_message', 'treat_neg_dim_as_zero', 'true', 'warn_assign_as_truth_value',
- 'warn_comma_in_global_decl', 'warn_divide_by_zero', 'warn_function_name_clash',
- 'whitespace_in_literal_matrix'
-}))
+lex:add_rule('variable', lex:tag(lexer.VARIABLE_BUILTIN, lex:word_match(lexer.VARIABLE_BUILTIN)))
+
+-- Constants.
+lex:add_rule('constant', lex:tag(lexer.CONSTANT_BUILTIN, lex:word_match(lexer.CONSTANT_BUILTIN)))
-- Identifiers.
-lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
+lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.word))
-- Strings.
local sq_str = lexer.range("'", true)
local dq_str = lexer.range('"')
local bq_str = lexer.range('`')
-lex:add_rule('string', token(lexer.STRING, sq_str + dq_str + bq_str))
+lex:add_rule('string', lex:tag(lexer.STRING, sq_str + dq_str + bq_str))
-- Comments.
local line_comment = lexer.to_eol(S('%#'))
local block_comment = lexer.range('%{', '%}')
-lex:add_rule('comment', token(lexer.COMMENT, block_comment + line_comment))
+lex:add_rule('comment', lex:tag(lexer.COMMENT, block_comment + line_comment))
-- Numbers.
-lex:add_rule('number', token(lexer.NUMBER, lexer.number))
+lex:add_rule('number', lex:tag(lexer.NUMBER, lexer.number))
-- Operators.
-lex:add_rule('operator', token(lexer.OPERATOR, S('!%^&*()[]{}-=+/\\|:;.,?<>~`´')))
+lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('!%^&*()[]{}-=+/\\|:;.,?<>~`´')))
-- Fold points.
lex:add_fold_point(lexer.KEYWORD, 'if', 'end')
@@ -77,7 +49,42 @@ lex:add_fold_point(lexer.KEYWORD, 'switch', 'end')
lex:add_fold_point(lexer.OPERATOR, '(', ')')
lex:add_fold_point(lexer.OPERATOR, '[', ']')
lex:add_fold_point(lexer.COMMENT, '%{', '%}')
-lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('%'))
-lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('#'))
+
+-- Word lists
+lex:set_word_list(lexer.KEYWORD, {
+ 'break', 'case', 'catch', 'continue', 'do', 'else', 'elseif', 'end', 'end_try_catch',
+ 'end_unwind_protect', 'endfor', 'endif', 'endswitch', 'endwhile', 'for', 'function',
+ 'endfunction', 'global', 'if', 'otherwise', 'persistent', 'replot', 'return', 'static', 'switch',
+ 'try', 'until', 'unwind_protect', 'unwind_protect_cleanup', 'varargin', 'varargout', 'while'
+})
+
+lex:set_word_list(lexer.FUNCTION_BUILTIN, {
+ 'abs', 'any', 'argvatan2', 'axes', 'axis', 'ceil', 'cla', 'clear', 'clf', 'columns', 'cos',
+ 'delete', 'diff', 'disp', 'doc', 'double', 'drawnow', 'exp', 'figure', 'find', 'fix', 'floor',
+ 'fprintf', 'gca', 'gcf', 'get', 'grid', 'help', 'hist', 'hold', 'isempty', 'isnull', 'length',
+ 'load', 'log', 'log10', 'loglog', 'max', 'mean', 'median', 'min', 'mod', 'ndims', 'numel',
+ 'num2str', 'ones', 'pause', 'plot', 'printf', 'quit', 'rand', 'randn', 'rectangle', 'rem',
+ 'repmat', 'reshape', 'round', 'rows', 'save', 'semilogx', 'semilogy', 'set', 'sign', 'sin',
+ 'size', 'sizeof', 'size_equal', 'sort', 'sprintf', 'squeeze', 'sqrt', 'std', 'strcmp', 'subplot',
+ 'sum', 'tan', 'tic', 'title', 'toc', 'uicontrol', 'who', 'xlabel', 'ylabel', 'zeros'
+})
+
+lex:set_word_list(lexer.VARIABLE_BUILTIN, {
+ 'ans', 'automatic_replot', 'default_return_value', 'do_fortran_indexing',
+ 'define_all_return_values', 'empty_list_elements_ok', 'eps', 'gnuplot_binary',
+ 'ignore_function_time_stamp', 'implicit_str_to_num_ok', 'ok_to_lose_imaginary_part',
+ 'output_max_field_width', 'output_precision', 'page_screen_output', 'prefer_column_vectors',
+ 'prefer_zero_one_indexing', 'print_answer_id_name', 'print_empty_dimensions',
+ 'resize_on_range_error', 'return_last_computed_value', 'save_precision', 'silent_functions',
+ 'split_long_rows', 'suppress_verbose_help_message', 'treat_neg_dim_as_zero',
+ 'warn_assign_as_truth_value', 'warn_comma_in_global_decl', 'warn_divide_by_zero',
+ 'warn_function_name_clash', 'whitespace_in_literal_matrix'
+})
+
+lex:set_word_list(lexer.CONSTANT_BUILTIN, {
+ 'false', 'Inf', 'inf', 'NaN', 'nan', 'pi', 'realmax', 'realmin', 'true'
+})
+
+lexer.property['scintillua.comment'] = '%'
return lex