/
espresso.js
37 lines (27 loc) · 1.09 KB
/
espresso.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
require("./ometa/ometa");
var Espresso = Object.create({});
Espresso.parser = Object.create(require('./grammars/parser.ojs'));
Espresso.translator = Object.create(require('./grammars/translator.ojs'));
Espresso.parse = function (input, /* optional[fname, rule] */ opts) {
var opts = opts || {};
this.ast = this.parser.parse(input, opts.fname, opts.rule);
return this.ast;
};
Espresso.translate = function (ast) {
return this.translator.translate(ast);;
}
Espresso.compile = function (input, /* optional[fname, rule, skip_runtime] */ opts) {
var opts = opts || {}
// , source = this.parse(input, opts.fname, opts.rule);
, source = this.translate(this.parse(input, opts.fname, opts.rule));
if (typeof opts.skip_runtime === "undefined") {
source = require("fs").readFileSync(__dirname + "/runtime.js", 'utf8') + '\n\n' + source
}
return source
};
Espresso.compileFile = function (fname, /* optional[rule, skip_runtime] */ opts) {
var opts = opts || {};
opts.fname = fname;
return this.compile(require('fs').readFileSync(fname, 'utf8'), opts);
};
module.exports = Espresso;