diff --git a/README.md b/README.md index 0120c9a..3e2c7c7 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ node main.js Result fill write in file. +You can test it: +$ node test.js Report for bugs: rolahd@yandex.ru \ No newline at end of file diff --git a/lexer.l b/lexer.l index 2be311b..705608b 100644 --- a/lexer.l +++ b/lexer.l @@ -279,43 +279,4 @@ var print_f = function() { r_str += next; return r_str; -}; - -console.log("TEST SINGLE"); -(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(); -(new Lexer("AND")).search(); -(new Lexer("and")).search(); -(new Lexer("OR")).search(); -(new Lexer("or")).search(); -(new Lexer("NOT")).search(); -(new Lexer("not")).search(); -(new Lexer("LIKE")).search(); -(new Lexer("like")).search(); -(new Lexer("NLIKE")).search(); -(new Lexer("nlike")).search(); -(new Lexer("Address")).search(); -(new Lexer("Time")).search(); -(new Lexer("TimeDiff")).search(); - -var lex_test_all = new Lexer("[ ] ( ) : , . % > >= < <= == != AND and OR or NOT not LIKE like NLIKE nlike Address Time TimeDiff 'sdfadfasdf' \"asdfasfd\" ") -var _lex; -while(_lex = lex_test_all.next()){ - console.log("IN while:", _lex.lexeme); -} - -console.log("TEST STRING LITERAL"); -(new Lexer(' "111\\\"11\\\"1" "222222" ')).search(); -(new Lexer(" '111\\\'11\\\'1' '222222' ")).search(); \ No newline at end of file +}; \ No newline at end of file diff --git a/main.js b/main.js index 472b838..375649a 100644 --- a/main.js +++ b/main.js @@ -39,5 +39,10 @@ var post_process_lexer = function (_string) { _string = js_beautify(_string, {indent_size: 4, space_in_empty_paren: true}); - fs.writeFileSync("lexer.js", _string); + var output = "lexer.js"; + if(process.argv[2]){ + output = process.argv[2]; + } + + fs.writeFileSync(output, _string); }; \ No newline at end of file diff --git a/test.js b/test.js new file mode 100644 index 0000000..c1cef56 --- /dev/null +++ b/test.js @@ -0,0 +1,62 @@ +/** + * Created by Aleksey Chichenkov on 1/25/19. + */ +var fs = require("fs"); +var exec = require('child_process').exec; + +exec("node main.js lexer_test.js", function(err, stdout, stderr) { + err && console.log("ERROR: ", err); + err && process.exit(1); + + var file = fs.readFileSync("lexer_test.js", "utf8"); + file += "\n module.exports = Lexer"; + fs.writeFileSync("lexer_test.js", file); + + test(); + + fs.unlinkSync("lexer_test.js"); +}); + +var test = function() { + var Lexer = require("./lexer_test"); + + console.log("TEST SINGLE"); + (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(); + (new Lexer("AND")).search(); + (new Lexer("and")).search(); + (new Lexer("OR")).search(); + (new Lexer("or")).search(); + (new Lexer("NOT")).search(); + (new Lexer("not")).search(); + (new Lexer("LIKE")).search(); + (new Lexer("like")).search(); + (new Lexer("NLIKE")).search(); + (new Lexer("nlike")).search(); + (new Lexer("Address")).search(); + (new Lexer("Time")).search(); + (new Lexer("TimeDiff")).search(); + + var lex_test_all = new Lexer("[ ] ( ) : , . % > >= < <= == != AND and OR or NOT not LIKE like NLIKE nlike Address Time TimeDiff 'sdfadfasdf' \"asdfasfd\" ") + var _lex; + + console.log("start search"); + while (_lex = lex_test_all.next()); + + console.log("TEST STRING LITERAL"); + (new Lexer(' "111\\\"11\\\"1" "222222" ')).search(); + (new Lexer(" '111\\\'11\\\'1' '222222' ")).search(); + +}; \ No newline at end of file