diff --git a/src/Lexer.ts b/src/Lexer.ts index 9cd9276..bbfd13b 100644 --- a/src/Lexer.ts +++ b/src/Lexer.ts @@ -41,21 +41,21 @@ export interface LexerToken { start: number; } -export interface Node { +export interface ASTNode { type: string; } -export interface ValueNode extends Node { +export interface ValueNode extends ASTNode { value: T; } -export interface FieldNode extends Node { +export interface FieldNode extends ASTNode { name: LexerTokenValue; } -export interface KeyValuePairNode extends FieldNode, ValueNode {} +export type KeyValuePairNode = FieldNode & ValueNode; -export interface ExpressionNode extends Node { +export interface ExpressionNode extends ASTNode { children: T[]; jmespathType?: Token; } @@ -64,7 +64,7 @@ export interface ComparitorNode extends ExpressionNode { name: Token; } -export type ExpressionNodeTree = Node | ExpressionNode | FieldNode | ValueNode; +export type ExpressionNodeTree = ASTNode | ExpressionNode | FieldNode | ValueNode; export const basicTokens = { '(': Token.TOK_LPAREN, diff --git a/src/Parser.ts b/src/Parser.ts index dbd9b06..ec295e3 100644 --- a/src/Parser.ts +++ b/src/Parser.ts @@ -6,7 +6,7 @@ import { KeyValuePairNode, LexerToken, ValueNode, - Node, + ASTNode, Token, } from './Lexer'; import Lexer from './Lexer'; @@ -110,7 +110,7 @@ class TokenParser { this.parseProjectionRHS(bindingPower.Star); return { type: 'ValueProjection', children: [left, right] } as ExpressionNode; case Token.TOK_FILTER: - return this.led(token.type, { type: 'Identity' } as Node); + return this.led(token.type, { type: 'Identity' } as ASTNode); case Token.TOK_LBRACE: return this.parseMultiselectHash(); case Token.TOK_FLATTEN: @@ -141,7 +141,7 @@ class TokenParser { const args: ExpressionNodeTree[] = []; while (this.lookahead(0) !== Token.TOK_RPAREN) { if (this.lookahead(0) === Token.TOK_CURRENT) { - expression = { type: Token.TOK_CURRENT } as Node; + expression = { type: Token.TOK_CURRENT } as ASTNode; this.advance(); } else { expression = this.expression(0); @@ -179,11 +179,11 @@ class TokenParser { return { type: 'AndExpression', children: [left, right] } as ExpressionNode; case Token.TOK_LPAREN: const name = (left as FieldNode).name; - const args: (ExpressionNodeTree | Node)[] = []; + const args: (ExpressionNodeTree | ASTNode)[] = []; let expression; while (this.lookahead(0) !== Token.TOK_RPAREN) { if (this.lookahead(0) === Token.TOK_CURRENT) { - expression = { type: Token.TOK_CURRENT } as Node; + expression = { type: Token.TOK_CURRENT } as ASTNode; this.advance(); } else { expression = this.expression(0);