2015-04-26 18:10:04 +03:00
|
|
|
///<reference path='refs.ts'/>
|
2015-04-13 23:24:20 +03:00
|
|
|
|
2015-04-11 03:47:26 +03:00
|
|
|
module TDev {
|
|
|
|
|
2015-04-26 18:10:04 +03:00
|
|
|
export module Embedded {
|
2015-04-13 23:24:20 +03:00
|
|
|
|
|
|
|
import J = AST.Json
|
|
|
|
|
|
|
|
export class JsonAstVisitor<T, U> {
|
2015-04-14 02:59:52 +03:00
|
|
|
public visit(env: T, n: J.JNode): U {
|
2015-04-13 23:24:20 +03:00
|
|
|
switch (n.nodeType) {
|
|
|
|
case "numberLiteral":
|
|
|
|
return this.visitNumberLiteral(env, (<J.JNumberLiteral> n).value);
|
|
|
|
case "booleanLiteral":
|
|
|
|
return this.visitBooleanLiteral(env, (<J.JBooleanLiteral> n).value);
|
|
|
|
case "stringLiteral":
|
|
|
|
return this.visitStringLiteral(env, (<J.JStringLiteral> n).value);
|
|
|
|
case "operator":
|
|
|
|
return this.visitOperator(env, (<J.JOperator> n).op);
|
|
|
|
case "propertyRef":
|
|
|
|
var n9 = <J.JPropertyRef> n;
|
|
|
|
return this.visitPropertyRef(env, n9.name, <any> n9.parent);
|
|
|
|
case "call":
|
2015-04-15 02:48:24 +03:00
|
|
|
var n10 = <J.JCall> n;
|
2015-05-21 23:57:40 +03:00
|
|
|
return this.visitCall(env, n10.name, n10.args, n10.parent, n10.isExtensionMethod);
|
2015-04-13 23:24:20 +03:00
|
|
|
case "singletonRef":
|
|
|
|
return this.visitSingletonRef(env, (<J.JSingletonRef> n).name);
|
2015-05-19 03:26:24 +03:00
|
|
|
case "globalDef":
|
|
|
|
var n13 = <J.JGlobalDef> n;
|
|
|
|
return this.visitGlobalDef(env, n13.name, n13.type);
|
2015-04-13 23:24:20 +03:00
|
|
|
case "localDef":
|
|
|
|
var n1 = <J.JLocalDef> n;
|
2015-04-15 03:38:18 +03:00
|
|
|
return this.visitLocalDef(env, n1.name, n1.id, n1.type);
|
2015-04-13 23:24:20 +03:00
|
|
|
case "localRef":
|
2015-04-15 02:48:24 +03:00
|
|
|
var n11 = <J.JLocalRef> n;
|
|
|
|
return this.visitLocalRef(env, n11.name, <any> n11.localId);
|
2015-04-13 23:24:20 +03:00
|
|
|
case "exprHolder":
|
|
|
|
return this.visitExprHolder(env, (<J.JExprHolder> n).tree);
|
|
|
|
case "exprStmt":
|
2015-05-20 23:03:32 +03:00
|
|
|
var ex = <J.JExprStmt> n
|
|
|
|
var tr = ex.expr.tree
|
|
|
|
switch (tr.nodeType) {
|
|
|
|
case "show":
|
|
|
|
var nshow = <J.JShow> tr;
|
|
|
|
return this.visitShow(env, nshow.expr);
|
|
|
|
case "break":
|
|
|
|
return this.visitBreak(env);
|
2015-05-20 23:54:40 +03:00
|
|
|
case "continue":
|
|
|
|
return this.visitContinue(env);
|
2015-05-20 23:03:32 +03:00
|
|
|
case "return":
|
|
|
|
var nret = <J.JReturn> tr;
|
|
|
|
return this.visitReturn(env, nret.expr);
|
|
|
|
default:
|
|
|
|
return this.visitExprStmt(env, ex.expr);
|
|
|
|
}
|
2015-04-13 23:24:20 +03:00
|
|
|
case "inlineActions":
|
|
|
|
var n8 = <J.JInlineActions> n;
|
|
|
|
return this.visitInlineActions(env, n8.expr, n8.actions);
|
|
|
|
case "while":
|
|
|
|
var n3 = <J.JWhile> n;
|
|
|
|
return this.visitWhile(env, n3.condition, n3.body);
|
|
|
|
case "for":
|
|
|
|
var n4 = <J.JFor> n;
|
|
|
|
return this.visitFor(env, n4.index, n4.bound, n4.body);
|
|
|
|
case "comment":
|
|
|
|
return this.visitComment(env, (<J.JComment> n).text);
|
|
|
|
case "if":
|
|
|
|
var n5 = <J.JIf> n;
|
|
|
|
return this.visitIf(env, n5.condition, n5.thenBody, n5.elseBody, n5.isElseIf);
|
|
|
|
case "inlineAction":
|
|
|
|
var n6 = <J.JInlineAction> n;
|
|
|
|
return this.visitInlineAction(env, n6.reference, n6.inParameters, n6.outParameters, n6.body);
|
|
|
|
case "action":
|
|
|
|
var n7 = <J.JAction> n;
|
2015-05-19 03:26:24 +03:00
|
|
|
return this.visitAction(env, n7.name, n7.inParameters, n7.outParameters, n7.body, n7.isPrivate);
|
2015-04-13 23:24:20 +03:00
|
|
|
case "app":
|
|
|
|
return this.visitApp(env, (<J.JApp> n).decls);
|
2015-04-15 01:50:13 +03:00
|
|
|
case "library":
|
|
|
|
return this.visitLibrary(env, (<J.JLibrary> n).scriptName);
|
2015-04-28 02:25:15 +03:00
|
|
|
case "art":
|
2015-05-19 03:26:24 +03:00
|
|
|
var n12 = <J.JArt> n;
|
|
|
|
return this.visitArt(env, n12.name, n12.type, n12.url);
|
|
|
|
case "data":
|
|
|
|
var n14 = <J.JData> n;
|
|
|
|
return this.visitData(env, n14.name, n14.type);
|
|
|
|
case "record":
|
|
|
|
var n15 = <J.JRecord> n;
|
|
|
|
return this.visitRecord(env, n15.name, n15.keys, n15.fields, n15.isExported);
|
2015-04-13 23:24:20 +03:00
|
|
|
}
|
2015-04-17 03:15:34 +03:00
|
|
|
throw new Error("Unsupported node: "+n.nodeType);
|
2015-04-13 23:24:20 +03:00
|
|
|
}
|
2015-04-11 03:47:26 +03:00
|
|
|
|
2015-04-17 03:15:34 +03:00
|
|
|
public visitNumberLiteral(env: T, v: number): U { throw new Error("Not implemented"); }
|
|
|
|
public visitStringLiteral(env: T, v: string): U { throw new Error("Not implemented"); }
|
|
|
|
public visitBooleanLiteral(env: T, v: boolean): U { throw new Error("Not implemented"); }
|
|
|
|
public visitOperator(env: T, op: string): U { throw new Error("Not implemented"); }
|
2015-04-13 23:24:20 +03:00
|
|
|
public visitPropertyRef(
|
|
|
|
env: T,
|
|
|
|
name: string,
|
2015-04-17 03:15:34 +03:00
|
|
|
parent: string): U { throw new Error("Not implemented"); }
|
2015-05-21 23:57:40 +03:00
|
|
|
public visitCall(
|
|
|
|
env: T,
|
|
|
|
name: string,
|
|
|
|
args: J.JExpr[],
|
|
|
|
parent: J.JTypeRef,
|
|
|
|
isExtensionMethod: boolean): U { throw new Error("Not implemented"); }
|
2015-04-17 03:15:34 +03:00
|
|
|
public visitSingletonRef(env: T, name: string): U { throw new Error("Not implemented"); }
|
2015-04-15 02:48:24 +03:00
|
|
|
public visitLocalDef(
|
|
|
|
env: T,
|
|
|
|
name: string,
|
|
|
|
id: string,
|
2015-04-17 03:15:34 +03:00
|
|
|
type: J.JTypeRef): U { throw new Error("Not implemented"); }
|
|
|
|
public visitLocalRef(env: T, name: string, id: string): U { throw new Error("Not implemented"); }
|
|
|
|
public visitExprHolder(env: T, expr: J.JExpr): U { throw new Error("Not implemented"); }
|
|
|
|
public visitExprStmt(env: T, expr: J.JExpr): U { throw new Error("Not implemented"); }
|
2015-05-20 23:03:32 +03:00
|
|
|
public visitReturn(env: T, expr: J.JExpr): U { throw new Error("Not implemented"); }
|
|
|
|
public visitShow(env: T, expr: J.JExpr): U { throw new Error("Not implemented"); }
|
|
|
|
public visitBreak(env: T): U { throw new Error("Not implemented"); }
|
2015-05-20 23:54:40 +03:00
|
|
|
public visitContinue(env: T): U { throw new Error("Not implemented"); }
|
2015-04-13 23:24:20 +03:00
|
|
|
public visitInlineActions(
|
|
|
|
env: T,
|
|
|
|
expr: J.JExpr,
|
2015-04-17 03:15:34 +03:00
|
|
|
actions: J.JInlineAction[]): U { throw new Error("Not implemented"); }
|
|
|
|
public visitWhile(env: T, cond: J.JExprHolder, body: J.JStmt[]): U { throw new Error("Not implemented"); }
|
2015-04-13 23:24:20 +03:00
|
|
|
public visitFor(
|
|
|
|
env: T,
|
|
|
|
index: J.JLocalDef,
|
|
|
|
bound: J.JExprHolder,
|
2015-04-17 03:15:34 +03:00
|
|
|
body: J.JStmt[]): U { throw new Error("Not implemented"); }
|
|
|
|
public visitComment(env: T, c: string): U { throw new Error("Not implemented"); }
|
2015-04-13 23:24:20 +03:00
|
|
|
public visitIf(
|
|
|
|
env: T,
|
|
|
|
cond: J.JExprHolder,
|
|
|
|
thenBranch: J.JStmt[],
|
|
|
|
elseBranch: J.JStmt[],
|
2015-04-17 03:15:34 +03:00
|
|
|
isElseIf: boolean): U { throw new Error("Not implemented"); }
|
2015-04-13 23:24:20 +03:00
|
|
|
public visitInlineAction(env: T,
|
|
|
|
reference: J.JLocalDef,
|
|
|
|
inParams: J.JLocalDef[],
|
|
|
|
outParams: J.JLocalDef[],
|
2015-04-17 03:15:34 +03:00
|
|
|
body: J.JStmt[]): U { throw new Error("Not implemented"); }
|
2015-04-13 23:24:20 +03:00
|
|
|
public visitAction(
|
|
|
|
env: T,
|
|
|
|
name: string,
|
|
|
|
inParams: J.JLocalDef[],
|
|
|
|
outParams: J.JLocalDef[],
|
2015-05-19 03:26:24 +03:00
|
|
|
body: J.JStmt[],
|
|
|
|
isPrivate: boolean): U { return this.visitDecl(env, name); }
|
2015-04-17 03:15:34 +03:00
|
|
|
public visitApp(env: T, decls: J.JDecl[]): U { throw new Error("Not implemented"); }
|
2015-05-19 03:26:24 +03:00
|
|
|
public visitLibrary(env: T, name: string): U { return this.visitDecl(env, name); }
|
|
|
|
public visitArt(
|
|
|
|
env: T,
|
|
|
|
name: string,
|
|
|
|
type: J.JTypeRef,
|
|
|
|
url: string): U { return this.visitGlobalDef(env, name, type); }
|
|
|
|
public visitData(
|
|
|
|
env: T,
|
|
|
|
name: string,
|
|
|
|
type: J.JTypeRef): U { return this.visitGlobalDef(env, name, type); }
|
|
|
|
public visitGlobalDef(
|
|
|
|
env: T,
|
|
|
|
name: string,
|
|
|
|
type: J.JTypeRef): U { return this.visitDecl(env, name); }
|
|
|
|
public visitRecord(
|
|
|
|
env: T,
|
|
|
|
name: string,
|
|
|
|
keys: J.JRecordKey[],
|
|
|
|
fields: J.JRecordField[],
|
|
|
|
isExported: boolean): U { return this.visitDecl(env, name); }
|
|
|
|
public visitDecl(
|
|
|
|
env: T,
|
|
|
|
name: string): U { throw new Error("Not implemented"); }
|
2015-04-11 03:47:26 +03:00
|
|
|
}
|
2015-04-13 23:24:20 +03:00
|
|
|
}
|
2015-04-11 03:47:26 +03:00
|
|
|
|
|
|
|
}
|
2015-04-15 01:50:13 +03:00
|
|
|
|
|
|
|
// vim: set ts=2 sw=2 sts=2:
|