Skip to content

Commit

Permalink
Change type Node to ASTNode; Change interface KeyValuePairNode to type
Browse files Browse the repository at this point in the history
  • Loading branch information
Glen Van Ginkel committed Jul 28, 2020
1 parent 8be0487 commit 1d5afe0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/Lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ export interface LexerToken {
start: number;
}

export interface Node {
export interface ASTNode {
type: string;
}

export interface ValueNode<T = LexerTokenValue> extends Node {
export interface ValueNode<T = LexerTokenValue> extends ASTNode {
value: T;
}

export interface FieldNode extends Node {
export interface FieldNode extends ASTNode {
name: LexerTokenValue;
}

export interface KeyValuePairNode extends FieldNode, ValueNode<ExpressionNodeTree> {}
export type KeyValuePairNode = FieldNode & ValueNode<ExpressionNodeTree>;

export interface ExpressionNode<T = ExpressionNodeTree> extends Node {
export interface ExpressionNode<T = ExpressionNodeTree> extends ASTNode {
children: T[];
jmespathType?: Token;
}
Expand All @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
KeyValuePairNode,
LexerToken,
ValueNode,
Node,
ASTNode,
Token,
} from './Lexer';
import Lexer from './Lexer';
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1d5afe0

Please sign in to comment.