// 注册 MATLAB 语言
monaco.languages.register({ id: 'matlab' });
// 设置语言配置 (缩进/括号等)
monaco.languages.setLanguageConfiguration('matlab', {
comments: {
lineComment: '%',
blockComment: ['%{', '%}'],
},
brackets: [
['(', ')'],
['[', ']'],
['{', '}'],
],
indentationRules: {
increaseIndentPattern: /^.*(function|if|else|elseif|switch|case|for|while|try|catch|classdef|properties|methods).*$/i,
decreaseIndentPattern: /^.*(end|else|elseif|case|catch).*$/i,
},
});
// 设置基础语法高亮 (简化版)
monaco.languages.setMonarchTokensProvider('matlab', {
tokenizer: {
root: [
[/(\%{)[\s\S]*?(\%\})/, 'comment'],
[/\%.*$/, 'comment'],
[
/[a-zA-Z_]\w*/,
{
cases: {
'@keywords': 'keyword',
'@default': 'identifier',
},
},
],
[/[0-9]+(\.[0-9]+)?(e[+-]?[0-9]+)?/, 'number'],
],
},
keywords: [
'function',
'end',
'if',
'else',
'elseif',
'switch',
'case',
'otherwise',
'for',
'while',
'try',
'catch',
'return',
'break',
'continue',
'classdef',
'properties',
'methods',
],
});
05-02
2780
