1
+ const html = require ( "tree-sitter-html/grammar" ) ;
2
+
3
+ module . exports = grammar ( html , {
4
+ name : "htmlsmarty" ,
5
+
6
+ extras : $ => [
7
+ $ . comment ,
8
+ // TODO: technically this would be possible too, and a whole lot easier (only needs adjusting text, nothing else)
9
+ // but i dont know if this would then properly work with indentation for eg. smarty_if
10
+ //$.smarty_comment,
11
+ / \s + / ,
12
+ ] ,
13
+
14
+ rules : {
15
+ smarty_comment : ( $ ) => seq (
16
+ "{*" ,
17
+ / [ ^ * ] * \* + ( [ ^ } * ] [ ^ * ] * \* + ) * / ,
18
+ "}"
19
+ ) ,
20
+
21
+ // in text
22
+ // FIXME: see comment in test/corpus/unpaired.txt for why this is broken in the edge case of
23
+ // `text {<valid-tag/>`
24
+ text : $ => / ( [ ^ < > { ] | \{ [ ^ * < > ] ) + / ,
25
+
26
+ _node : $ => choice (
27
+ $ . doctype ,
28
+ $ . text ,
29
+ $ . smarty_comment ,
30
+ $ . element ,
31
+ $ . script_element ,
32
+ $ . style_element ,
33
+ $ . erroneous_end_tag
34
+ ) ,
35
+
36
+ // in attribute lists
37
+ _attribute : $ => choice (
38
+ $ . attribute ,
39
+ $ . smarty_comment ,
40
+ ) ,
41
+
42
+ attribute_name : $ => / ( [ ^ < > " ' / = \s { ] | \{ [ ^ * < > " ' / = \s { ] ) + / ,
43
+
44
+ sq_attribute_value_fragment : $ => repeat1 ( choice (
45
+ / ( [ ^ ' { ] | \{ [ ^ * ' ] ) + / ,
46
+ $ . smarty_comment
47
+ ) ) ,
48
+ dq_attribute_value_fragment : $ => repeat1 ( choice (
49
+ / ( [ ^ " { ] | \{ [ ^ * " ] ) + / ,
50
+ $ . smarty_comment
51
+ ) ) ,
52
+
53
+ quoted_attribute_value : $ => choice (
54
+ seq ( "'" , optional ( alias ( $ . sq_attribute_value_fragment , $ . attribute_value ) ) , optional ( "{" ) , "'" ) ,
55
+ seq ( '"' , optional ( alias ( $ . dq_attribute_value_fragment , $ . attribute_value ) ) , optional ( "{" ) , '"' ) ,
56
+ ) ,
57
+
58
+
59
+ start_tag : $ => seq (
60
+ '<' ,
61
+ alias ( $ . _start_tag_name , $ . tag_name ) ,
62
+ repeat ( $ . _attribute ) ,
63
+ '>'
64
+ ) ,
65
+
66
+ script_start_tag : $ => seq (
67
+ '<' ,
68
+ alias ( $ . _script_start_tag_name , $ . tag_name ) ,
69
+ repeat ( $ . _attribute ) ,
70
+ '>'
71
+ ) ,
72
+
73
+ style_start_tag : $ => seq (
74
+ '<' ,
75
+ alias ( $ . _style_start_tag_name , $ . tag_name ) ,
76
+ repeat ( $ . _attribute ) ,
77
+ '>'
78
+ ) ,
79
+
80
+ self_closing_tag : $ => seq (
81
+ '<' ,
82
+ alias ( $ . _start_tag_name , $ . tag_name ) ,
83
+ repeat ( $ . _attribute ) ,
84
+ '/>'
85
+ ) ,
86
+ }
87
+ } ) ;
0 commit comments