Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions TeXmacs/plugins/matlab/progs/code/matlab-lang.scm
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@
`(,(string->symbol key)
(bool_features
"escape_char_after_backslash")
(escape_sequences "\\" "\"" "n" "t" "b" "r" "f" "a" "v" "0")))
(escape_sequences "\\" "\"" "n" "t" "b" "r" "f" "a" "v" "0")
(double_escape "'")
(start_disallow_after
"alpha" "digit" "underscore" ")" "]" "}" "." "'")))

;;------------------------------------------------------------------------------
;; 注释格式定义
Expand Down Expand Up @@ -140,4 +143,4 @@
("syntax:matlab:operator_special" "orange" notify-matlab-syntax)
("syntax:matlab:keyword" "#309090" notify-matlab-syntax)
("syntax:matlab:keyword_conditional" "#309090" notify-matlab-syntax)
("syntax:matlab:keyword_control" "#008080ff" notify-matlab-syntax))
("syntax:matlab:keyword_control" "#008080ff" notify-matlab-syntax))
226 changes: 226 additions & 0 deletions TeXmacs/tests/tmu/209_14.tmu
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
<TMU|<tuple|1.1.0|2026.1.2>>

<style|<tuple|generic|chinese|table-captions-above|number-europe|preview-ref|matlab>>

<\body>
<\matlab-code>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% MATLAB Quote / Transpose / String Highlight Test

% For Mogan / TeXmacs syntax highlighting

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\;

clc;

clear;

\;

%% 1. Basic string tests

\;

s1 = 'hello';

s2 = 'world';

s3 = 'it''s ok';

s4 = '';

s5 = '12345';

['a' 'b']

disp(s1);

disp(s3);

\;

\;

%% 2. Basic transpose tests

\;

A = rand(3,3);

B = A';

C = A'';

D = (A + B)';

E = A(1,:)';

F = A(:,2)';

\;

disp(B);

disp(D);

\;

\;

%% 3. Multiply + transpose

\;

x = rand(3,1);

y = rand(3,1);

\;

r1 = x' * y;

r2 = x'*y;

r3 = (x + y)' * x;

\;

disp(r1);

\;

\;

%% 4. String + transpose mixed

\;

s = 'abc';

T = A';

\;

u = 'x' + A'; \ \ \ \ \ \ \ \ \ \ % string + transpose

v = ['a','b','c']'; \ \ \ \ % char array + transpose

\;

disp(s);

disp(T);

\;

\;

%% 5. Function arguments

\;

sprintf('value = %f', pi);

disp('hello world');

\;

\;

%% 6. Complex nested cases

\;

M = rand(4,4);

\;

result = (M(1:2,2:3)' * M(3:4,1:2))';

\;

name = 'matrix';

msg \ = ['Result of ', name, ' is OK'];

\;

disp(msg);

\;

%% 7. Edge cases

\;

A2 = rand(2);

\;

B1 = A2'; C1 = A2'; D1 = A2';

\;

s6 = 'a'; t6 = 'b';

\;

x1 = (A2')';

y1 = ((A2)')';

\;

z1 = A2'';

\;

\;

%% 8. Minimal reproduction cases

\;

P = rand(3);

\;

Q = P';

R = 'abc';

S = P' + 1;

T2 = 'x' + P';

\;

\;

%% 9. Visual check block

\;

disp('===== Highlight Check Finished =====');

\;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% End of test file

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\;
</matlab-code>
</body>

<\initial>
<\collection>
<associate|page-medium|paper>
<associate|page-screen-margin|false>
</collection>
</initial>
32 changes: 32 additions & 0 deletions devel/209_14.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 209_14 MATLAB���뵥���Ÿ����޸�

## ����

1. ����Mogan
2. ����matlab�����
3. ���뺬�е����ŵĴ��룬�۲��Ƿ��ܱ���ȷ�ĸ��������磺
- `A' + B`
- `x = y' * z`
- `M(1,:)'`
- `C = A'';`
- `s3 = 'it''s ok';`
- `['a' 'b']`

�����ĵ��� `TeXmacs/tests/tmu/209_14.tmu`

