str/src/index.ts

26 lines
747 B
TypeScript

import {log} from './log.js'
import {Lifecycle} from './util/lifecycle.js'
import {Input} from './vm/input.js'
import {Lexer} from "./vm/lexer.js";
import {Parser} from "./vm/parser.js";
import {commands} from "./vm/commands/index.js";
import {Executor} from "./vm/vm.js";
const lifecycle = new Lifecycle()
const input = new Input()
input.adoptLifecycle(lifecycle)
input.subscribe(line => log.verbose('input', { line }))
const lexer = new Lexer(input)
lexer.subscribe(token => log.verbose('token', token))
const parser = new Parser(commands, lexer)
parser.subscribe(exec => log.verbose('exec', exec))
const exec = new Executor(parser)
exec.subscribe(state => state.output())
input.setupPrompt()
process.on('SIGINT', () => lifecycle.close())