-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgrammar.js
101 lines (84 loc) · 2.6 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
const CPP = require("tree-sitter-cpp/grammar")
module.exports = grammar(CPP, {
name: 'hlsl',
conflicts: ($, original) => original.concat([
[$.function_declarator],
]),
rules: {
_top_level_item: (_, original) => original,
function_definition: ($, original) => seq(
optional(
$.hlsl_attribute,
)
, original
),
function_declarator: ($, original) => seq(
original,
optional($.semantics)
),
declaration: $ => seq(
$._declaration_specifiers,
commaSep1(field('declarator', choice(
seq($._declarator, optional(alias(seq(':', $.expression), $.semantics))),
$.init_declarator
))),
';'
),
_declaration_modifiers: ($, original) => choice(
'in',
'out',
'inout',
$.qualifiers,
original),
parameter_declaration: ($, original) =>
seq(
original,
optional($.semantics),
),
semantics: $ => seq(":", $.identifier),
_non_case_statement: ($, original) => choice($.discard_statement, $.cbuffer_specifier, original),
if_statement: ($, original) => seq(optional($.hlsl_attribute), original),
discard_statement: _ => seq('discard', ';'),
qualifiers: _ => choice(
'precise',
'shared',
'groupshared',
'uniform',
'row_major',
'column_major',
'globallycoherent',
'centroid',
'noperspective',
'nointerpolation',
'sample',
'linear',
'snorm',
'unorm',
'point',
'line',
'triangleadj',
'lineadj',
'triangle',
),
cbuffer_specifier: $ => prec.right(seq(
'cbuffer',
optional($.attribute_declaration),
choice(
field('name', $._class_name),
seq(
optional(field('name', $._class_name)),
optional($.virtual_specifier),
optional($.base_class_clause),
field('body', $.field_declaration_list)
)
)
)),
hlsl_attribute: $ => seq('[',
$.expression,
']'),
for_statement: ($, original) => seq(optional($.hlsl_attribute), original),
}
});
function commaSep1(rule) {
return seq(rule, repeat(seq(',', rule)))
}