This repository was archived by the owner on Jan 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathgrammar.js
More file actions
54 lines (54 loc) · 1.34 KB
/
grammar.js
File metadata and controls
54 lines (54 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module.exports = grammar({
name: 'pug',
externals: $ => [
$._newline,
$._indent,
$._dedent
],
rules: {
source_file: $ => repeat(choice($.comment, $.tag)),
tag: $ => seq(
choice($.tag_name, $.id, $.class),
optional(repeat(choice($.id, $.class))),
optional($.attributes),
optional(seq(' ', $.content)),
$._newline,
optional($.children),
),
attributes: $ => seq(
'(',
repeat(seq(
$.attribute,
choice(',', ' ')
)),
optional($.attribute),
')',
),
attribute: $ => seq(
$.attribute_name,
optional(seq(
'=',
$.quoted_attribute_value
))
),
children: $ => choice(
seq($._indent, repeat($.tag), $._dedent),
),
comment: $ => seq(
'//',
optional($._comment_content),
$._newline,
optional(seq($._indent, repeat(seq($._comment_content, $._newline)), $._dedent))
),
tag_name: $ => /\w(?:[-:\w]*\w)?/,
class: $ => /\.[_a-z0-9\-]*[_a-z][_a-z0-9\-]*/i,
id: $ => /#[\w-]+/,
attribute_name: $ => /[\w@\-:]+/,
quoted_attribute_value: $ => choice(
seq("'", optional(alias(/[^']+/, $.attribute_value)), "'"),
seq('"', optional(alias(/[^"]+/, $.attribute_value)), '"')
),
content: $ => /[^\n]+/,
_comment_content: $ => /[^ ][^\n]*/
}
})