-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
68 lines (57 loc) · 1.54 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import Start from './repl/repl';
import process from 'process';
import os from 'os';
import fs from 'fs';
import { NewEnvironment, NewBrowserEnvironment, NewNodeEnvironment } from './object/environment';
import Lexer from './lexer/lexer';
import Parser from './parser/parser';
import Eval from './evaluator/evaluator';
export { NewEnvironment, NewBrowserEnvironment, NewNodeEnvironment, Lexer, Parser, Eval };
import {
BOOLEAN_OBJ,
BUILTIN_OBJ,
ERROR_OBJ,
COMMENT_OBJ,
FUNCTION_OBJ,
INTEGER_OBJ,
FLOAT_OBJ,
NULL_OBJ,
RETURN_VALUE_OBJ,
STRING_OBJ,
ARRAY_OBJ,
HASH_OBJ,
} from './object/object';
export const OObject = {
BOOLEAN_OBJ,
BUILTIN_OBJ,
ERROR_OBJ,
COMMENT_OBJ,
FUNCTION_OBJ,
INTEGER_OBJ,
FLOAT_OBJ,
NULL_OBJ,
RETURN_VALUE_OBJ,
STRING_OBJ,
ARRAY_OBJ,
HASH_OBJ,
};
export function main(argv: string[]): void {
let output = process.stdout;
let errors = process.stderr;
if (argv[2]) {
// load a file
let filename: string = argv[2];
const stream = fs.createReadStream(filename, { encoding: 'utf8' });
Start(stream, output, errors, true);
} else {
// run the REPL
let username = os.userInfo().username;
console.log(`Hello ${username}! This is the Monkey programming language!`);
console.log('Feel free to type in commands');
let input = process.stdin;
input.setEncoding('utf-8');
Start(input, output, errors, false);
}
}
// NodeJS runs a REPL or file loader
if (typeof process !== 'undefined' && typeof process.versions.node !== 'undefined') main(process.argv);