## 2026/01/30
### What
- �����ַ�����ʼ���ƹ��򣬱��� MATLAB ת�� `'` �������ַ���
- ֧�ֵ������ַ����� `''` ת��
- �հ׺�������ʼ���ַ������� `['a' 'b']`��

### How
- ���� `start_disallow_after` ���ã����ַ�������ǰ�ж�ǰһ�ַ�
- `string_parser` ֧�� `double_escape`������ `''` �������ַ���
- MATLAB ���ã�`start_disallow_after (alpha digit underscore ) ] } . ')` �� `double_escape "'"`
- ������� `'` ����ǰһ�ַ�ʱ��Ч�����м��пհ����������ַ�����ʼ

### Why
- MATLAB �� `'` ����ת�������ַ�������������������
- �������ַ����� `''` �Ϸ�����Ҫ����ض�
- �ַ���ƴ�ӳ��ÿհ׷ָ���`['a' 'b']`���������ʶ��Ϊ�ַ���
29 changes: 27 additions & 2 deletions src/Data/Parser/string_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#include "iterator.hpp"

string_parser_rep::string_parser_rep () {
use_esc_parser= false;
use_esc_parser = false;
m_double_escapes= array<string> ();
reset ();
}

Expand Down Expand Up @@ -71,7 +72,13 @@ string_parser_rep::do_parse (string s, int& pos) {

// Advance until the end or the escaped sequence
string closing= m_pairs (m_start);
while (pos < N (s) && !test (s, pos, closing)) {
while (pos < N (s)) {
if (can_double_escape (closing) && test (s, pos, closing) &&
test (s, pos + N (closing), closing)) {
pos+= 2 * N (closing);
continue;
}
if (test (s, pos, closing)) break;
if (use_esc_parser && m_esc_parser.can_parse (s, pos)) {
if (m_skip_escaped) {
m_esc_parser.parse (s, pos);
Expand Down Expand Up @@ -110,6 +117,11 @@ string_parser_rep::set_pairs (hashmap<string, string> p_pairs) {
m_pairs= p_pairs;
}

void
string_parser_rep::set_double_escapes (array<string> p_double_escapes) {
m_double_escapes= p_double_escapes;
}

bool
string_parser_rep::escaped () {
return m_escaped;
Expand All @@ -136,6 +148,14 @@ string_parser_rep::skip_escaped (bool skip) {
m_skip_escaped= skip;
}

bool
string_parser_rep::can_double_escape (string closing) {
for (int i= 0; i < N (m_double_escapes); i++) {
if (m_double_escapes[i] == closing) return true;
}
return false;
}

string
string_parser_rep::to_string () {
string ret= parser_rep::to_string ();
Expand All @@ -145,6 +165,11 @@ string_parser_rep::to_string () {
while (iter->busy ()) {
ret << " - " << iter->next () << "\n";
}
ret << " double_escape:"
<< "\n";
for (int i= 0; i < N (m_double_escapes); i++) {
ret << " - " << m_double_escapes[i] << "\n";
}
ret << m_esc_parser.to_string ();
return ret;
}
3 changes: 3 additions & 0 deletions src/Data/Parser/string_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class string_parser_rep : public parser_rep {
string to_string ();

void set_pairs (hashmap<string, string> p_pairs);
void set_double_escapes (array<string> p_double_escapes);

bool unfinished ();
void reset ();
Expand Down Expand Up @@ -59,8 +60,10 @@ class string_parser_rep : public parser_rep {
bool use_esc_parser;
bool m_escaped;
bool m_skip_escaped;
array<string> m_double_escapes;

void do_parse (string s, int& pos);
bool can_double_escape (string closing);
};

#endif
9 changes: 7 additions & 2 deletions src/System/Language/impl_language.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@ struct prog_language_rep : abstract_language_rep {
void customize_path (tree config);
tree get_parser_config (string lan, string key);

bool inline_comment_requires_space;
bool path_parser_enabled;
bool inline_comment_requires_space;
bool path_parser_enabled;
bool string_start_disallow_after_alpha;
bool string_start_disallow_after_digit;
bool string_start_disallow_after_underscore;
array<char> string_start_disallow_after_chars;
bool string_skip_escaped;
};

struct scheme_language_rep : language_rep {
Expand Down
Loading