Skip to content

Commit a05a5b2

Browse files
committed
[209_7] 修复bash代码模式下的错误高亮
1 parent e9e472e commit a05a5b2

File tree

3 files changed

+55
-9
lines changed

3 files changed

+55
-9
lines changed

TeXmacs/tests/tmu/209_7.tmu

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<TMU|<tuple|1.1.0|2026.1.1>>
1+
<TMU|<tuple|1.1.0|2026.1.2>>
22

33
<style|<tuple|generic|chinese|table-captions-above|number-europe|preview-ref|bash>>
44

@@ -24,6 +24,38 @@
2424

2525
IFS=$'\\n\\t'
2626

27+
# ---------- path -------------
28+
29+
\;
30+
31+
tar xzvf nvim-linux-x86_64.tar.gz
32+
33+
sudo mv nvim-linux-x86_64 /opt/nvim
34+
35+
git clone [email protected]:XmacsLabs/mogan.git
36+
37+
cat chapter-3.1.tmu
38+
39+
3.2 4.5
40+
41+
\;
42+
43+
# ----------- commment ---------
44+
45+
echo $# # 行尾注释
46+
47+
\;
48+
49+
echo ${#PATH}#not_comment
50+
51+
echo "${#PATH}#still_not_comment"
52+
53+
\;
54+
55+
echo ${#PATH} # 这里才是注释
56+
57+
\;
58+
2759
\;
2860

2961
# ---------- globals ----------

devel/209_7.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,13 @@
3333

3434
关联 issue #2607
3535

36+
## 2026/01/29
37+
### What
38+
- 修复 Bash 代码模式下 `#``$#``${#...}` 中被误识别为注释的问题
39+
- 增加路径/URL 识别规则,避免路径/文件名中的关键字与数字误高亮(如 `abc.git`
40+
41+
### How
42+
-`prog_language.cpp` 增加可配置的 `path` 解析步骤,位于 `string_parser` 之后、`keyword/number` 之前;匹配到路径/URL token 则整体消费
43+
- `bash-lang.scm` 中启用 `path` 解析
44+
- 注释规则增加 `inline_require_space`:仅当 `#` 位于行首或空白后才作为注释起始
45+

src/System/Language/prog_language.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ prog_language_rep::prog_language_rep (string name)
2626
if (DEBUG_PARSER)
2727
debug_packrat << "Building the " * name * " language parser" << LF;
2828
inline_comment_requires_space= false;
29-
path_parser_enabled= false;
29+
path_parser_enabled = false;
3030

3131
string use_modules= "(use-modules (code " * name * "-lang))";
3232
eval (use_modules);
@@ -249,8 +249,8 @@ prog_language_rep::customize_path (tree config) {
249249
static bool
250250
is_path_token_delim (char c) {
251251
return is_space (c) || c == '(' || c == ')' || c == '{' || c == '}' ||
252-
c == '[' || c == ']' || c == ';' || c == '|' || c == '&' ||
253-
c == '<' || c == '>';
252+
c == '[' || c == ']' || c == ';' || c == '|' || c == '&' || c == '<' ||
253+
c == '>';
254254
}
255255

256256
static bool
@@ -264,13 +264,17 @@ looks_like_path_token (string token) {
264264

265265
bool has_dot = false;
266266
bool has_alpha= false;
267+
bool has_digit= false;
267268
bool has_at = false;
268269
bool has_colon= false;
270+
bool has_dash = false;
269271
for (int i= 0; i < N (token); i++) {
270272
char c= token[i];
271273
if (c == '/' || c == '\\') return true;
272274
if (c == '.') has_dot= true;
273275
if (is_alpha (c)) has_alpha= true;
276+
if (is_digit (c)) has_digit= true;
277+
if (c == '-') has_dash= true;
274278
if (c == '@') has_at= true;
275279
if (c == ':') has_colon= true;
276280
if (c == ':' && i + 2 < N (token) && token[i + 1] == '/' &&
@@ -279,12 +283,12 @@ looks_like_path_token (string token) {
279283
}
280284

281285
if (N (token) >= 2 && token[0] == '.' && token[1] == '/') return true;
282-
if (N (token) >= 3 && token[0] == '.' && token[1] == '.' &&
283-
token[2] == '/')
286+
if (N (token) >= 3 && token[0] == '.' && token[1] == '.' && token[2] == '/')
284287
return true;
285288
if (N (token) >= 2 && token[0] == '~' && token[1] == '/') return true;
286289
if (has_at && has_colon) return true;
287290
if (has_dot && has_alpha) return true;
291+
if (token[0] != '-' && has_dash && has_alpha && has_digit) return true;
288292
return false;
289293
}
290294

@@ -295,7 +299,8 @@ parse_path_token (string s, int& pos) {
295299

296300
int start= pos;
297301
int end = pos;
298-
while (end < N (s) && !is_path_token_delim (s[end])) end++;
302+
while (end < N (s) && !is_path_token_delim (s[end]))
303+
end++;
299304
string token= s (start, end);
300305
if (!looks_like_path_token (token)) return false;
301306
pos= end;
@@ -392,8 +397,7 @@ prog_language_rep::get_color (tree t, int start, int end) {
392397
int pos= 0;
393398
while (pos <= start) {
394399
if (inline_comment_parser.can_parse (s, pos)) {
395-
if (!inline_comment_requires_space ||
396-
(pos == 0 || is_space (s[pos - 1])))
400+
if (!inline_comment_requires_space || (pos == 0 || is_space (s[pos - 1])))
397401
return decode_color (lan_name, encode_color ("comment"));
398402
}
399403
pos++;

0 commit comments

Comments
 (0)