Permalink
Browse files

[lib] port to new coa and ometajs

  • Loading branch information...
indutny committed Nov 28, 2011
1 parent 605c021 commit 2eb3ae5c49c194dac33999c1c6b2d9cbc97b5ee7
Showing with 4,187 additions and 106 deletions.
  1. +10 −6 lib/cli.js
  2. +2,086 −49 lib/ometa-highlighter.js
  3. +3 −2 package.json
  4. +1,867 −41 src/ometa-highlighter.ometajs.js
  5. +120 −4 src/ometa-highlighter2bemjson.ometajs.js
  6. +101 −4 src/ometa-highlighter2html.ometajs.js
View
@@ -1,7 +1,7 @@
exports.main = function () {
- var sys = require('sys'),
- fs = require('fs');
+ var fs = require('fs'),
+ q = require('q');
require('coa').Cmd()
.name(process.argv[1])
@@ -74,6 +74,7 @@ exports.main = function () {
.flag()
.end()
.act(function(opts) {
+ var deferred = q.defer();
readStream(opts.input, function(err, input) {
if (err) throw err;
@@ -87,18 +88,20 @@ exports.main = function () {
result = (opts.format == 'html' ?
ohl.OmetaHighlighterToHtml.match(ast, 'topLevel') :
JSON.stringify(ohl.OmetaHighlighterToBemjson.match(ast, 'topLevel'), null, 4)) + '\n';
- opts.output.end(result);
+ opts.output.write(result);
+ if (opts.output !== process.stdout) opts.output.end();
} catch (e) {
e.errorPos != undefined &&
- sys.error(
+ console.error(
input.slice(0, e.errorPos) +
"\n--- Parse error ->" +
input.slice(e.errorPos) + '\n');
throw e;
}
+ deferred.resolve();
});
- opts.input.resume();
+ return deferred.promise;
})
.run();
};
@@ -114,5 +117,6 @@ function readStream(stream, callback) {
})
.on('end', function() {
callback(null, data);
- });
+ })
+ .resume();
}
Oops, something went wrong.

0 comments on commit 2eb3ae5

Please sign in to comment.