add version

This commit is contained in:
Aleksey Chichenkov 2019-01-25 16:30:02 +03:00
parent 7abc0dbbc4
commit a5991c4e55
4 changed files with 25 additions and 6 deletions

View File

@ -15,6 +15,12 @@ or
node main.js node main.js
###Flags
-o=<output_path>
-t=<web|node>
-nb|--no-beautify
Result fill write in <lexer.js> file. Result fill write in <lexer.js> file.
You can test it: You can test it:

20
main.js
View File

@ -2,6 +2,8 @@
* Created by Aleksey Chichenkov <a.chichenkov@initi.ru> on 1/23/19. * Created by Aleksey Chichenkov <a.chichenkov@initi.ru> on 1/23/19.
*/ */
var js_beautify = require("js-beautify"); var js_beautify = require("js-beautify");
var args = require("args-parser")(process.argv);
var fs = require("fs"); var fs = require("fs");
var exec = require('child_process').exec; 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 = _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"; var output = args["o"] || "lexer.js";
if(process.argv[2]){
output = process.argv[2]; if( !(args["no-beautify"] || args["nb"]) ) {
_string = js_beautify(_string, {indent_size: 4, space_in_empty_paren: true});
} }
fs.writeFileSync(output, _string); fs.writeFileSync(output, _string);

View File

@ -23,6 +23,7 @@
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
"version": "1.1.1" "version": "1.1.1"
}, },
"args-parser": "^1.1.0",
"balanced-match": { "balanced-match": {
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",

View File

@ -4,7 +4,7 @@
var fs = require("fs"); var fs = require("fs");
var exec = require('child_process').exec; 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 && console.log("ERROR: ", err);
err && process.exit(1); 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();
(new Lexer(":")).search(); (new Lexer(":")).search();
(new Lexer(",")).search(); (new Lexer(",")).search();
(new Lexer(".")).search(); (new Lexer(".")).search();