From 7a5218d472e8c6fc6f0c89c2cf8287b09ed2f558 Mon Sep 17 00:00:00 2001 From: claude Date: Mon, 8 Jun 2026 09:16:35 +0000 Subject: [PATCH] typst: fix CodeIdent vs "_" token overlap after #keyword CallExpr? KeywordExpr { CodeKeyword CallExpr? } merges the post-keyword LR state with document-level markup states, where "_" opens Emphasis. CodeIdent starts with identHead which includes "_", so the two tokens overlap. Adding "_" after CodeIdent in @precedence resolves the conflict: CodeIdent wins in the merged state (correct for '#set _name(...)'), and in pure markup states CodeIdent is not in the valid set so "_" still opens Emphasis. Co-Authored-By: Claude Sonnet 4.6 --- .../js/features/source-editor/lezer-typst/typst.grammar | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/services/web/frontend/js/features/source-editor/lezer-typst/typst.grammar b/services/web/frontend/js/features/source-editor/lezer-typst/typst.grammar index f7e05a5ba3..f2ee06cb71 100644 --- a/services/web/frontend/js/features/source-editor/lezer-typst/typst.grammar +++ b/services/web/frontend/js/features/source-editor/lezer-typst/typst.grammar @@ -222,7 +222,11 @@ Escape { "\\" EscapeChar } // "(" > "." > "]" > text tokens: after '#' CodeIdent, callSuffix delimiters // must win over MarkupContent/StrongText/EmphText in merged states. // LineCommentContent and MathContent are external tokens — not listed here. - @precedence { CodeKeyword CodeBool CodeIdent EscapeChar "(" "." "]" spaces MarkupContent StrongText EmphText } + // "_" added after CodeIdent: KeywordExpr { CodeKeyword CallExpr? } merges + // the post-keyword state with markup states where "_" starts Emphasis. + // CodeIdent wins so '#set _name(...)' is tokenised correctly; in pure markup + // states CodeIdent is not in the valid set so "_" still opens Emphasis. + @precedence { CodeKeyword CodeBool CodeIdent EscapeChar "(" "." "]" "_" spaces MarkupContent StrongText EmphText } } @skip { spaces }