onelang
Version:
OneLang transpiler framework core
400 lines (399 loc) • 11.8 kB
TypeScript
export declare namespace OneAst {
interface ILangData {
literalClassNames: {
string: string;
boolean: string;
numeric: string;
character: string;
map: string;
array: string;
};
langId: string;
allowImplicitVariableDeclaration: boolean;
supportsTemplateStrings: boolean;
supportsFor: boolean;
}
interface TextRange {
start: number;
end: number;
}
interface NodeData {
sourceRange: TextRange;
destRanges: {
[langName: string]: TextRange;
};
}
interface INode {
nodeData?: NodeData;
}
interface Schema {
sourceType: "program" | "overlay" | "stdlib";
langData: ILangData;
meta: {
transforms?: {
[name: string]: boolean;
};
};
globals: {
[name: string]: VariableDeclaration;
};
enums: {
[name: string]: Enum;
};
classes: {
[name: string]: Class;
};
interfaces: {
[name: string]: Interface;
};
mainBlock: Block;
}
interface NamedItem extends INode {
name?: string;
outName?: string;
metaPath?: string;
}
interface Enum extends NamedItem {
name?: string;
values: EnumMember[];
type?: Type;
leadingTrivia: string;
}
interface EnumMember extends NamedItem {
name: string;
}
interface Interface extends NamedItem {
schemaRef?: Schema;
type?: Type;
properties: {
[name: string]: Property;
};
methods: {
[name: string]: Method;
};
typeArguments: string[];
meta?: {
iterable?: boolean;
};
leadingTrivia: string;
attributes: {
[name: string]: any;
};
baseInterfaces: string[];
}
interface Class extends Interface {
fields: {
[name: string]: Field;
};
constructor: Constructor;
meta?: {
iterable?: boolean;
overlay?: boolean;
stdlib?: boolean;
};
baseClass: string;
}
enum Visibility {
Public = "public",
Protected = "protected",
Private = "private"
}
enum TypeKind {
Void = "void",
Any = "any",
Null = "null",
Class = "class",
Interface = "interface",
Enum = "enum",
Method = "method",
Generics = "generics"
}
class Type implements INode {
typeKind: TypeKind;
$objType: string;
constructor(typeKind?: TypeKind);
className: string;
enumName: string;
typeArguments: Type[];
classType: Type;
methodName: string;
genericsName: string;
nodeData?: NodeData;
get isPrimitiveType(): boolean;
get isClass(): boolean;
get isInterface(): boolean;
get isClassOrInterface(): boolean;
get isComplexClass(): boolean;
get isEnum(): boolean;
get isMethod(): boolean;
get isGenerics(): boolean;
get isAny(): boolean;
get isNull(): boolean;
get isVoid(): boolean;
get isNumber(): boolean;
get isString(): boolean;
get isCharacter(): boolean;
get isBoolean(): boolean;
get isOneArray(): boolean;
get isOneMap(): boolean;
get canBeNull(): boolean;
equals(other: Type): any;
repr(): any;
get oneName(): string;
static PrimitiveTypeKinds: TypeKind[];
static get Void(): Type;
static get Any(): Type;
static get Null(): Type;
static Class(className: string, generics?: Type[]): Type;
static Interface(className: string, generics?: Type[]): Type;
static Enum(enumName: string): Type;
static Method(classType: Type, methodName: string): Type;
static Generics(genericsName: string): Type;
static Load(source: Type): Type;
}
interface VariableBase extends NamedItem {
type: Type;
isUnused?: boolean;
isMutable?: boolean;
}
interface Field extends VariableDeclaration {
classRef?: Class;
visibility: Visibility;
static: boolean;
}
interface Property extends VariableBase {
classRef?: Class;
visibility: Visibility;
static: boolean;
getter: Block;
setter: Block;
}
interface MethodParameter extends VariableDeclaration {
}
interface Constructor extends NamedItem {
classRef?: Class;
parameters: MethodParameter[];
body: Block;
throws: boolean;
leadingTrivia: string;
attributes: {
[name: string]: any;
};
}
interface Method extends NamedItem {
type?: Type;
classRef?: Class;
typeArguments: string[];
static: boolean;
parameters: MethodParameter[];
returns: Type;
body: Block;
throws: boolean;
mutates: boolean;
visibility?: Visibility;
leadingTrivia: string;
attributes: {
[name: string]: any;
};
}
type MethodLike = Method | Constructor;
enum ExpressionKind {
Call = "Call",
Binary = "Binary",
PropertyAccess = "PropertyAccess",
ElementAccess = "ElementAccess",
Identifier = "Identifier",
New = "New",
Conditional = "Conditional",
Literal = "Literal",
TemplateString = "TemplateString",
Parenthesized = "Parenthesized",
Unary = "Unary",
Cast = "Cast",
ArrayLiteral = "ArrayLiteral",
MapLiteral = "MapLiteral",
VariableReference = "VariableReference",
MethodReference = "MethodReference",
ThisReference = "ThisReference",
ClassReference = "ClassReference",
EnumReference = "EnumReference",
EnumMemberReference = "EnumMemberReference"
}
interface Expression extends INode {
exprKind: ExpressionKind;
parentRef?: Expression | Statement;
valueType?: Type;
typeArgs?: string[];
}
interface CallArgument extends Expression {
paramName?: string;
}
abstract class Reference implements Expression {
abstract exprKind: ExpressionKind;
parentRef?: Expression | Statement;
valueType?: Type;
}
enum VariableRefType {
StaticField = "StaticField",
InstanceField = "InstanceField",
MethodArgument = "MethodArgument",
LocalVar = "LocalVar"
}
class VariableRef extends Reference {
varType: VariableRefType;
varRef: VariableBase;
thisExpr?: Expression;
$objType: string;
exprKind: ExpressionKind;
static InstanceField(thisExpr: Expression, varRef: VariableBase): VariableRef;
static StaticField(thisExpr: Expression, varRef: VariableBase): VariableRef;
static MethodVariable(varRef: VariableBase): VariableRef;
static MethodArgument(varRef: VariableBase): VariableRef;
static Load(source: any): any;
protected constructor(varType: VariableRefType, varRef: VariableBase, thisExpr?: Expression);
}
class MethodReference extends Reference {
methodRef: Method;
thisExpr?: Expression;
exprKind: ExpressionKind;
constructor(methodRef: Method, thisExpr?: Expression);
}
class ClassReference extends Reference {
classRef: Class;
exprKind: ExpressionKind;
constructor(classRef: Class);
}
class EnumReference extends Reference {
enumRef: Enum;
exprKind: ExpressionKind;
constructor(enumRef: Enum);
}
class EnumMemberReference extends Reference {
enumMemberRef: EnumMember;
enumRef: Enum;
exprKind: ExpressionKind;
constructor(enumMemberRef: EnumMember, enumRef: Enum);
}
class ThisReference extends Reference {
exprKind: ExpressionKind;
}
interface CallExpression extends Expression {
method: Expression | MethodReference;
arguments: CallArgument[];
}
interface Identifier extends Expression {
text: string;
}
interface Literal extends Expression {
literalType: "numeric" | "string" | "character" | "boolean" | "null";
value: any;
escapedText: string;
escapedTextSingle: string;
}
interface TemplateStringPart {
literal: boolean;
text?: string;
expr?: Expression;
}
interface TemplateString extends Expression {
parts: TemplateStringPart[];
}
interface ArrayLiteral extends Expression {
items: Expression[];
}
interface MapLiteral extends Expression {
properties: VariableDeclaration[];
}
interface NewExpression extends Expression {
cls: Identifier | ClassReference;
typeArguments: Type[];
arguments: CallArgument[];
}
interface BinaryExpression extends Expression {
left: Expression;
operator: string;
right: Expression;
}
interface UnaryExpression extends Expression {
unaryType: "postfix" | "prefix";
operator: string;
operand: Expression;
}
interface CastExpression extends Expression {
expression: Expression;
newType: Type;
}
interface ParenthesizedExpression extends Expression {
expression: Expression;
}
interface ConditionalExpression extends Expression {
condition: Expression;
whenTrue: Expression;
whenFalse: Expression;
}
interface PropertyAccessExpression extends Expression {
object: Expression;
propertyName: string;
}
interface ElementAccessExpression extends Expression {
object: Expression;
elementExpr: Expression;
}
enum StatementType {
If = "If",
Return = "Return",
ExpressionStatement = "ExpressionStatement",
VariableDeclaration = "VariableDeclaration",
While = "While",
Throw = "Throw",
Foreach = "Foreach",
For = "For",
Break = "Break",
Unset = "Unset"
}
interface Statement extends INode {
leadingTrivia?: string;
leadingTrivia2?: string;
parentRef?: Block;
stmtType: StatementType;
}
interface IfStatement extends Statement, NamedItem {
condition: Expression;
then: Block;
else: Block;
}
interface ReturnStatement extends Statement {
expression: Expression;
}
interface ThrowStatement extends Statement {
expression: Expression;
}
interface ExpressionStatement extends Statement {
expression: Expression;
}
interface UnsetStatement extends Statement {
expression: Expression;
}
interface VariableDeclaration extends Statement, VariableBase {
initializer?: Expression;
}
interface WhileStatement extends Statement, NamedItem {
condition: Expression;
body: Block;
}
interface ForeachStatement extends Statement, NamedItem {
itemVariable: VariableBase;
items: Expression;
body: Block;
}
interface ForStatement extends Statement, NamedItem {
itemVariable: VariableDeclaration;
condition: Expression;
incrementor: Expression;
body: Block;
}
interface Block extends NamedItem {
parentRef?: Statement | MethodLike;
statements: Statement[];
}
}