-
Notifications
You must be signed in to change notification settings - Fork 17
/
grammar.js
52 lines (42 loc) · 1.02 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
/**
* @file Embedded Template grammar for tree-sitter
* @author Max Brunsfeld <maxbrunsfeld@gmail.com>
* @license MIT
*/
/// <reference types="tree-sitter-cli/dsl" />
// @ts-check
module.exports = grammar({
name: 'embedded_template',
extras: _ => [],
rules: {
template: $ => repeat(choice(
$.directive,
$.output_directive,
$.comment_directive,
$.graphql_directive,
$.content,
)),
code: _ => repeat1(choice(/[^%=_-]+|[%=_-]/, '%%>')),
content: _ => prec.right(repeat1(choice(/[^<]+|</, '<%%'))),
directive: $ => seq(
choice('<%', '<%_', '<%|'),
optional($.code),
choice('%>', '-%>', '_%>'),
),
output_directive: $ => seq(
choice('<%=', '<%==', '<%|=', '<%|==', '<%-'),
optional($.code),
choice('%>', '-%>', '=%>'),
),
comment_directive: $ => seq(
'<%#',
optional(alias($.code, $.comment)),
'%>',
),
graphql_directive: $ => seq(
'<%graphql',
optional($.code),
'%>',
),
},
});