diff --git a/TODO.md b/TODO.md index 9acb5c40..f19e4354 100644 --- a/TODO.md +++ b/TODO.md @@ -7,6 +7,7 @@ update to esmodule remove hypergraph support - move test about hypergraph to docs/archive +- remove "sjcl" fix repl for windows diff --git a/src/app/App.ts b/src/app/App.ts index e3fa5c53..201a03a1 100644 --- a/src/app/App.ts +++ b/src/app/App.ts @@ -1,11 +1,9 @@ import * as Loggers from "@cicada-lang/framework/lib/loggers" import { AppConfig } from "./AppConfig" import { AppHome } from "./AppHome" -import { AppReplEventHandler } from "./AppReplEventHandler" export class App { logger = new Loggers.PrettyLogger() config = new AppConfig() home = new AppHome() - replEventHandler = new AppReplEventHandler() } diff --git a/src/app/AppReplEventHandler.ts b/src/app/AppReplEventHandler.ts deleted file mode 100644 index d9befcf3..00000000 --- a/src/app/AppReplEventHandler.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { ReplEvent, ReplEventHandler } from "@cicada-lang/framework/lib/repl" -import fs from "fs" -import process from "process" -import { createErrorReport, highlightErrorMessage } from "../lang/errors" -import { executeStmts } from "../lang/execute" -import { parseStmts } from "../lang/syntax" -import { Loader } from "../loader" -import { colors } from "../utils/colors" - -export class AppReplEventHandler extends ReplEventHandler { - pathname = process.cwd() + "/repl" - loader = new Loader({ - onOutput: (output) => console.log(colors.blue(output)), - }) - - constructor() { - super() - this.loader.fetcher.register("file", (url) => - fs.readFileSync(url.pathname, "utf8"), - ) - this.loader.fetcher.register("repl", (url) => { - return url.pathname === this.pathname - ? "" - : fs.readFileSync(url.pathname, "utf8") - }) - } - - greeting(): void { - console.log(`Chimera ${app.config.pkg.version}`) - } - - async handle(event: ReplEvent): Promise { - const { text } = event - - const url = new URL(`repl://${this.pathname}`) - const mod = this.loader.load(url, { text: "" }) - - try { - const stmts = parseStmts(text) - executeStmts(mod, stmts) - } catch (error) { - error = createErrorReport(error, text) - if (error instanceof Error) { - console.error(highlightErrorMessage(error.message)) - } else console.error(error) - } - } -} diff --git a/src/command-line/commands/DefaultCommand.ts b/src/command-line/commands/DefaultCommand.ts index 66518aa9..f3b46f0f 100644 --- a/src/command-line/commands/DefaultCommand.ts +++ b/src/command-line/commands/DefaultCommand.ts @@ -32,9 +32,9 @@ export class DefaultCommand extends Command { const file = argv["file"] if (file === undefined) { - const dir = process.cwd() - const command = new Commands.ReplCommand() - await command.execute({ dir }) + const command = new Commands.CommonHelp() + await command.execute({}, runner) + return } else { const command = new Commands.RunCommand() await command.execute({ file }) diff --git a/src/command-line/commands/ReplCommand.ts b/src/command-line/commands/ReplCommand.ts deleted file mode 100644 index 1a0a9c56..00000000 --- a/src/command-line/commands/ReplCommand.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { ReadlineRepl } from "@cicada-lang/framework/lib/repls/readline-repl" -import { Command, CommandRunner } from "@xieyuheng/command-line" -import Path from "path" - -type Args = {} - -export class ReplCommand extends Command { - name = "repl" - - description = "Open an interactive REPL" - - args = {} - - // prettier-ignore - help(runner: CommandRunner): string { - const { blue } = this.colors - - return [ - `The ${blue(this.name)} command takes you into a rabbit hole`, - ` called REPL -- "Read Evaluate Print Loop".`, - ``, - `In which you can try some ideas real quick.`, - ``, - blue(` ${runner.name} ${this.name}`), - ``, - ].join("\n") - } - - async execute(argv: Args): Promise { - const repl = await ReadlineRepl.create({ - dir: Path.resolve(process.cwd()), - handler: app.replEventHandler, - files: app.home, - commitOnDoubleNewline: true, - }) - - await repl.run() - } -} diff --git a/src/command-line/commands/index.ts b/src/command-line/commands/index.ts index 9f6711e3..014b11d4 100644 --- a/src/command-line/commands/index.ts +++ b/src/command-line/commands/index.ts @@ -1,4 +1,3 @@ export * from "@xieyuheng/command-line/lib/commands" export * from "./DefaultCommand" -export * from "./ReplCommand" export * from "./RunCommand" diff --git a/src/command-line/index.ts b/src/command-line/index.ts index 5154619f..42851d23 100644 --- a/src/command-line/index.ts +++ b/src/command-line/index.ts @@ -6,7 +6,6 @@ export function createCommandRunner(): CommandRunner { return new CommandRunners.CommonCommandRunner({ defaultCommand: new Commands.DefaultCommand(), commands: [ - new Commands.ReplCommand(), new Commands.RunCommand(), new Commands.CommonHelp(), ],