webidl-parser 0.1.0

A WebIDL parser
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
#![allow(missing_docs)]

pub type Identifier = String;

#[derive(Clone, Debug, PartialEq)]
pub enum Argument {
    NonOptional(NonOptionalArgument),
    Optional(OptionalArgument),
}

#[allow(variant_size_differences)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum ArgumentName {
    Identifier(Identifier),
    Keyword(ArgumentNameKeyword),
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum ArgumentNameKeyword {
    Attribute,
    Callback,
    Const,
    Deleter,
    Dictionary,
    Enum,
    Getter,
    Implements,
    Inherit,
    Interface,
    Iterable,
    LegacyCaller,
    Maplike,
    Namespace,
    Partial,
    Required,
    Serializer,
    Setlike,
    Setter,
    Static,
    Stringifier,
    Typedef,
    Unrestricted,
}

#[derive(Clone, Debug, PartialEq)]
pub struct Attribute {
    pub inherit: bool,
    pub name: AttributeName,
    pub read_only: bool,
    pub type_: Box<TypeWithExtendedAttributes>,
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum AttributeName {
    Identifier(Identifier),
    Required,
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum BufferRelatedType {
    ArrayBuffer,
    DataView,
    Int16Array,
    Int32Array,
    Int8Array,
    Uint16Array,
    Uint32Array,
    Uint8Array,
    Uint8ClampedArray,
    Float32Array,
    Float64Array,
}

#[derive(Clone, Debug, PartialEq)]
pub struct Callback {
    pub arguments: Vec<Argument>,
    pub name: Identifier,
    pub return_type: ReturnType,
}

#[derive(Clone, Debug, PartialEq)]
pub struct Const {
    pub name: Identifier,
    pub type_: ConstType,
    pub value: ConstValue,
}

#[allow(variant_size_differences)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum ConstType {
    Identifier(Nullable<Identifier>),
    PrimitiveType(Nullable<PrimitiveType>),
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub enum ConstValue {
    BooleanLiteral(bool),
    FloatLiteral(f64),
    IntegerLiteral(i64),
    Null,
}

#[derive(Clone, Debug, PartialEq)]
pub enum DefaultValue {
    ConstValue(ConstValue),
    EmptySequence,
    StringLiteral(String),
}

#[derive(Clone, Debug, PartialEq)]
pub struct Definition {
    pub definition_type: DefinitionType,
    pub extended_attributes: Vec<Box<ExtendedAttribute>>,
}

#[derive(Clone, Debug, PartialEq)]
pub enum DefinitionType {
    Callback(Callback),
    Dictionary(Dictionary),
    Enum(Enum),
    Implements(Implements),
    Interface(Interface),
    Namespace(Namespace),
    Typedef(Typedef),
}

#[derive(Clone, Debug, PartialEq)]
pub struct Dictionary {
    pub members: Vec<DictionaryMember>,
    pub name: Identifier,
    pub type_: DictionaryType,
}

#[derive(Clone, Debug, PartialEq)]
pub enum DictionaryMember {
    NonRequired(NonRequiredDictionaryMember),
    Required(RequiredDictionaryMember),
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum DictionaryType {
    NonPartial(Option<Identifier>),
    Partial,
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct Enum {
    pub name: String,
    pub variants: Vec<String>,
}

#[derive(Clone, Debug, PartialEq)]
pub enum ExtendedAttribute {
    Nested {
        group_type: ExtendedAttributeGroupType,
        inner: Option<Box<ExtendedAttributeInner>>,
        rest: Option<Box<ExtendedAttribute>>,
    },
    Other {
        other: Other,
        rest: Option<Box<ExtendedAttribute>>,
    },
}

#[derive(Clone, Debug, PartialEq)]
pub enum ExtendedAttributePattern {
    ArgList(Identifier, Vec<Argument>),
    Identifier(Identifier, Identifier),
    IdentifierList(Identifier, Vec<Identifier>),
    NamedArgList(Identifier, Identifier, Vec<Argument>),
    NoArgs(Identifier),
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum ExtendedAttributeGroupType {
    Brace,
    Bracket,
    Parenthesis,
}

#[derive(Clone, Debug, PartialEq)]
pub enum ExtendedAttributeInner {
    Nested {
        group_type: ExtendedAttributeGroupType,
        inner: Option<Box<ExtendedAttributeInner>>,
        rest: Option<Box<ExtendedAttributeInner>>,
    },
    Other {
        inner: Option<Box<ExtendedAttributeInner>>,
        other: Option<Other>,
    },
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum FloatType {
    Double,
    Float,
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct Implements {
    pub lhs: Identifier,
    pub rhs: Identifier,
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum IntegerType {
    Long,
    LongLong,
    Short,
}

#[derive(Clone, Debug, PartialEq)]
pub struct Interface {
    pub members: Vec<InterfaceMember>,
    pub name: Identifier,
    pub type_: InterfaceType,
}

#[derive(Clone, Debug, PartialEq)]
pub struct InterfaceMember {
    pub extended_attributes: Vec<Box<ExtendedAttribute>>,
    pub type_: InterfaceMemberType,
}

#[derive(Clone, Debug, PartialEq)]
pub enum InterfaceMemberType {
    Attribute(Attribute),
    Const(Const),
    Iterable(Iterable),
    Maplike(Maplike),
    Operation(Operation),
    Serializer(Serializer),
    Setlike(Setlike),
    StaticMember(StaticMember),
    Stringifier(Stringifier),
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum InterfaceType {
    Callback(Option<Identifier>),
    NonPartial(Option<Identifier>),
    Partial,
}

#[derive(Clone, Debug, PartialEq)]
pub struct Iterable {
    pub key_type: Option<Box<TypeWithExtendedAttributes>>,
    pub value_type: Box<TypeWithExtendedAttributes>,
}

#[derive(Clone, Debug, PartialEq)]
pub struct Maplike {
    pub key_type: Box<TypeWithExtendedAttributes>,
    pub read_only: bool,
    pub value_type: Box<TypeWithExtendedAttributes>,
}

#[derive(Clone, Debug, PartialEq)]
pub struct Namespace {
    pub members: Vec<NamespaceMember>,
    pub name: Identifier,
    pub partial: bool,
}

#[derive(Clone, Debug, PartialEq)]
pub struct NamespaceMember {
    pub extended_attributes: Vec<Box<ExtendedAttribute>>,
    pub type_: NamespaceMemberType,
}

#[derive(Clone, Debug, PartialEq)]
pub enum NamespaceMemberType {
    Attribute(NamespaceMemberAttribute),
    Operation(NamespaceMemberOperation),
}

#[derive(Clone, Debug, PartialEq)]
pub struct NamespaceMemberAttribute {
    pub name: AttributeName,
    pub type_: Box<TypeWithExtendedAttributes>,
}

#[derive(Clone, Debug, PartialEq)]
pub struct NamespaceMemberOperation {
    pub arguments: Vec<Argument>,
    pub name: Option<Identifier>,
    pub return_type: ReturnType,
}

#[derive(Clone, Debug, PartialEq)]
pub enum NonAnyType {
    BufferRelatedType(Nullable<BufferRelatedType>),
    Error(bool),
    DOMException(bool),
    FrozenArray(Nullable<Box<TypeWithExtendedAttributes>>),
    Identifier(Nullable<Identifier>),
    Object(bool),
    PrimitiveType(Nullable<PrimitiveType>),
    PromiseType(ReturnType),
    RecordType(Nullable<RecordType>),
    Sequence(Nullable<Box<TypeWithExtendedAttributes>>),
    StringType(Nullable<StringType>),
}

#[derive(Clone, Debug, PartialEq)]
pub struct NonAnyUnionMemberType {
    pub extended_attributes: Vec<Box<ExtendedAttribute>>,
    pub type_: NonAnyType,
}

#[derive(Clone, Debug, PartialEq)]
pub struct NonOptionalArgument {
    pub extended_attributes: Vec<Box<ExtendedAttribute>>,
    pub name: ArgumentName,
    pub type_: Box<Type>,
    pub variadic: bool,
}

#[derive(Clone, Debug, PartialEq)]
pub struct NonRequiredDictionaryMember {
    pub default: Option<DefaultValue>,
    pub extended_attributes: Vec<Box<ExtendedAttribute>>,
    pub name: Identifier,
    pub type_: Box<Type>,
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct Nullable<T> {
    pub nullable: bool,
    pub type_: T,
}

#[derive(Clone, Debug, PartialEq)]
pub struct Operation {
    pub arguments: Vec<Argument>,
    pub name: Option<Identifier>,
    pub return_type: ReturnType,
    pub specials: Vec<Special>,
}

#[derive(Clone, Debug, PartialEq)]
pub struct OptionalArgument {
    pub default: Option<DefaultValue>,
    pub extended_attributes: Vec<Box<ExtendedAttribute>>,
    pub name: ArgumentName,
    pub type_: Box<TypeWithExtendedAttributes>,
}

#[derive(Clone, Debug, PartialEq)]
pub enum Other {
    Any,
    Boolean,
    Byte,
    FrozenArray,
    Null,
    Object,
    Octet,
    Optional,
    Or,
    Sequence,
    Unsigned,
    Void,

    ArgumentNameKeyword(ArgumentNameKeyword),
    BooleanLiteral(bool),
    BufferRelatedType(BufferRelatedType),
    FloatLiteral(f64),
    FloatType(FloatType),
    Identifier(String),
    IntegerLiteral(i64),
    IntegerType(IntegerType),
    OtherLiteral(char),
    StringLiteral(String),
    StringType(StringType),

    Colon,
    Ellipsis,
    Equals,
    GreaterThan,
    Hyphen,
    LessThan,
    Period,
    QuestionMark,
    Semicolon,
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum PrimitiveType {
    Boolean,
    Byte,
    Octet,
    UnrestrictedFloatType(UnrestrictedFloatType),
    UnsignedIntegerType(UnsignedIntegerType),
}

#[derive(Clone, Debug, PartialEq)]
pub struct RecordType {
    pub key_type: StringType,
    pub value_type: Box<TypeWithExtendedAttributes>,
}

#[derive(Clone, Debug, PartialEq)]
pub struct RequiredDictionaryMember {
    pub default: Option<DefaultValue>,
    pub extended_attributes: Vec<Box<ExtendedAttribute>>,
    pub name: Identifier,
    pub type_: Box<TypeWithExtendedAttributes>,
}

#[derive(Clone, Debug, PartialEq)]
pub enum ReturnType {
    Type(Box<Type>),
    Void,
}

#[derive(Clone, Debug, PartialEq)]
pub enum Serializer {
    Default,
    Operation(SerializationOperation),
    Pattern(SerializationPattern),
}

#[derive(Clone, Debug, PartialEq)]
pub struct SerializationOperation {
    pub arguments: Vec<Argument>,
    pub name: Option<Identifier>,
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum SerializationPattern {
    Identifier(Identifier),
    List(Option<SerializationPatternList>),
    Map(Option<SerializationPatternMap>),
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum SerializationPatternList {
    Getter,
    Identifiers(Vec<Identifier>),
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum SerializationPatternMap {
    Getter,
    Identifiers(Vec<Identifier>),
    Inherit(Vec<Identifier>),
}

#[derive(Clone, Debug, PartialEq)]
pub struct Setlike {
    pub read_only: bool,
    pub value_type: Box<TypeWithExtendedAttributes>,
}

#[derive(Clone, Debug, PartialEq)]
pub enum SingleType {
    Any,
    NonAnyType(NonAnyType),
}

#[derive(Clone, Debug, PartialEq)]
pub struct SingleTypeWithExtendedAttributes {
    pub extended_attributes: Vec<Box<ExtendedAttribute>>,
    pub type_: SingleType,
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum Special {
    Deleter,
    Getter,
    LegacyCaller,
    Setter,
}

#[derive(Clone, Debug, PartialEq)]
pub enum StaticMember {
    Attribute(StaticMemberAttribute),
    Operation(StaticMemberOperation),
}

#[derive(Clone, Debug, PartialEq)]
pub struct StaticMemberAttribute {
    pub name: AttributeName,
    pub read_only: bool,
    pub type_: Box<TypeWithExtendedAttributes>,
}

#[derive(Clone, Debug, PartialEq)]
pub struct StaticMemberOperation {
    pub arguments: Vec<Argument>,
    pub name: Option<Identifier>,
    pub return_type: ReturnType,
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum StringType {
    ByteString,
    DOMString,
    USVString,
}

#[derive(Clone, Debug, PartialEq)]
pub enum Stringifier {
    Attribute(StringifierAttribute),
    Default,
    Operation(StringifierOperation),
}

#[derive(Clone, Debug, PartialEq)]
pub struct StringifierAttribute {
    pub name: AttributeName,
    pub read_only: bool,
    pub type_: Box<TypeWithExtendedAttributes>,
}

#[derive(Clone, Debug, PartialEq)]
pub struct StringifierOperation {
    pub arguments: Vec<Argument>,
    pub name: Option<Identifier>,
    pub return_type: ReturnType,
}

#[derive(Clone, Debug, PartialEq)]
pub enum Type {
    SingleType(SingleType),
    UnionType(Nullable<Vec<UnionMemberType>>),
}

#[derive(Clone, Debug, PartialEq)]
pub enum TypeWithExtendedAttributes {
    SingleType(SingleTypeWithExtendedAttributes),
    UnionType(UnionTypeWithExtendedAttributes),
}

#[derive(Clone, Debug, PartialEq)]
pub struct Typedef {
    pub name: Identifier,
    pub type_: Box<TypeWithExtendedAttributes>,
}

#[derive(Clone, Debug, PartialEq)]
pub enum UnionMemberType {
    NonAnyType(NonAnyUnionMemberType),
    UnionType(Nullable<Vec<UnionMemberType>>),
}

#[derive(Clone, Debug, PartialEq)]
pub struct UnionTypeWithExtendedAttributes {
    pub extended_attributes: Vec<Box<ExtendedAttribute>>,
    pub nullable: bool,
    pub type_: Vec<UnionMemberType>,
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct UnrestrictedFloatType {
    pub float_type: FloatType,
    pub restricted: bool,
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct UnsignedIntegerType {
    pub integer_type: IntegerType,
    pub unsigned: bool,
}