From dc9cb74320853d281314038c972c78f178d42388 Mon Sep 17 00:00:00 2001 From: Michael Netshipise Date: Mon, 19 Jan 2026 20:42:49 +0200 Subject: [PATCH] Fix grammar to produce queryable nodes Use seq() with named rules instead of inline regex patterns to ensure raw_block, template_comment, etc. produce proper named nodes that can be queried in highlights.scm Co-Authored-By: Claude Opus 4.5 --- grammar.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/grammar.js b/grammar.js index 06900c3..77e6d16 100644 --- a/grammar.js +++ b/grammar.js @@ -567,21 +567,33 @@ module.exports = grammar({ // Comments comment: ($) => choice($.template_comment, $.html_comment), - // Template comments: @* ... *@ (simple form only for syntax highlighting) + // Template comments: @* ... *@ template_comment: ($) => - seq("@", /\*+/, optional(/([^*]|\*+[^@])*/), /\*+/, "@"), + seq( + alias("@*", $.comment_start), + optional($.comment_content), + alias("*@", $.comment_end) + ), + comment_content: ($) => /([^*]|\*[^@])*/, + // HTML comment: html_comment: ($) => seq(""), html_comment_content: ($) => /([^-]|-[^-]|--[^>])*/, - // Raw blocks: @#...#@ (simple form only for syntax highlighting) + // Raw blocks: @# ... #@ raw_block: ($) => - seq("@", /#+/, optional(/([^#]|#+[^@])*/), /#+/, "@"), + seq( + alias("@#", $.raw_start), + optional($.raw_content), + alias("#@", $.raw_end) + ), + raw_content: ($) => /([^#]|#[^@])*/, // Embedded language blocks: @```lang ... ```@ embedded_language: ($) => - seq("@", /`+/, $.language_name, optional(/([^`]|`+[^@])*/), /`+/, "@"), + seq("@```", $.language_name, optional($.embedded_content), "```@"), + embedded_content: ($) => /([^`]|`[^`]|``[^`]|```[^@])*/, language_name: ($) => choice("html", "css", "js", "javascript", "json", "alpine", "style"),