-
Notifications
You must be signed in to change notification settings - Fork 4
/
grammar.js
51 lines (41 loc) · 1.43 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
const CPP = require("tree-sitter-cpp/grammar")
module.exports = grammar(CPP, {
name: 'cuda',
rules: {
_top_level_item: (_, original) => original,
_declaration_modifiers: ($, original) =>
choice(
$.launch_bounds,
'__device__',
'__host__',
prec(10, '__global__'),
'__forceinline__',
'__noinline__',
original
),
delete_expression: (_, original) => prec.left(original),
expression: ($, original) => choice(
original,
alias(prec(10, $.kernel_call_expression), $.call_expression),
),
kernel_call_expression: ($) => prec(1,seq(
field('function', $.expression),
$.kernel_call_syntax,
field('arguments', $.argument_list),
)),
kernel_call_syntax: $ => seq(alias(rep3('<'), '<<<'), $.expression, repeat(seq(",", $.expression)), alias(rep3('>'), '>>>')),
type_qualifier: (_, original) => choice(
original,
'__shared__',
'__global__',
'__local__',
'__constant__',
'__managed__',
'__grid_constant__',
),
launch_bounds: $ => seq("__launch_bounds__", "(", $.expression, optional(seq(",", $.expression),), ")"),
}
});
function rep3(obj) {
return token(seq(obj, /\s*/, obj, /\s*/, obj));
}