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 <noreply@anthropic.com>
This commit is contained in:
parent
769d8bfc51
commit
dc9cb74320
22
grammar.js
22
grammar.js
|
|
@ -567,21 +567,33 @@ module.exports = grammar({
|
||||||
// Comments
|
// Comments
|
||||||
comment: ($) => choice($.template_comment, $.html_comment),
|
comment: ($) => choice($.template_comment, $.html_comment),
|
||||||
|
|
||||||
// Template comments: @* ... *@ (simple form only for syntax highlighting)
|
// Template comments: @* ... *@
|
||||||
template_comment: ($) =>
|
template_comment: ($) =>
|
||||||
seq("@", /\*+/, optional(/([^*]|\*+[^@])*/), /\*+/, "@"),
|
seq(
|
||||||
|
alias("@*", $.comment_start),
|
||||||
|
optional($.comment_content),
|
||||||
|
alias("*@", $.comment_end)
|
||||||
|
),
|
||||||
|
comment_content: ($) => /([^*]|\*[^@])*/,
|
||||||
|
|
||||||
// HTML comment: <!-- ... -->
|
// HTML comment: <!-- ... -->
|
||||||
html_comment: ($) => seq("<!--", optional($.html_comment_content), "-->"),
|
html_comment: ($) => seq("<!--", optional($.html_comment_content), "-->"),
|
||||||
|
|
||||||
html_comment_content: ($) => /([^-]|-[^-]|--[^>])*/,
|
html_comment_content: ($) => /([^-]|-[^-]|--[^>])*/,
|
||||||
|
|
||||||
// Raw blocks: @#...#@ (simple form only for syntax highlighting)
|
// Raw blocks: @# ... #@
|
||||||
raw_block: ($) =>
|
raw_block: ($) =>
|
||||||
seq("@", /#+/, optional(/([^#]|#+[^@])*/), /#+/, "@"),
|
seq(
|
||||||
|
alias("@#", $.raw_start),
|
||||||
|
optional($.raw_content),
|
||||||
|
alias("#@", $.raw_end)
|
||||||
|
),
|
||||||
|
raw_content: ($) => /([^#]|#[^@])*/,
|
||||||
|
|
||||||
// Embedded language blocks: @```lang ... ```@
|
// Embedded language blocks: @```lang ... ```@
|
||||||
embedded_language: ($) =>
|
embedded_language: ($) =>
|
||||||
seq("@", /`+/, $.language_name, optional(/([^`]|`+[^@])*/), /`+/, "@"),
|
seq("@```", $.language_name, optional($.embedded_content), "```@"),
|
||||||
|
embedded_content: ($) => /([^`]|`[^`]|``[^`]|```[^@])*/,
|
||||||
|
|
||||||
language_name: ($) =>
|
language_name: ($) =>
|
||||||
choice("html", "css", "js", "javascript", "json", "alpine", "style"),
|
choice("html", "css", "js", "javascript", "json", "alpine", "style"),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue