Skip to content

Commit ff60494

Browse files
committed
Removed translator and py_visitor (Refs #51) [11]
* Removed translator.ts as thats the whole point of the migration + annoying import dependencies * py_visitor is not used, a failed attempt for migration.
1 parent 801e807 commit ff60494

File tree

5 files changed

+89
-940
lines changed

5 files changed

+89
-940
lines changed

src/cse-machine/py_visitor.ts

Lines changed: 0 additions & 222 deletions
This file was deleted.

src/index.ts

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,17 @@
129129
/* Use as a command line script */
130130
/* npm run start:dev -- test.py */
131131

132+
// import { Translator } from "./translator";
133+
// import { Program } from "estree";
134+
// import { Resolver } from "./resolver";
135+
// import { Context } from './cse-machine/context';
136+
// import { runCSEMachine } from "./runner/pyRunner";
137+
132138
import { Tokenizer } from "./tokenizer";
133139
import { Parser } from "./parser";
134-
import { Translator } from "./translator";
135-
import { Program } from "estree";
136-
import { Resolver } from "./resolver";
137-
import { Context } from './cse-machine/context';
140+
138141
export * from './errors';
139142
import { Finished, RecursivePartial, Result } from "./types";
140-
// import { runCSEMachine } from "./runner/pyRunner";
141143
import { initialise } from "./conductor/runner/util/initialise";
142144
import { PyEvaluator } from "./conductor/runner/types/PyEvaluator";
143145
export * from './errors';
@@ -147,20 +149,20 @@ import { PyContext } from "./cse-machine/py_context";
147149

148150
type Stmt = StmtNS.Stmt;
149151

150-
export function parsePythonToEstreeAst(code: string,
151-
variant: number = 1,
152-
doValidate: boolean = false): Program {
153-
const script = code + '\n'
154-
const tokenizer = new Tokenizer(script)
155-
const tokens = tokenizer.scanEverything()
156-
const pyParser = new Parser(script, tokens)
157-
const ast = pyParser.parse()
158-
if (doValidate) {
159-
new Resolver(script, ast).resolve(ast);
160-
}
161-
const translator = new Translator(script)
162-
return translator.resolve(ast) as unknown as Program
163-
}
152+
// export function parsePythonToEstreeAst(code: string,
153+
// variant: number = 1,
154+
// doValidate: boolean = false): Program {
155+
// const script = code + '\n'
156+
// const tokenizer = new Tokenizer(script)
157+
// const tokens = tokenizer.scanEverything()
158+
// const pyParser = new Parser(script, tokens)
159+
// const ast = pyParser.parse()
160+
// if (doValidate) {
161+
// new Resolver(script, ast).resolve(ast);
162+
// }
163+
// const translator = new Translator(script)
164+
// return translator.resolve(ast) as unknown as Program
165+
// }
164166

165167
// import {ParserErrors, ResolverErrors, TokenizerErrors} from "./errors";
166168
// import fs from "fs";
@@ -200,15 +202,15 @@ export interface IOptions {
200202
stepLimit: number
201203
};
202204

203-
export async function runInContext(
204-
code: string,
205-
context: Context,
206-
options: RecursivePartial<IOptions> = {}
207-
): Promise<Result> {
208-
const estreeAst = parsePythonToEstreeAst(code, 1, true);
209-
const result = runCSEMachine(code, estreeAst, context, options);
210-
return result;
211-
}
205+
// export async function runInContext(
206+
// code: string,
207+
// context: Context,
208+
// options: RecursivePartial<IOptions> = {}
209+
// ): Promise<Result> {
210+
// const estreeAst = parsePythonToEstreeAst(code, 1, true);
211+
// const result = runCSEMachine(code, estreeAst, context, options);
212+
// return result;
213+
// }
212214

213215

214216

@@ -245,7 +247,7 @@ if (require.main === module) {
245247
process.exit(1);
246248
}
247249
const options = {};
248-
const context = new Context();
250+
const context = new PyContext();
249251

250252
const filePath = process.argv[2];
251253

@@ -255,10 +257,10 @@ if (require.main === module) {
255257
const code = fs.readFileSync(filePath, "utf8") + "\n";
256258
console.log(`Parsing Python file: ${filePath}`);
257259

258-
const result = await runInContext(code, context, options);
260+
const result = await PyRunInContext(code, context, options);
259261
console.info(result);
260262
console.info((result as Finished).value);
261-
console.info((result as Finished).representation.toString((result as Finished).value));
263+
console.info((result as Finished).representation.toString());
262264

263265
} catch (e) {
264266
console.error("Error:", e);

0 commit comments

Comments
 (0)