Split out compiler to separate syndicatec command
This commit is contained in:
parent
adaf9511bf
commit
3b5a07f954
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env node
|
||||
// -*- javascript -*-
|
||||
|
||||
var fs = require('fs');
|
||||
var compiler = require('../compiler/compiler.js');
|
||||
|
||||
function compileAndPrint(inputSource) {
|
||||
var translatedSource = compiler.compileSyndicateSource(inputSource);
|
||||
if (translatedSource) {
|
||||
console.log(translatedSource);
|
||||
}
|
||||
}
|
||||
|
||||
if (process.argv.length < 3 || process.argv[2] === '-') {
|
||||
var inputSource = '';
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding('utf8');
|
||||
process.stdin.on('data', function(buf) { inputSource += buf; });
|
||||
process.stdin.on('end', function() { compileAndPrint(inputSource); });
|
||||
} else {
|
||||
var inputSource = fs.readFileSync(process.argv[2]).toString();
|
||||
compileAndPrint(inputSource);
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
# Syndicate/js compiler
|
||||
|
||||
Translates ES5 + Syndicate extensions to plain ES5 using
|
||||
[Ohm](https://github.com/cdglabs/ohm#readme).
|
|
@ -316,27 +316,22 @@ semantics.addOperation('pushBindings(accumulator)', {
|
|||
}
|
||||
})
|
||||
|
||||
function compileExtendedSource(inputSource) {
|
||||
function compileSyndicateSource(inputSource, onError) {
|
||||
var parseResult = grammar.match(inputSource);
|
||||
if (parseResult.failed()) console.error(parseResult.message);
|
||||
return parseResult.succeeded() && semantics(parseResult).asES5;
|
||||
}
|
||||
|
||||
function compileAndPrint(inputSource) {
|
||||
var translatedSource = compileExtendedSource(inputSource);
|
||||
if (translatedSource) {
|
||||
console.log('"use strict";');
|
||||
console.log(translatedSource);
|
||||
}
|
||||
}
|
||||
|
||||
if (process.argv.length < 3 || process.argv[2] === '-') {
|
||||
var inputSource = '';
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding('utf8');
|
||||
process.stdin.on('data', function(buf) { inputSource += buf; });
|
||||
process.stdin.on('end', function() { compileAndPrint(inputSource); });
|
||||
if (parseResult.failed()) {
|
||||
if (onError) {
|
||||
return onError(parseResult.message, parseResult);
|
||||
} else {
|
||||
var inputSource = fs.readFileSync(process.argv[2]).toString();
|
||||
compileAndPrint(inputSource);
|
||||
console.error(parseResult.message);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return '"use strict";\n' + semantics(parseResult).asES5;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
module.exports.grammar = grammar;
|
||||
module.exports.semantics = semantics;
|
||||
module.exports.compileSyndicateSource = compileSyndicateSource;
|
|
@ -1,3 +1,4 @@
|
|||
// -*- javascript -*-
|
||||
// Syntactic extensions to ES5 for Syndicate/js. See compiler.js for
|
||||
// the rest of the translator.
|
||||
|
|
@ -8,11 +8,15 @@
|
|||
"type": "git",
|
||||
"url": "git://github.com/tonyg/syndicate"
|
||||
},
|
||||
"directories": {
|
||||
"bin": "./bin"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rm -f dist/*",
|
||||
"build-debug": "browserify src/main.js -d -s Syndicate -o dist/syndicate.js",
|
||||
"build-min": "browserify src/main.js -s Syndicate -o dist/_syndicate.js && uglifyjs dist/_syndicate.js -o dist/syndicate.min.js && rm dist/_syndicate.js",
|
||||
"build": "npm run build-debug && npm run build-min",
|
||||
"build-compiler": "browserify compiler/compiler.js -s SyndicateCompiler -o dist/_syndicatecompiler.js && uglifyjs dist/_syndicatecompiler.js -o dist/syndicatecompiler.min.js && rm dist/_syndicatecompiler.js",
|
||||
"build": "npm run build-debug && npm run build-min && npm run build-compiler",
|
||||
"watch": "watchify src/main.js -d -s Syndicate -o dist/syndicate.js",
|
||||
"test": "mocha",
|
||||
"prepublish": "npm run build"
|
||||
|
|
Loading…
Reference in New Issue