fix(parse): diagnose unclosed code-shaped bold
Treat `` **x = 1 `` as Code and error with a clear unclosed-`**` diagnostic instead of silently skipping it as a comment. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
95a49697f7
commit
6f303ff957
6 files changed
+86
-30
No files matched your search
@@ -363,6 +363,19 @@ impl<'a> Cursor<'a> {
|
||||
});
|
||||
}
|
||||
|
||||
// Unclosed code-shaped bold (classified Code so we can diagnose).
|
||||
if trimmed.starts_with("**")
|
||||
&& !(trimmed.ends_with("**") && trimmed.len() >= 4)
|
||||
&& crate::lex::looks_like_bold_code(&trimmed[2..])
|
||||
{
|
||||
return Err(Diagnostic::new(
|
||||
None,
|
||||
span,
|
||||
"unclosed bold code: expected closing `**`".to_string(),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
|
||||
// v0.3: **…** = code segment (assign / call / expr)
|
||||
if trimmed.starts_with("**") && trimmed.ends_with("**") && trimmed.len() >= 4 {
|
||||
let inner = &trimmed[2..trimmed.len() - 2];
|
||||
|
||||
+2
-29
@@ -5,6 +5,8 @@
|
||||
|
||||
use crate::lex::{matching_bold_close_inline, matching_italic_close_inline};
|
||||
|
||||
pub use crate::lex::looks_like_bold_code;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ProseBit {
|
||||
/// `` `ident` `` or `` `ident`=default `` (default string is raw RHS text).
|
||||
@@ -71,35 +73,6 @@ pub fn scan_prose_line(line: &str) -> Vec<ProseBit> {
|
||||
out
|
||||
}
|
||||
|
||||
/// Whether `**inner**` should execute (assign / call / expr), not soft emphasis.
|
||||
pub fn looks_like_bold_code(inner: &str) -> bool {
|
||||
let t = inner.trim();
|
||||
if t.is_empty() {
|
||||
return false;
|
||||
}
|
||||
if t.contains('=') || t.starts_with('>') {
|
||||
return true;
|
||||
}
|
||||
if t.chars().any(|c| matches!(c, '+' | '-' | '*' | '/' | '(' | ')' | '[' | ']')) {
|
||||
return true;
|
||||
}
|
||||
let parts: Vec<&str> = t.split_whitespace().collect();
|
||||
if parts.len() >= 2 {
|
||||
return parts[1..].iter().any(|p| {
|
||||
p.contains('=')
|
||||
|| p.starts_with('"')
|
||||
|| p.starts_with('\'')
|
||||
|| p.starts_with('`')
|
||||
|| p.chars().all(|c| c.is_ascii_digit())
|
||||
|| (p.contains('.')
|
||||
&& p.chars()
|
||||
.filter(|c| *c != '.')
|
||||
.all(|c| c.is_ascii_digit()))
|
||||
});
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// Whether `*inner*` is a return (vs mid-prose English/CJK emphasis).
|
||||
fn looks_like_italic_return(line: &str, at: usize, after: usize, inner: &str) -> bool {
|
||||
let t = inner.trim();
|
||||
|
||||
Reference in new issue
Block a user