Release v0.0.3: function end, paragraph comments, logo, and welcome polish.

End nested functions with ---/***/empty return; blank-line comment paragraphs in lex and view; brand favicon/logo; bump crate to 0.0.3.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-04 16:03:10 +08:00
1 parent 69fecaeaab
commit 7848180454
16 files changed
+380 -101

No files matched your search

+70 -11
View File
@@ -1,7 +1,8 @@
//! Line classification (M1) — no Flex.
//!
//! Unmarked lines are comments; lines whose first non-whitespace character
//! opens a Marqdo/Markdown marker are code.
//! Narrative comments are paragraph-scoped: blank lines separate paragraphs.
//! After a comment line, subsequent non-blank lines stay comments until a blank
//! (so mid-paragraph lines starting with `` ` `` are not treated as code).
use std::fmt;
@@ -40,6 +41,9 @@ fn is_code_starter(c: char) -> bool {
}
/// Classify a single logical line (no trailing newline required).
///
/// This is the **paragraph-start** rule only. Prefer [`classify_source`] for
/// full-file classification (paragraph continuation).
pub fn classify_line(text: &str) -> LineKind {
let trimmed = text.trim_end_matches(['\r', '\n']);
if trimmed.chars().all(|c| c.is_whitespace()) {
@@ -53,7 +57,11 @@ pub fn classify_line(text: &str) -> LineKind {
}
}
/// Classify every line of a source file.
/// Classify every line of a source file (blank-line paragraph comments).
///
/// Structural end markers (`---` / `***` / empty `****`) always stay Code and
/// break a comment paragraph, so frontmatter closers and function ends work
/// even when adjacent to narrative.
pub fn classify_source(source: &str) -> Vec<ClassifiedLine> {
let source = source.strip_prefix('\u{feff}').unwrap_or(source);
let lines: Vec<&str> = if source.is_empty() {
@@ -62,15 +70,46 @@ pub fn classify_source(source: &str) -> Vec<ClassifiedLine> {
source.lines().collect()
};
lines
.into_iter()
.enumerate()
.map(|(i, text)| ClassifiedLine {
let mut out = Vec::with_capacity(lines.len());
let mut in_comment_paragraph = false;
for (i, text) in lines.into_iter().enumerate() {
let base = classify_line(text);
let trimmed = text.trim();
let structural = is_structural_code_line(trimmed);
let kind = match base {
LineKind::Blank => {
in_comment_paragraph = false;
LineKind::Blank
}
LineKind::Comment => {
in_comment_paragraph = true;
LineKind::Comment
}
LineKind::Code if structural => {
in_comment_paragraph = false;
LineKind::Code
}
LineKind::Code if in_comment_paragraph => LineKind::Comment,
LineKind::Code => LineKind::Code,
};
out.push(ClassifiedLine {
line_no: (i + 1) as u32,
kind: classify_line(text),
kind,
text: text.to_string(),
})
.collect()
});
}
out
}
/// Function-end / frontmatter HR or empty bold return — never swallowed by paragraphs.
fn is_structural_code_line(trimmed: &str) -> bool {
if trimmed.len() >= 3
&& (trimmed.chars().all(|c| c == '-') || trimmed.chars().all(|c| c == '*'))
{
return true;
}
false
}
/// Human-readable dump for `--dump-lines`.
@@ -120,11 +159,31 @@ mod tests {
assert_eq!(classify_line("`x` = 1"), LineKind::Code);
}
#[test]
fn paragraph_comment_keeps_backtick_continuation() {
let src = "采用了\n`.mq.md`的双层后缀\n\n> print text=ok\n";
let lines = classify_source(src);
assert_eq!(lines[0].kind, LineKind::Comment);
assert_eq!(lines[1].kind, LineKind::Comment);
assert_eq!(lines[2].kind, LineKind::Blank);
assert_eq!(lines[3].kind, LineKind::Code);
}
#[test]
fn frontmatter_closing_hr_stays_code() {
let src = "---\ntitle: x\n---\n\n# main\n";
let lines = classify_source(src);
assert_eq!(lines[0].kind, LineKind::Code);
assert_eq!(lines[1].kind, LineKind::Comment);
assert_eq!(lines[2].kind, LineKind::Code);
assert_eq!(lines[2].text.trim(), "---");
}
#[test]
fn classify_hello_fixture() {
let src = include_str!("../../tests/structure/hello.mq.md");
let lines = classify_source(src);
assert!(lines.iter().any(|l| l.kind == LineKind::Code && l.text.contains("print")));
assert!(lines.iter().any(|l| l.kind == LineKind::Comment));
assert!(lines.iter().any(|l| l.kind == LineKind::Code));
}
}
+35 -4
View File
@@ -144,14 +144,29 @@ impl<'a> Cursor<'a> {
break;
}
// Body until next heading at level <= ours.
// Body until next heading at level <= ours, or explicit end (--- / *** / empty **).
while self.skip_noise() {
let Some(l) = self.peek() else { break };
let trimmed = l.text.trim();
// Empty bold return ends the function body.
if is_empty_bold_return(trimmed) {
let span = Span {
line: l.line_no,
col: 1,
};
self.bump();
fun.body.push(Stmt::Return {
value: Expr::Literal(Literal::None),
span,
});
break;
}
// --- / *** at function body top level ends the function (no return).
if is_frame(trimmed) {
self.bump();
continue;
break;
}
if is_heading(trimmed) {
@@ -191,10 +206,14 @@ impl<'a> Cursor<'a> {
bail!("{span}: unexpected frame line as statement");
}
// Bold return **…**
// Bold return **…** (empty inner → None)
if trimmed.starts_with("**") && trimmed.ends_with("**") && trimmed.len() >= 4 {
let inner = &trimmed[2..trimmed.len() - 2];
let value = parse_expr_str(inner)?;
let value = if inner.trim().is_empty() {
Expr::Literal(Literal::None)
} else {
parse_expr_str(inner)?
};
return Ok(Stmt::Return { value, span });
}
@@ -481,9 +500,21 @@ fn is_frame(trimmed: &str) -> bool {
if trimmed.len() < 3 {
return false;
}
// Empty bold return `****` is handled separately; frames are --- or *** (etc.).
if is_empty_bold_return(trimmed) {
return false;
}
trimmed.chars().all(|c| c == '-') || trimmed.chars().all(|c| c == '*')
}
/// `****` or `**` + whitespace only + `**`.
fn is_empty_bold_return(trimmed: &str) -> bool {
if !(trimmed.starts_with("**") && trimmed.ends_with("**") && trimmed.len() >= 4) {
return false;
}
trimmed[2..trimmed.len() - 2].trim().is_empty()
}
fn is_ordered_branch(trimmed: &str) -> bool {
strip_ordered(trimmed).is_some()
}
+42 -6
View File
@@ -78,6 +78,21 @@ a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
z-index: 20;
}
.topbar .brand { margin: 0; font-size: 1.05rem; font-weight: 600; letter-spacing: -0.022em; }
.brand-row {
display: flex;
align-items: center;
gap: 0.55rem;
}
.brand-row .brand { margin: 0; }
.logo {
width: 1.75rem;
height: 1.75rem;
object-fit: contain;
flex-shrink: 0;
border-radius: 6px;
}
.topbar .logo { width: 1.45rem; height: 1.45rem; }
.nav-brand .logo { width: 2rem; height: 2rem; }
.nav-btn {
appearance: none;
border: 1px solid var(--line);
@@ -112,7 +127,8 @@ a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
align-self: start;
height: 100vh;
}
.nav-brand { display: block; padding: 0 0.35rem; }
.nav-brand { display: block; padding: 0 0.35rem; margin-bottom: 1.15rem; }
.nav-brand .tagline { margin: 0.1rem 0 0; }
.brand {
font-size: 1.35rem;
font-weight: 700;
@@ -122,9 +138,10 @@ a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.tagline {
color: var(--muted);
font-size: 0.78rem;
margin: 0 0 1.5rem;
margin: 0;
font-weight: 500;
}
.nav > h2:first-of-type { margin-top: 0.35rem; }
.nav h2 {
font-size: 0.68rem;
text-transform: uppercase;
@@ -286,7 +303,15 @@ section.block > h2 {
color: var(--ink);
font-weight: 500;
}
.comment-text { color: var(--muted); font-size: 0.92rem; }
.comment-text {
color: var(--muted);
font-size: 0.92rem;
display: block;
margin-top: 0.35rem;
white-space: pre-line;
line-height: 1.55;
max-width: 42em;
}
code.expr {
font-family: var(--mono);
font-size: 0.84rem;
@@ -352,6 +377,9 @@ pub fn layout(title: &str, nav: &str, main: &str) -> String {
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>{title} · marqdo</title>
<link rel="icon" href="https://s3.cflmy.cn/logo/Logo.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="https://s3.cflmy.cn/logo/Logo.ico" type="image/x-icon"/>
<link rel="apple-touch-icon" href="https://s3.cflmy.cn/logo/Logo.png"/>
<style>{css}</style>
</head>
<body>
@@ -359,13 +387,21 @@ pub fn layout(title: &str, nav: &str, main: &str) -> String {
<label class="backdrop" for="nav-toggle" aria-hidden="true"></label>
<header class="topbar">
<label class="nav-btn" for="nav-toggle" aria-label="Menu">☰</label>
<p class="brand">marqdo</p>
<div class="brand-row">
<img class="logo" src="https://s3.cflmy.cn/logo/Logo.png" width="28" height="28" alt="marqdo"/>
<p class="brand">marqdo</p>
</div>
</header>
<div class="shell">
<aside class="nav">
<div class="nav-brand">
<p class="brand">marqdo</p>
<p class="tagline">view</p>
<div class="brand-row">
<img class="logo" src="https://s3.cflmy.cn/logo/Logo.png" width="32" height="32" alt="marqdo"/>
<div>
<p class="brand">marqdo</p>
<p class="tagline">view</p>
</div>
</div>
</div>
{nav}
</aside>
+34 -8
View File
@@ -77,6 +77,20 @@ fn skip_frontmatter_end(lines: &[ClassifiedLine]) -> Option<u32> {
fn emit_comments(lines: &[ClassifiedLine], from_line: u32, before_line: u32) -> String {
let mut s = String::new();
let mut paragraph: Vec<String> = Vec::new();
let flush = |paragraph: &mut Vec<String>, s: &mut String| {
if paragraph.is_empty() {
return;
}
let text = paragraph.join("\n");
paragraph.clear();
s.push_str(&format!(
"<div class=\"card comment-card\"><span class=\"badge\">comment</span><span class=\"comment-text\">{}</span></div>",
escape(&text)
));
};
for l in lines {
if l.line_no < from_line {
continue;
@@ -84,17 +98,18 @@ fn emit_comments(lines: &[ClassifiedLine], from_line: u32, before_line: u32) ->
if l.line_no >= before_line {
break;
}
if l.kind == LineKind::Comment {
let text = l.text.trim();
if text.is_empty() {
continue;
match l.kind {
LineKind::Comment => {
let text = l.text.trim();
if !text.is_empty() {
paragraph.push(text.to_string());
}
}
s.push_str(&format!(
"<div class=\"card comment-card\"><span class=\"badge\">comment</span><span class=\"comment-text\">{}</span></div>",
escape(text)
));
LineKind::Blank => flush(&mut paragraph, &mut s),
LineKind::Code => flush(&mut paragraph, &mut s),
}
}
flush(&mut paragraph, &mut s);
s
}
@@ -421,4 +436,15 @@ mod tests {
assert!(!html.contains("Binary {"));
assert!(!html.contains("Literal(Int"));
}
#[test]
fn comments_render_as_paragraphs() {
let src = "段首说明\n续行仍属同段\n\n下一段\n\n# main\n\n> print text=x\n";
let module = crate::parse::parse_source(src).unwrap();
let html = render_module_structure(&module, src);
let cards = html.matches("comment-card").count();
assert_eq!(cards, 2, "blank line should split comment paragraphs: {html}");
assert!(html.contains("段首说明\n续行仍属同段"));
assert!(html.contains("下一段"));
}
}