-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.js
118 lines (107 loc) · 2.86 KB
/
grammar.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
* @file Mustache grammar for tree-sitter
* @author Luis Calle <[email protected]>
* @license MIT
*/
/// <reference types="tree-sitter-cli/dsl" />
// @ts-check
module.exports = grammar({
name: "mustache",
externals: ($) => [
$._start_tag_name,
$._end_tag_name,
$._erroneous_end_tag_name,
$.start_delimiter,
$.end_delimiter,
$._comment_content,
$._identifier_content,
$._set_start_delimiter_content,
$._set_end_delimiter_content,
$._old_end_delimiter,
$.text,
],
rules: {
template: ($) => repeat($._declaration),
_declaration: ($) => choice($.comment_statement, $._statement),
comment_statement: ($) =>
seq(
alias($.start_delimiter, $._start_delimiter),
"!",
$._comment_content,
alias($.end_delimiter, $._end_delimiter),
),
_statement: ($) =>
choice(
$.triple_statement,
$.ampersand_statement,
$.section,
$.inverted_section,
$.interpolation_statement,
$.set_delimiter_statement,
$.partial_statement,
$.text,
),
interpolation_statement: ($) =>
seq($.start_delimiter, $._expression, $.end_delimiter),
triple_statement: ($) =>
seq($.start_delimiter, "{", $._expression, "}", $.end_delimiter),
ampersand_statement: ($) =>
seq($.start_delimiter, "&", $._expression, $.end_delimiter),
set_delimiter_statement: ($) =>
seq(
$.start_delimiter,
"=",
$._set_start_delimiter_content,
/\s/,
$._set_end_delimiter_content,
"=",
alias($._old_end_delimiter, $.end_delimiter),
),
partial_statement: ($) =>
seq(
$.start_delimiter,
">",
alias($._comment_content, $.partial_content),
$.end_delimiter,
),
section: ($) =>
seq(
$.section_begin,
repeat($._statement),
alias($._section_end, $.section_end),
),
_section_end: ($) =>
seq(
$.start_delimiter,
"/",
choice(
alias($._end_tag_name, $.tag_name),
alias($._erroneous_end_tag_name, $.erroneous_tag_name),
),
$.end_delimiter,
),
section_begin: ($) =>
seq(
$.start_delimiter,
"#",
alias($._start_tag_name, $.tag_name),
$.end_delimiter,
),
inverted_section: ($) =>
seq(
$.inverted_section_begin,
repeat($._statement),
alias($._section_end, $.inverted_section_end),
),
inverted_section_begin: ($) =>
seq(
$.start_delimiter,
"^",
alias($._start_tag_name, $.tag_name),
$.end_delimiter,
),
_expression: ($) => choice($.path_expression, $.identifier, "."),
identifier: ($) => $._identifier_content,
path_expression: ($) => seq($.identifier, repeat1(seq(".", $.identifier))),
},
});