Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ indent_size = 4
indent_style = tab
indent_size = 8

[*.txt]
indent_style = space
indent_size = 2

[Makefile]
indent_style = tab
indent_size = 8
100 changes: 64 additions & 36 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ module.exports = grammar(HTML, {

conflicts: ($) => [
[$.arrow_function_parameters, $._primitive],
[$._any_expression, $.arguments],
[$.expression, $.arguments],
[$.microsyntax_property_binding, $._primitive],

],

externals: ($, original) =>
Expand All @@ -42,7 +46,13 @@ module.exports = grammar(HTML, {

// ---------- Overrides ----------
attribute_name: (_) => /[^<>\*.\[\]\(\)"'=\s]+/,
text: (_) => /[^<>@{}&\s]([^<>@{}&]*[^<>@{}&\s])?/,
text: (_) => choice(
// 1. The original greedy block (matches standard text until it hits a boundary)
/[^<>@{}&\s]([^<>@{}&]*[^<>@{}&\s])?/,

// 2. The Fallback (Catches naked ampersands that fail the entity rule)
/&/
),

// ----------- Statement block --------
statement_block: ($) => prec.right(seq('{', repeat($._node), '}')),
Expand Down Expand Up @@ -396,56 +406,74 @@ module.exports = grammar(HTML, {
optional(
seq(
'=',
choice($._double_quote, $._single_quote),
choice($.structural_expression, $.structural_declaration),
choice($._double_quote, $._single_quote),
choice(
seq($._double_quote, $.microsyntax, $._double_quote),
seq($._single_quote, $.microsyntax, $._single_quote),
),
),
),
),

structural_expression: ($) =>
seq(
$._any_expression,
optional($._alias),
optional($._else_template_expression),
optional($._context_expression),
microsyntax: ($) =>
prec.left(
seq(
choice($.microsyntax_anonymous_binding, $.microsyntax_binding),
repeat(seq(optional(choice(';', ',')), $.microsyntax_binding)),
optional(choice(';', ',')),
),
),

structural_declaration: ($) =>
seq(
alias('let', $.special_keyword),
microsyntax_anonymous_binding: ($) =>
choice(
prec(3, seq(
field('value', $.identifier),
optional($._alias)
)),
prec(2, seq(
field('value', $._any_expression),
optional($._alias)
)),
),

microsyntax_binding: ($) =>
choice(
// evaluate explicit rules first
prec(2, $.microsyntax_variable_declaration),
prec(2, $.microsyntax_keyword_binding),
prec(1, $.microsyntax_property_binding),
),

microsyntax_property_binding: ($) =>
choice(
seq(
field('name', $.identifier),
optional(':'),
field('value', $._any_expression),
optional($._alias)
),
),

microsyntax_keyword_binding: ($) =>
seq(
$.structural_assignment,
repeat(seq(choice(';', ','), $.structural_assignment)),
field('name', choice(
alias('else', $.special_keyword),
alias('then', $.special_keyword),
alias('of', $.special_keyword),
)),
optional(':'),
field('value', $._any_expression),
optional($._alias)
),
),

structural_assignment: ($) =>
choice(
seq(field('name', $.identifier), ':', field('value', $.identifier)),
prec.left(
PREC.ALIAS,
microsyntax_variable_declaration: ($) =>
seq(
optional(alias('let', $.special_keyword)),
alias('let', $.special_keyword),
field('name', $.identifier),
field('operator', choice($.identifier, '=')),
field('value', $.expression),
optional(seq(field('operator', '='), field('value', $.expression))),
optional($._alias),
),
),
seq(field('name', $.identifier), optional($._alias)),
),

_alias: ($) => seq(alias('as', $.special_keyword), field('alias', $.identifier)),
_else_template_expression: ($) =>
seq(';', alias('else', $.special_keyword), $.identifier),
_context_expression: ($) =>
seq(
';',
choice(alias('context', $.special_keyword), field('named', $.identifier)),
':',
$._any_expression,
),

// ---------- Bindings ----------
property_binding: ($) =>
Expand Down
3 changes: 0 additions & 3 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
"\"\""
] @punctuation.delimiter)

(structural_assignment
operator: (identifier) @keyword)

(member_expression
property: (identifier) @property)

Expand Down
Loading