mancha
Version:
Javscript HTML rendering engine
102 lines (101 loc) • 3.22 kB
TypeScript
import type * as ast from "./ast.js";
import type { AstFactory } from "./ast_factory.js";
export interface Scope {
[key: string]: unknown;
}
export interface Evaluatable {
evaluate(scope: Scope): unknown;
getIds(idents: string[]): string[];
}
export type Expression = Literal | Empty | ID | Unary | Binary | Getter | Invoke | Index | Ternary | Map | List | ArrowFunction | SpreadProperty | SpreadElement | Property;
export interface Literal extends Evaluatable {
type: "Literal";
value: ast.LiteralValue;
}
export interface Empty extends Evaluatable {
type: "Empty";
}
export interface ID extends Evaluatable {
type: "ID";
value: string;
}
export interface Unary extends Evaluatable {
type: "Unary";
operator: string;
child: Expression;
}
export interface Binary extends Evaluatable {
type: "Binary";
operator: string;
left: Expression;
right: Expression;
}
export interface Getter extends Evaluatable {
type: "Getter";
receiver: Expression;
name: string;
optional?: boolean;
}
export interface Invoke extends Evaluatable {
type: "Invoke";
receiver: Expression;
method: string | undefined;
arguments: Array<Expression> | undefined;
optional?: boolean;
}
export interface Index extends Evaluatable {
type: "Index";
receiver: Expression;
argument: Expression;
optional?: boolean;
}
export interface Ternary extends Evaluatable {
type: "Ternary";
condition: Expression;
trueExpr: Expression;
falseExpr: Expression;
}
export interface Map extends Evaluatable {
type: "Map";
properties?: Array<Property | SpreadProperty> | undefined;
}
export interface Property extends Evaluatable {
type: "Property";
key: string;
value: Expression;
}
export interface List extends Evaluatable {
type: "List";
items: Array<Expression> | undefined;
}
export interface ArrowFunction extends Evaluatable {
type: "ArrowFunction";
params: Array<string>;
body: Expression;
}
export interface SpreadProperty extends Evaluatable {
type: "SpreadProperty";
expression: Expression;
}
export interface SpreadElement extends Evaluatable {
type: "SpreadElement";
expression: Expression;
}
export declare class EvalAstFactory implements AstFactory<Expression> {
empty(): Empty;
literal(v: ast.LiteralValue): Literal;
id(v: string): ID;
unary(op: string, expr: Expression): Unary;
binary(l: Expression, op: string, r: Expression): Binary;
getter(g: Expression, n: string, optional?: boolean): Getter;
invoke(receiver: Expression, method: string | undefined, args: Expression[], optional?: boolean): Invoke;
paren(e: Expression): Expression;
index(e: Expression, a: Expression, optional?: boolean): Index;
ternary(c: Expression, t: Expression, f: Expression): Ternary;
map(properties: Array<Property | SpreadProperty> | undefined): Map;
property(key: string, value: Expression): Property;
list(l: Array<Expression> | undefined): List;
arrowFunction(params: string[], body: Expression): Expression;
spreadProperty(expression: Expression): SpreadProperty;
spreadElement(expression: Expression): SpreadElement;
}