Skip to content

Commit b012173

Browse files
authored
feat(jmespath): add base types and errors (#2192)
* feat(jmespath): add base types and errors
1 parent 874e8ad commit b012173

File tree

5 files changed

+521
-3
lines changed

5 files changed

+521
-3
lines changed

Diff for: packages/jmespath/src/Functions.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This is a placeholder for the real class. The actual implementation will be added in a subsequent PR.
2+
export class Functions {
3+
public iAmAPlaceholder = true;
4+
}

Diff for: packages/jmespath/src/constants.ts

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* The binding powers for the various tokens in the JMESPath grammar.
3+
*
4+
* The binding powers are used to determine the order of operations for
5+
* the parser. The higher the binding power, the more tightly the token
6+
* binds to its arguments.
7+
*/
8+
const BINDING_POWER = {
9+
eof: 0,
10+
unquoted_identifier: 0,
11+
quoted_identifier: 0,
12+
literal: 0,
13+
rbracket: 0,
14+
rparen: 0,
15+
comma: 0,
16+
rbrace: 0,
17+
number: 0,
18+
current: 0,
19+
expref: 0,
20+
colon: 0,
21+
pipe: 1,
22+
or: 2,
23+
and: 3,
24+
eq: 5,
25+
gt: 5,
26+
lt: 5,
27+
gte: 5,
28+
lte: 5,
29+
ne: 5,
30+
flatten: 9,
31+
// Everything above stops a projection.
32+
star: 20,
33+
filter: 21,
34+
dot: 40,
35+
not: 45,
36+
lbrace: 50,
37+
lbracket: 55,
38+
lparen: 60,
39+
} as const;
40+
41+
/**
42+
* The set of ASCII lowercase letters allowed in JMESPath identifiers.
43+
*/
44+
const ASCII_LOWERCASE = 'abcdefghijklmnopqrstuvwxyz';
45+
/**
46+
* The set of ASCII uppercase letters allowed in JMESPath identifiers.
47+
*/
48+
const ASCII_UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
49+
/**
50+
* The set of ASCII letters allowed in JMESPath identifiers.
51+
*/
52+
const ASCII_LETTERS = ASCII_LOWERCASE + ASCII_UPPERCASE;
53+
/**
54+
* The set of ASCII digits allowed in JMESPath identifiers.
55+
*/
56+
const DIGITS = '0123456789';
57+
/**
58+
* The set of ASCII letters and digits allowed in JMESPath identifiers.
59+
*/
60+
const START_IDENTIFIER = new Set(ASCII_LETTERS + '_');
61+
/**
62+
* The set of ASCII letters and digits allowed in JMESPath identifiers.
63+
*/
64+
const VALID_IDENTIFIER = new Set(ASCII_LETTERS + DIGITS + '_');
65+
/**
66+
* The set of ASCII digits allowed in JMESPath identifiers.
67+
*/
68+
const VALID_NUMBER = new Set(DIGITS);
69+
/**
70+
* The set of ASCII whitespace characters allowed in JMESPath identifiers.
71+
*/
72+
const WHITESPACE = new Set(' \t\n\r');
73+
/**
74+
* The set of simple tokens in the JMESPath grammar.
75+
*/
76+
const SIMPLE_TOKENS: Map<string, keyof typeof BINDING_POWER> = new Map([
77+
['.', 'dot'],
78+
['*', 'star'],
79+
[':', 'colon'],
80+
[']', 'rbracket'],
81+
[',', 'comma'],
82+
[':', 'colon'],
83+
['@', 'current'],
84+
['(', 'lparen'],
85+
[')', 'rparen'],
86+
['{', 'lbrace'],
87+
['}', 'rbrace'],
88+
]);
89+
90+
export {
91+
BINDING_POWER,
92+
SIMPLE_TOKENS,
93+
START_IDENTIFIER,
94+
VALID_IDENTIFIER,
95+
VALID_NUMBER,
96+
WHITESPACE,
97+
};

0 commit comments

Comments
 (0)