Skip to content

feat(jmespath): add base types and errors #2192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/jmespath/src/Functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This is a placeholder for the real class. The actual implementation will be added in a subsequent PR.
export class Functions {
public iAmAPlaceholder = true;
}
97 changes: 97 additions & 0 deletions packages/jmespath/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* The binding powers for the various tokens in the JMESPath grammar.
*
* The binding powers are used to determine the order of operations for
* the parser. The higher the binding power, the more tightly the token
* binds to its arguments.
*/
const BINDING_POWER = {
eof: 0,
unquoted_identifier: 0,
quoted_identifier: 0,
literal: 0,
rbracket: 0,
rparen: 0,
comma: 0,
rbrace: 0,
number: 0,
current: 0,
expref: 0,
colon: 0,
pipe: 1,
or: 2,
and: 3,
eq: 5,
gt: 5,
lt: 5,
gte: 5,
lte: 5,
ne: 5,
flatten: 9,
// Everything above stops a projection.
star: 20,
filter: 21,
dot: 40,
not: 45,
lbrace: 50,
lbracket: 55,
lparen: 60,
} as const;

/**
* The set of ASCII lowercase letters allowed in JMESPath identifiers.
*/
const ASCII_LOWERCASE = 'abcdefghijklmnopqrstuvwxyz';
/**
* The set of ASCII uppercase letters allowed in JMESPath identifiers.
*/
const ASCII_UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
/**
* The set of ASCII letters allowed in JMESPath identifiers.
*/
const ASCII_LETTERS = ASCII_LOWERCASE + ASCII_UPPERCASE;
/**
* The set of ASCII digits allowed in JMESPath identifiers.
*/
const DIGITS = '0123456789';
/**
* The set of ASCII letters and digits allowed in JMESPath identifiers.
*/
const START_IDENTIFIER = new Set(ASCII_LETTERS + '_');
/**
* The set of ASCII letters and digits allowed in JMESPath identifiers.
*/
const VALID_IDENTIFIER = new Set(ASCII_LETTERS + DIGITS + '_');
/**
* The set of ASCII digits allowed in JMESPath identifiers.
*/
const VALID_NUMBER = new Set(DIGITS);
/**
* The set of ASCII whitespace characters allowed in JMESPath identifiers.
*/
const WHITESPACE = new Set(' \t\n\r');
/**
* The set of simple tokens in the JMESPath grammar.
*/
const SIMPLE_TOKENS: Map<string, keyof typeof BINDING_POWER> = new Map([
['.', 'dot'],
['*', 'star'],
[':', 'colon'],
[']', 'rbracket'],
[',', 'comma'],
[':', 'colon'],
['@', 'current'],
['(', 'lparen'],
[')', 'rparen'],
['{', 'lbrace'],
['}', 'rbrace'],
]);

export {
BINDING_POWER,
SIMPLE_TOKENS,
START_IDENTIFIER,
VALID_IDENTIFIER,
VALID_NUMBER,
WHITESPACE,
};
Loading