diff --git a/README.md b/README.md index 3e2c7c7..62301ee 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,12 @@ or node main.js +###Flags + + -o= + -t= + -nb|--no-beautify + Result fill write in file. You can test it: diff --git a/main.js b/main.js index 375649a..ed11cd4 100644 --- a/main.js +++ b/main.js @@ -2,6 +2,8 @@ * Created by Aleksey Chichenkov on 1/23/19. */ var js_beautify = require("js-beautify"); +var args = require("args-parser")(process.argv); + var fs = require("fs"); var exec = require('child_process').exec; @@ -37,11 +39,21 @@ var post_process_lexer = function (_string) { _string = _string.replace(/yych/gm, "this._yy_char"); // replace yych to this._yy_char - _string = js_beautify(_string, {indent_size: 4, space_in_empty_paren: true}); + if(args["t"] !== undefined) { + switch (args["t"]) { + case "web": + _string = "(function(){\n" + _string + "return Lexer; \n})"; + break; + case "node": + _string += "\n module.exports = Lexer"; + break; + } + } - var output = "lexer.js"; - if(process.argv[2]){ - output = process.argv[2]; + var output = args["o"] || "lexer.js"; + + if( !(args["no-beautify"] || args["nb"]) ) { + _string = js_beautify(_string, {indent_size: 4, space_in_empty_paren: true}); } fs.writeFileSync(output, _string); diff --git a/package.json b/package.json index dd17001..6942e98 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", "version": "1.1.1" }, + "args-parser": "^1.1.0", "balanced-match": { "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", diff --git a/test.js b/test.js index c1cef56..4f2422c 100644 --- a/test.js +++ b/test.js @@ -4,7 +4,7 @@ var fs = require("fs"); var exec = require('child_process').exec; -exec("node main.js lexer_test.js", function(err, stdout, stderr) { +exec("node main.js -o=lexer_test.js -t=node", function(err, stdout, stderr) { err && console.log("ERROR: ", err); err && process.exit(1); @@ -24,7 +24,7 @@ var test = function() { (new Lexer("[")).search(); (new Lexer("]")).search(); (new Lexer("(")).search(); - (new Lexer(")").search()); + (new Lexer(")")).search(); (new Lexer(":")).search(); (new Lexer(",")).search(); (new Lexer(".")).search();