fix(lex): treat leading backtick decl lines as narrative
Only `` `name` = … `` binds stay Code; lines like `` `捕获=True` 时… `` are Comment Decl prose so they no longer raise unrecognized statement. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
4f09e515ee
commit
8846f5f070
4 files changed
+51
-2
No files matched your search
+1
-1
@@ -53,7 +53,7 @@ description: 中文系统包装(加载环境 可选 路径=)
|
||||
|
||||
运行子进程。默认返回退出码(整数)。
|
||||
|
||||
当捕获为真(`捕获=True`)时返回映射 `{code, stdout, stderr}`(过大输出可能截断)。
|
||||
`捕获=True` 时返回映射 `{code, stdout, stderr}`(过大输出可能截断)。
|
||||
|
||||
在 `**…**` 内优先写裸变量 `参数=参数`;`` 参数=`参数` `` 亦可。
|
||||
|
||||
|
||||
+33
-1
@@ -39,10 +39,29 @@ pub struct ClassifiedLine {
|
||||
fn is_code_starter(c: char) -> bool {
|
||||
matches!(
|
||||
c,
|
||||
'#' | '*' | '>' | '+' | '-' | '`' | '|' | '~' | '$'
|
||||
'#' | '*' | '>' | '+' | '-' | '|' | '~' | '$'
|
||||
) || c.is_ascii_digit()
|
||||
}
|
||||
|
||||
/// Whole-line backtick bind `` `name` = … `` (empty RHS / fence / table OK).
|
||||
/// Narrative decls like `` `捕获=True` 时… `` or `` `n`,我们… `` are **not** binds.
|
||||
fn looks_like_backtick_assign(trimmed: &str) -> bool {
|
||||
let t = trimmed.trim();
|
||||
if !t.starts_with('`') {
|
||||
return false;
|
||||
}
|
||||
let rest = &t[1..];
|
||||
let Some(end) = rest.find('`') else {
|
||||
return false;
|
||||
};
|
||||
let name = &rest[..end];
|
||||
if name.is_empty() || name.chars().any(|c| c.is_whitespace()) {
|
||||
return false;
|
||||
}
|
||||
let after = rest[end + 1..].trim_start();
|
||||
after.starts_with('=')
|
||||
}
|
||||
|
||||
/// `*` / `**` lines that are Marqdo executable (statement / return / else), not narrative Markdown.
|
||||
///
|
||||
/// Closing `*` / `**` must not be taken from inside `` `…` `` or `"…"` (GAP-06/07 nested markers).
|
||||
@@ -213,6 +232,8 @@ pub fn classify_line(text: &str) -> LineKind {
|
||||
match first {
|
||||
None => LineKind::Blank,
|
||||
Some('*') if !is_marqdo_star_line(trimmed) => LineKind::Comment,
|
||||
Some('`') if looks_like_backtick_assign(trimmed) => LineKind::Code,
|
||||
Some('`') => LineKind::Comment,
|
||||
Some(c) if is_code_starter(c) => LineKind::Code,
|
||||
Some(_) => LineKind::Comment,
|
||||
}
|
||||
@@ -369,6 +390,17 @@ mod tests {
|
||||
assert_eq!(classify_line("1. arm"), LineKind::Code);
|
||||
assert_eq!(classify_line("| a |"), LineKind::Code);
|
||||
assert_eq!(classify_line("`x` = 1"), LineKind::Code);
|
||||
assert_eq!(
|
||||
classify_line("`捕获=True` 时返回映射。"),
|
||||
LineKind::Comment,
|
||||
"prose decl / narrative, not backtick assign"
|
||||
);
|
||||
assert_eq!(
|
||||
classify_line("`n`,我们执行操作"),
|
||||
LineKind::Comment,
|
||||
"leading decl in narrative"
|
||||
);
|
||||
assert_eq!(classify_line("`礼貌`=False"), LineKind::Code);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -3872,3 +3872,8 @@ fn markup_v03_float_discount() {
|
||||
fn markup_v03_dynamic_footnote() {
|
||||
assert_out_v03("tests/markup-v03/dynamic-footnote.mq.md", "28");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn markup_v03_leading_backtick_decl() {
|
||||
assert_out_v03("tests/markup-v03/leading-backtick-decl.mq.md", "ok");
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
---
|
||||
title: leading backtick decl is narrative
|
||||
description: `` `名`… `` / `` `捕获=True` 时… `` are Decl prose, not statements
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
`捕获=True` 时返回映射 `{code, stdout, stderr}`。
|
||||
|
||||
向`谁`问好。
|
||||
|
||||
> print text=ok
|
||||
Reference in new issue
Block a user