This repository has been archived by the owner on Sep 10, 2024. It is now read-only.
forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Expressions] Add support of comments (elastic#122457)
* Add comments support to the expressions grammar * Add typings to the interpreter parser * Add expressions comments highlighting * Update canvas to preserve original expression formatting * Update documentation to cover comments
- Loading branch information
Showing
29 changed files
with
644 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export type AstNode = Ast | AstFunction | AstArgument; | ||
|
||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export type Ast = { | ||
type: 'expression'; | ||
chain: AstFunction[]; | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export type AstFunction = { | ||
type: 'function'; | ||
function: string; | ||
arguments: Record<string, AstArgument[]>; | ||
}; | ||
|
||
export type AstArgument = string | boolean | number | Ast; | ||
|
||
interface WithMeta<T> { | ||
start: number; | ||
end: number; | ||
text: string; | ||
node: T; | ||
} | ||
|
||
type Replace<T, R> = Pick<T, Exclude<keyof T, keyof R>> & R; | ||
|
||
type WrapAstArgumentWithMeta<T> = T extends Ast ? AstWithMeta : WithMeta<T>; | ||
export type AstArgumentWithMeta = WrapAstArgumentWithMeta<AstArgument>; | ||
|
||
export type AstFunctionWithMeta = WithMeta< | ||
Replace< | ||
AstFunction, | ||
{ | ||
arguments: { | ||
[key: string]: AstArgumentWithMeta[]; | ||
}; | ||
} | ||
> | ||
>; | ||
|
||
export type AstWithMeta = WithMeta< | ||
Replace< | ||
Ast, | ||
{ | ||
chain: AstFunctionWithMeta[]; | ||
} | ||
> | ||
>; | ||
|
||
export function isAstWithMeta(value: any): value is AstWithMeta { | ||
return typeof value?.node === 'object'; | ||
} | ||
|
||
export function isAst(value: any): value is Ast { | ||
return typeof value === 'object' && value?.type === 'expression'; | ||
} |
Oops, something went wrong.