Skip to content
Draft
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
37 changes: 36 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ module.exports = grammar({
fragment: ($) => repeat($._node),

_node: ($) =>
choice($.doctype, $.tag, $.component, $.text, $.comment, $.directive),
choice(
$.doctype,
$.tag,
$.component,
$.script,
$.text,
$.comment,
$.directive
),

doctype: ($) => seq("<!", "DOCTYPE", "html", ">"),

Expand All @@ -22,6 +30,30 @@ module.exports = grammar({
$.self_closing_component
),

script: ($) =>
choice(
seq($.start_script, $.raw_text, $.end_script),
$.self_closing_script
),

start_script: ($) =>
seq(
"<",
"script",
repeat(choice($.attribute, $.expression, $.special_attribute)),
">"
),

end_script: ($) => seq("</", "script", ">"),

self_closing_script: ($) =>
seq(
"<",
"script",
repeat(choice($.attribute, $.expression, $.special_attribute)),
"/>"
),

slot: ($) =>
choice(
seq($.start_slot, repeat($._node), $.end_slot),
Expand Down Expand Up @@ -164,6 +196,9 @@ module.exports = grammar({

attribute_name: ($) => token(prec(-1, /[^:<>{}"'/=\s][^<>{}"'/=\s]*/)),

// TODO: figure out why {} are treated as (ERROR (text)), see current failing test
raw_text: ($) => /[^\s](.*[^\s])?/,

text: ($) => /[^<>{}\s]([^<>{}]*[^<>{}\s])?/,
},
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"devDependencies": {
"nan": "^2.16.0",
"prettier": "^2.7.1",
"tree-sitter-cli": "^0.20.7"
"tree-sitter-cli": "^0.20.8"
},
"tree-sitter": [
{
Expand Down
125 changes: 125 additions & 0 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 102 additions & 0 deletions src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading