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
23 changes: 20 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
module.exports = grammar({
name: "pug",

externals: ($) => [$._newline, $._indent, $._dedent],
externals: ($) => [
$._newline,
$._indent,
$._dedent,
$._tag_name,
$._script_tag_name,
$._style_tag_name,
$.raw_text,
],

rules: {
source_file: ($) =>
Expand All @@ -25,12 +33,21 @@ module.exports = grammar({
script_tag: ($) =>
seq("script", optional($._attributes), optional(seq(".", $._newline))),

// No ERROR nodes, without external token raw_text
// style_tag: ($) => seq("style", optional($._attributes)),

// Produces many ERROR nodes
style_tag: ($) =>
seq("style", optional($._attributes), optional(seq(".", $._newline))),
seq(
"style",
optional($._attributes),
optional(seq(".", $._newline, $.raw_text))
),

path: ($) => seq(repeat1(choice(/\w/, "/")), ".", repeat1(/\w/)),

raw_text: ($) => choice(seq($._indent, /\w/, $._dedent)),
// Alternative to external token raw_text
// raw_text: ($) => choice(seq($._indent, /\w/, $._dedent)),

_attributes: ($) =>
seq("(", repeat(seq($.attribute, optional(choice(",", " ")))), ")"),
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"tree-sitter-cli": "^0.20.8"
},
"scripts": {
"example": "tree-sitter parse example-file.pug",
"generate": "tree-sitter generate",
"gt": "tree-sitter generate && tree-sitter test",
"parse": "tree-sitter parse",
Expand Down
42 changes: 20 additions & 22 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@
{
"type": "SYMBOL",
"name": "_newline"
},
{
"type": "SYMBOL",
"name": "raw_text"
}
]
},
Expand Down Expand Up @@ -204,28 +208,6 @@
}
]
},
"raw_text": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_indent"
},
{
"type": "PATTERN",
"value": "\\w"
},
{
"type": "SYMBOL",
"name": "_dedent"
}
]
}
]
},
"_attributes": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -416,6 +398,22 @@
{
"type": "SYMBOL",
"name": "_dedent"
},
{
"type": "SYMBOL",
"name": "_tag_name"
},
{
"type": "SYMBOL",
"name": "_script_tag_name"
},
{
"type": "SYMBOL",
"name": "_style_tag_name"
},
{
"type": "SYMBOL",
"name": "raw_text"
}
],
"inline": [],
Expand Down
8 changes: 8 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@
{
"type": "attribute",
"named": true
},
{
"type": "raw_text",
"named": true
}
]
}
Expand Down Expand Up @@ -213,6 +217,10 @@
"type": "link",
"named": false
},
{
"type": "raw_text",
"named": true
},
{
"type": "script",
"named": false
Expand Down
Loading