-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.js
155 lines (149 loc) · 4.48 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const { commaSep, commaSep1 } = require('./common/common')
const base_types = require('./common/base_types')
const expr = require('./common/expr')
const literal = require('./common/literal')
const directive = require('./common/directive')
const interface_ = require('./common/interface')
const bitmask = require('./common/bitmask')
const annotation = require('./common/annotation')
const template = require('./common/template')
const value_type = require('./common/value_type')
const typedef_dcl = require('./common/typedef_dcl')
const union_dcl = require('./common/union_dcl')
const corba_interface = require('./common/corba_interface')
const corba_value = require('./common/corba_value')
const component_basic = require('./common/component_basic') // idl 7.4.8
const component_homes = require('./common/component_homes') // idl 7.4.9
const event_dcl = require('./common/event_dcl') // idl 7.4.10
const component_port = require('./common/component_port') // idl 7.4.11
module.exports = grammar({
name: 'idl',
extras: $ => [/\s|\\\r?\n/, $.comment],
inline: $ => [],
precedences: $ => [
[$.annotation_appl, $.scoped_name],
[$.simple_type_spec, $.unary_expr],
[$.annotation_member_type, $.const_type],
[$.simple_type_spec, $.primary_expr],
[$.definition, $.type_dcl],
[$.value_inheritance_spec, $.value_supports],
[$.value_inheritance_spec, $.value_inheritance],
[$.scoped_name, $.annotation_appl_param],
],
rules: {
specification: $ => repeat($.definition),
...base_types.rules,
...expr.rules,
...literal.rules,
...directive.rules,
...interface_.rules,
...bitmask.rules,
...annotation.rules,
...template.rules,
...value_type.rules,
...typedef_dcl.rules,
...union_dcl.rules,
...corba_interface.rules,
...corba_value.rules,
...component_basic.rules,
...component_homes.rules,
...event_dcl.rules,
...component_port.rules, // idl 7.4.11
definition: $ =>
choice(
seq(
choice(
$.module_dcl,
$.type_dcl,
$.const_dcl,
$.except_dcl,
$.interface_dcl,
$.annotation_dcl, // 7.4.15
$.template_module_dcl, // idl 7.4.12
$.template_module_inst, // idl 7.4.12
$.value_dcl, // idl 7.4.5
$.type_id_dcl, // idl 7.4.6
$.type_prefix_dcl, // idl 7.4.6
$.import_dcl, // idl 7.4.6
$.component_dcl, // idl 7.4.8
$.home_dcl, // idl 7.4.9
$.event_dcl, // idl 7.4.10
$.porttype_dcl, // idl 7.4.11
$.connector_dcl, // idl 7.4.11
),
';',
),
$.preproc_include,
$.preproc_call,
$.preproc_define,
),
type_dcl: $ =>
seq(
repeat($.annotation_appl),
choice($.constr_type_dcl, $.native_dcl, $.typedef_dcl),
),
constr_type_dcl: $ =>
choice(
$.struct_dcl,
$.union_dcl,
$.enum_dcl,
$.bitset_dcl, // idl 7.4.13
$.bitmask_dcl, // idl 7.4.13
),
native_dcl: $ => seq('native', $.simple_declarator),
module_dcl: $ =>
seq(
repeat($.annotation_appl),
'module',
$.identifier,
'{',
repeat($.definition),
'}',
),
struct_dcl: $ => choice($.struct_forward_dcl, $.struct_def),
struct_forward_dcl: $ => seq('struct', $.identifier),
struct_def: $ =>
seq(
'struct',
$.identifier,
optional(seq(':', field('parent', $.scoped_name))),
'{',
repeat($.member),
'}',
),
member: $ =>
prec.left(
seq(
repeat($.annotation_appl),
field('type', $.type_spec),
field('identifier', $.declarators),
optional($.default),
';',
optional($.extend_annotation_appl),
),
),
default: $ => seq('default', $.const_expr),
const_dcl: $ => seq('const', $.const_type, $.identifier, '=', $.const_expr),
const_type: $ =>
choice(
$.integer_type,
$.floating_pt_type,
$.fixed_pt_const_type,
$.char_type,
$.wide_char_type,
$.boolean_type,
$.octet_type,
$.string_type,
$.wide_string_type,
$.scoped_name,
$.sequence_type,
),
// table 21
identifier: _ => /[a-zA-Z_][\w_]*/, // 7.2.3
comment: $ =>
choice(
seq('//', /(\\+(.|\r?\n)|[^\\\n])*/),
seq('/*', /[^*]*\*+([^/*][^*]*\*+)*/, '/'),
),
},
})