cddl 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/ast.d.ts +13 -1
- package/build/ast.d.ts.map +1 -1
- package/build/parser.d.ts +2 -0
- package/build/parser.d.ts.map +1 -1
- package/build/parser.js +84 -4
- package/examples/webdriver/remote.cddl +1 -1
- package/package.json +1 -1
package/build/ast.d.ts
CHANGED
|
@@ -48,6 +48,7 @@ export type Variable = {
|
|
|
48
48
|
Name: string;
|
|
49
49
|
IsChoiceAddition: boolean;
|
|
50
50
|
PropertyType: PropertyType | PropertyType[];
|
|
51
|
+
Operator?: Operator;
|
|
51
52
|
};
|
|
52
53
|
/**
|
|
53
54
|
* a comment statement
|
|
@@ -69,6 +70,7 @@ export type Property = {
|
|
|
69
70
|
Name: PropertyName;
|
|
70
71
|
Type: PropertyType | PropertyType[];
|
|
71
72
|
Comment: string;
|
|
73
|
+
Operator?: Operator;
|
|
72
74
|
};
|
|
73
75
|
export declare enum Type {
|
|
74
76
|
/**
|
|
@@ -115,13 +117,23 @@ export type Range = {
|
|
|
115
117
|
Max: RangePropertyReference;
|
|
116
118
|
Inclusive: boolean;
|
|
117
119
|
};
|
|
120
|
+
export type OperatorType = 'default' | 'size' | 'regexp' | 'bits' | 'and' | 'within' | 'eq' | 'ne' | 'lt' | 'le' | 'gt' | 'ge';
|
|
121
|
+
export interface Operator {
|
|
122
|
+
Type: OperatorType;
|
|
123
|
+
Value: PropertyType;
|
|
124
|
+
}
|
|
118
125
|
export type PropertyReferenceType = 'literal' | 'group' | 'group_array' | 'range' | 'tag';
|
|
119
126
|
export type PropertyReference = {
|
|
120
127
|
Type: PropertyReferenceType;
|
|
121
128
|
Value: string | number | boolean | Group | Array | Range | Tag;
|
|
122
129
|
Unwrapped: boolean;
|
|
130
|
+
Operator?: Operator;
|
|
123
131
|
};
|
|
132
|
+
export interface NativeTypeWithOperator {
|
|
133
|
+
Type: Type;
|
|
134
|
+
Operator?: Operator;
|
|
135
|
+
}
|
|
124
136
|
export type Assignment = Group | Array | Variable | Comment;
|
|
125
|
-
export type PropertyType = Assignment | Array | PropertyReference | string;
|
|
137
|
+
export type PropertyType = Assignment | Array | PropertyReference | string | NativeTypeWithOperator;
|
|
126
138
|
export type PropertyName = string;
|
|
127
139
|
//# sourceMappingURL=ast.d.ts.map
|
package/build/ast.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,MAAM,KAAK,GAAG;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,gBAAgB,EAAE,OAAO,CAAC;IAC1B,UAAU,EAAE,CAAC,QAAQ,GAAC,QAAQ,EAAE,CAAC,EAAE,CAAC;CACvC,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,KAAK,GAAG;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,CAAC,QAAQ,GAAC,QAAQ,EAAE,CAAC,EAAE,CAAC;CACnC,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,GAAG,GAAG;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CACpB,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG;IACnB,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,OAAO,CAAC;IAC1B,YAAY,EAAE,YAAY,GAAG,YAAY,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,MAAM,KAAK,GAAG;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,E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UAAU,GAAG,KAAK,GAAG,iBAAiB,GAAG,MAAM,GAAG,sBAAsB,CAAA;AACnG,MAAM,MAAM,YAAY,GAAG,MAAM,CAAA"}
|
package/build/parser.d.ts
CHANGED
package/build/parser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,YAAY,CAAA;AAE9B,OAAO,EAAE,KAAK,EAAU,MAAM,aAAa,CAAC;AAG5C,OAAO,EAE2C,UAAU,EAE3D,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,YAAY,CAAA;AAE9B,OAAO,EAAE,KAAK,EAAU,MAAM,aAAa,CAAC;AAG5C,OAAO,EAE2C,UAAU,EAE3D,MAAM,UAAU,CAAA;AAoBjB,MAAM,CAAC,OAAO,OAAO,MAAM;;IAEvB,CAAC,EAAE,KAAK,CAAC;IAET,QAAQ,EAAE,KAAK,CAAa;IAC5B,SAAS,EAAE,KAAK,CAAa;gBAEhB,QAAQ,EAAE,MAAM;IAQ7B,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,gBAAgB;IA8BxB,OAAO,CAAC,oBAAoB;IAyW5B,OAAO,CAAC,wBAAwB;IAahC;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAoBnB,OAAO,CAAC,iBAAiB;IAazB,OAAO,CAAC,iBAAiB;IA2HzB,OAAO,CAAC,aAAa;IAgBrB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,kBAAkB;IAiD1B,OAAO,CAAC,gBAAgB;IA4DxB;;OAEG;IACH,OAAO,CAAC,YAAY;IAUpB,KAAK;IAuBL,OAAO,CAAC,WAAW;CAKtB"}
|
package/build/parser.js
CHANGED
|
@@ -6,6 +6,21 @@ import { parseNumberValue } from './utils.js';
|
|
|
6
6
|
import { Type } from './ast.js';
|
|
7
7
|
const NIL_TOKEN = { Type: Tokens.ILLEGAL, Literal: '' };
|
|
8
8
|
const DEFAULT_OCCURRENCE = { n: 1, m: 1 }; // exactly one time
|
|
9
|
+
const OPERATORS = ['default', 'size', 'regexp', 'bits', 'and', 'within', 'eq', 'ne', 'lt', 'le', 'gt', 'ge'];
|
|
10
|
+
const OPERATORS_EXPECTING_VALUES = {
|
|
11
|
+
default: undefined,
|
|
12
|
+
size: ['literal', 'range'],
|
|
13
|
+
regexp: ['literal'],
|
|
14
|
+
bits: ['group'],
|
|
15
|
+
and: ['group'],
|
|
16
|
+
within: ['group'],
|
|
17
|
+
eq: ['group'],
|
|
18
|
+
ne: ['group'],
|
|
19
|
+
lt: ['group'],
|
|
20
|
+
le: ['group'],
|
|
21
|
+
gt: ['group'],
|
|
22
|
+
ge: ['group'],
|
|
23
|
+
};
|
|
9
24
|
export default class Parser {
|
|
10
25
|
#filePath;
|
|
11
26
|
l;
|
|
@@ -103,10 +118,34 @@ export default class Parser {
|
|
|
103
118
|
IsChoiceAddition: isChoiceAddition,
|
|
104
119
|
PropertyType: propertyType
|
|
105
120
|
};
|
|
121
|
+
if (this.isOperator()) {
|
|
122
|
+
variable.Operator = this.parseOperator();
|
|
123
|
+
}
|
|
106
124
|
return variable;
|
|
107
125
|
}
|
|
108
126
|
return propertyType;
|
|
109
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* parse operator assignments, e.g. `ip4 = (float .ge 0.0) .default 1.0`
|
|
130
|
+
*/
|
|
131
|
+
if (closingTokens.length === 1 && this.peekToken.Type === Tokens.DOT) {
|
|
132
|
+
const prop = {
|
|
133
|
+
Type: this.parsePropertyType(),
|
|
134
|
+
Operator: this.parseOperator()
|
|
135
|
+
};
|
|
136
|
+
this.nextToken(); // eat closing token
|
|
137
|
+
if (groupName) {
|
|
138
|
+
const variable = {
|
|
139
|
+
Type: 'variable',
|
|
140
|
+
Name: groupName,
|
|
141
|
+
IsChoiceAddition: isChoiceAddition,
|
|
142
|
+
PropertyType: prop,
|
|
143
|
+
Operator: this.parseOperator()
|
|
144
|
+
};
|
|
145
|
+
return variable;
|
|
146
|
+
}
|
|
147
|
+
return [prop];
|
|
148
|
+
}
|
|
110
149
|
while (!closingTokens.includes(this.curToken.Type)) {
|
|
111
150
|
const propertyType = [];
|
|
112
151
|
let isUnwrapped = false;
|
|
@@ -258,6 +297,7 @@ export default class Parser {
|
|
|
258
297
|
* parse property value
|
|
259
298
|
*/
|
|
260
299
|
const props = this.parseAssignmentValue();
|
|
300
|
+
const operator = this.isOperator() ? this.parseOperator() : undefined;
|
|
261
301
|
if (Array.isArray(props)) {
|
|
262
302
|
/**
|
|
263
303
|
* property has multiple types (e.g. `float / tstr / int`)
|
|
@@ -284,7 +324,8 @@ export default class Parser {
|
|
|
284
324
|
Occurrence: occurrence,
|
|
285
325
|
Name: propertyName,
|
|
286
326
|
Type: propertyType,
|
|
287
|
-
Comment: comment
|
|
327
|
+
Comment: comment,
|
|
328
|
+
...(operator ? operator : {})
|
|
288
329
|
};
|
|
289
330
|
if (isChoice) {
|
|
290
331
|
valuesOrProperties[valuesOrProperties.length - 1].push(prop);
|
|
@@ -382,8 +423,9 @@ export default class Parser {
|
|
|
382
423
|
throw this.parserError(`Expected property name, received ${this.curToken.Type}(${this.curToken.Literal}), ${this.peekToken.Type}(${this.peekToken.Literal})`);
|
|
383
424
|
}
|
|
384
425
|
parsePropertyType() {
|
|
385
|
-
let type;
|
|
426
|
+
let type = undefined;
|
|
386
427
|
let isUnwrapped = false;
|
|
428
|
+
let isGroupedRange = false;
|
|
387
429
|
/**
|
|
388
430
|
* check if variable name is unwrapped
|
|
389
431
|
*/
|
|
@@ -451,6 +493,15 @@ export default class Parser {
|
|
|
451
493
|
Unwrapped: isUnwrapped
|
|
452
494
|
};
|
|
453
495
|
}
|
|
496
|
+
else if (this.curToken.Literal === Tokens.LPAREN && this.peekToken.Type === Tokens.NUMBER) {
|
|
497
|
+
this.nextToken();
|
|
498
|
+
type = {
|
|
499
|
+
Type: 'literal',
|
|
500
|
+
Value: parseNumberValue(this.curToken),
|
|
501
|
+
Unwrapped: isUnwrapped
|
|
502
|
+
};
|
|
503
|
+
isGroupedRange = true;
|
|
504
|
+
}
|
|
454
505
|
else {
|
|
455
506
|
throw this.parserError(`Invalid property type "${this.curToken.Literal}"`);
|
|
456
507
|
}
|
|
@@ -484,13 +535,42 @@ export default class Parser {
|
|
|
484
535
|
},
|
|
485
536
|
Unwrapped: isUnwrapped
|
|
486
537
|
};
|
|
538
|
+
if (isGroupedRange) {
|
|
539
|
+
this.nextToken(); // eat ")"
|
|
540
|
+
}
|
|
487
541
|
}
|
|
488
542
|
return type;
|
|
489
543
|
}
|
|
544
|
+
parseOperator() {
|
|
545
|
+
const type = this.peekToken.Literal;
|
|
546
|
+
if (this.curToken.Literal !== Tokens.DOT || !OPERATORS.includes(this.peekToken.Literal)) {
|
|
547
|
+
throw new Error(`Operator ".${type}", expects a ${OPERATORS_EXPECTING_VALUES[type].join(' or ')} property, but found ${this.peekToken.Literal}!`);
|
|
548
|
+
}
|
|
549
|
+
this.nextToken(); // eat "."
|
|
550
|
+
this.nextToken(); // eat operator type
|
|
551
|
+
const value = this.parsePropertyType();
|
|
552
|
+
this.nextToken(); // eat operator value
|
|
553
|
+
return {
|
|
554
|
+
Type: type,
|
|
555
|
+
Value: value
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
isOperator() {
|
|
559
|
+
return this.curToken.Literal === Tokens.DOT && OPERATORS.includes(this.peekToken.Literal);
|
|
560
|
+
}
|
|
490
561
|
parsePropertyTypes() {
|
|
491
562
|
const propertyTypes = [];
|
|
492
|
-
|
|
493
|
-
this.
|
|
563
|
+
let prop = this.parsePropertyType();
|
|
564
|
+
if (this.isOperator()) {
|
|
565
|
+
prop = {
|
|
566
|
+
Type: prop,
|
|
567
|
+
Operator: this.parseOperator()
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
else {
|
|
571
|
+
this.nextToken(); // eat `/`
|
|
572
|
+
}
|
|
573
|
+
propertyTypes.push(prop);
|
|
494
574
|
/**
|
|
495
575
|
* ensure we don't go into the next choice, e.g.:
|
|
496
576
|
* ```
|
package/package.json
CHANGED