-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrammar.js
More file actions
46 lines (39 loc) · 1.13 KB
/
grammar.js
File metadata and controls
46 lines (39 loc) · 1.13 KB
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
/**
* @file MQL5 grammar for tree-sitter (extends C++)
* @license MIT
*/
/// <reference types="tree-sitter-cli/dsl" />
// @ts-check
const CPP = require('tree-sitter-cpp/grammar');
module.exports = grammar(CPP, {
name: 'mql5',
externals: ($, original) => [
...original,
$.color_literal,
],
rules: {
// Add input/sinput to storage class specifiers
storage_class_specifier: (_, original) => choice(
original,
'input',
'sinput',
),
// Add MQL5-specific primitive types
primitive_type: _ => token(choice(
'bool', 'char', 'int', 'float', 'double', 'void',
'size_t', 'ssize_t', 'ptrdiff_t', 'intptr_t', 'uintptr_t',
'charptr_t', 'nullptr_t', 'max_align_t',
...[8, 16, 32, 64].map(n => `int${n}_t`),
...[8, 16, 32, 64].map(n => `uint${n}_t`),
...[8, 16, 32, 64].map(n => `char${n}_t`),
'datetime', 'color', 'string',
'uchar', 'ushort', 'uint', 'ulong',
'long',
)),
// Add color_literal (external scanner token) to expressions
_expression_not_binary: ($, original) => choice(
original,
$.color_literal,
),
},
});