-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
67 lines (62 loc) · 2 KB
/
index.js
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
const path_applied = process.cwd(),
pathLib = require('path')
global.internalPaths = {
utils: './bin/utils.js',
ast_to_js: '../lib/compiler/ast_to_js.js',
text_to_ast: './text_to_ast.js',
compiler: '../lib/compiler/index.js',
built_in: './built_in.js',
built_in_from_utils: '../lib/compiler/built_in.js',
grammar: './lib/grammar',
bin: '../../bin/',
nearley: '../../nearley/lib/nearley.js',
nearleyCompile: "../../nearley/lib/compile.js",
nearleyGenerate: "../../nearley/lib/generate.js",
nearleyGrammar: "../../nearley/lib/nearley-language-bootstrapped.js",
};
global.baseUrl = {
path: path_applied.replace(/\\/g, '/'),
from_indexJS: true,
relative: '',
ext: '',
};
global.pathJS = function (pathString = '') {
let r = /\\/g;
return {
resolve: pathLib.resolve(pathString),
path: pathString.replace(r, '/'),
dir: pathLib.dirname(pathString).replace(r, '/'),
name: pathLib.basename(pathString).replace(r, '/'),
ext: pathLib.extname(pathString).replace(r, '/'),
filename: (function (str) {
return str.split('\\').join('/').split('/').pop();
})(pathString),
add(...args) {
return pathLib.join(pathString, ...args).replace(r, '/');
},
relative() {
return pathJS(baseUrl.path).add(baseUrl.relative);
},
full() {
return pathJS(baseUrl.path).add(baseUrl.relative, baseUrl.filename);
}
}
};
global.CLIArguments = [];
baseUrl.filename = '';
const utils = require("./bin/utils"),
fs = require('fs');
const BaseScript = {
compile: utils.fromString,
compileFile(path) {
return BaseScript.compile(fs.readFileSync(path, 'utf8'));
},
builtins() {
return fs.readFileSync('./lib/compiler/builtin/index.js', 'utf8');
},
run(path, args = []) {
let answer = utils.parse(path, '', '', false, true, null, args, true)
return answer;
}
};
module.exports = BaseScript;