From 60508166c0e45fad6a9a72ee45350950e53db3c0 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 19 Feb 2026 10:23:42 -0800 Subject: [PATCH] Fix formatting of markdown grammar with cut This fixes a formatting issue with how the grammar is rendered in markdown when there is a cut operator. The Alt renderer was incorrectly missing a space on alternations that span multiple lines with a cut operator. This is because the Cut expression is essentially the same as a sequence, but the `last_expr` function was not treating it that way. The Cut was preventing it from seeing that the alternation had a Break at the end. --- tools/mdbook-spec/src/grammar/render_markdown.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/mdbook-spec/src/grammar/render_markdown.rs b/tools/mdbook-spec/src/grammar/render_markdown.rs index 316eb9aaf3..531ccd8052 100644 --- a/tools/mdbook-spec/src/grammar/render_markdown.rs +++ b/tools/mdbook-spec/src/grammar/render_markdown.rs @@ -65,6 +65,7 @@ fn render_production(prod: &Production, cx: &RenderCtx, output: &mut String) { fn last_expr(expr: &Expression) -> &ExpressionKind { match &expr.kind { ExpressionKind::Alt(es) | ExpressionKind::Sequence(es) => last_expr(es.last().unwrap()), + ExpressionKind::Cut(e) => last_expr(e), ExpressionKind::Grouped(_) | ExpressionKind::Optional(_) | ExpressionKind::NegativeLookahead(_) @@ -80,7 +81,6 @@ fn last_expr(expr: &Expression) -> &ExpressionKind { | ExpressionKind::Comment(_) | ExpressionKind::Charset(_) | ExpressionKind::NegExpression(_) - | ExpressionKind::Cut(_) | ExpressionKind::Unicode(_) => &expr.kind, } }