-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.js
50 lines (42 loc) · 1.16 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
module.exports = grammar({
name: 'vento',
externals: $ => [
$._code,
],
extras: $ => [/\s/],
rules: {
template: $ => repeat(choice(
$.content,
$.tag,
)),
content: () => prec.right(repeat1(/[^\{]+|\{/)),
tag: $ => seq(
choice("{{", "{{-"),
optional($._expression),
optional($.filter),
choice("}}", "-}}")
),
_expression: $ => choice(
// "Solo keywords" are just code blocks
alias($.code_snippet, $.code),
alias($.keyword, $.code),
alias($.close_keyword, $.keyword),
seq(
$.keyword,
alias($._code, $.code),
),
$.comment,
),
filter: $ => repeat1(seq(
"|>",
alias($._code, $.code)
)),
// General rule for keyword tags
// It just tries to match the first word in a tag block,
// plus any other special characters that might be present
keyword: () => /[a-z>][a-zA-Z]*? |if|for|include|set|import|export|layout|function/,
code_snippet: $ => seq(/[a-zA-Z>\.\(\)\!_\?]/, $._code),
close_keyword: () => /\/([a-zA-Z]+|if|for|include|set|import|export|layout|function)/,
comment: () => /#[^#]+#/,
}
});