diff --git a/config.template b/config.template new file mode 100644 index 0000000..c77f7da --- /dev/null +++ b/config.template @@ -0,0 +1,17 @@ +var config = { + lemon_bin: "./lemon-src/lemon-js", + out_path: "", + + /** + * В папке назначения должен лежать файл parser.y; + * Или другой файл парсера с именем .y + */ + file_name: "", + + /** + * Флаги для лемона, можно посмотреть в README.md + */ + flags: "-l", +}; + +module.exports = config; \ No newline at end of file diff --git a/main.js b/main.js index 08e1989..876ea6d 100644 --- a/main.js +++ b/main.js @@ -7,14 +7,29 @@ var args = require("args-parser")(process.argv); var fs = require("fs"); var exec = require('child_process').exec; -var program_path = "./lemon-src/lemon-js"; -var parser_path = "parsers/filters/"; -var file_name = "parser.y"; -var temp_file_name = "temp_parser.y"; +var config; +if(args["c"] !== undefined) { + config = require("./" + args["c"]); +} else { + config = require("./config.js"); +} + +var program_path = config.lemon_bin; +var lemon_flags = config.flags; +var parser_path = config.out_path; +var file_name = config.file_name; + +var fn_y = file_name + ".y"; +var fn_js = file_name + ".js"; +var fn_out = file_name + ".out"; + +var temp_fn_y = "temp_" + "file_name" + ".y"; +var temp_fn_js = "temp_" + "file_name" + ".js"; +var temp_fn_out = "temp_" + "file_name" + ".out"; var update_parser_y = function () { - var source_parser_y = fs.readFileSync(parser_path + file_name, "utf8"); + var source_parser_y = fs.readFileSync(parser_path + fn_y, "utf8"); var result = /&&.*?REPLACER\{(.*?)\}&&/gm.exec(source_parser_y); if(result) { @@ -23,31 +38,44 @@ var update_parser_y = function () { source_parser_y = source_parser_y.replace(/&&.*?REPLACER\{(.*?)\}&&/gm, process_code); - fs.writeFileSync(parser_path + temp_file_name, source_parser_y); + fs.writeFileSync(parser_path + temp_fn_y, source_parser_y); } }; var post_process_parser = function () { - var out_js = fs.readFileSync(parser_path + "temp_parser.js", "utf8"); - out_js = js_beautify(out_js, {indent_size: 4, space_in_empty_paren: true}); - fs.writeFileSync(parser_path + "parser.js", out_js); + var out_js = fs.readFileSync(parser_path + temp_fn_js, "utf8"); - var temp_parser_out = fs.readFileSync(parser_path + "temp_parser.out", "utf8"); - fs.writeFileSync(parser_path + "parser.out", temp_parser_out); + if(args["t"] !== undefined) { + switch (args["t"]) { + case "web": + out_js = "(function(){\n" + out_js + "return Lexer; \n})()"; + break; + case "node": + out_js += "\n\n module.exports = LemonJS;"; + break; + } + } + + out_js = js_beautify(out_js, {indent_size: 4, space_in_empty_paren: true}); + + fs.writeFileSync(parser_path + fn_js, out_js); + + var temp_parser_out = fs.readFileSync(parser_path + temp_fn_out, "utf8"); + fs.writeFileSync(parser_path + fn_out, temp_parser_out); }; var start = function () { update_parser_y(); - exec(program_path + " " + parser_path + temp_file_name + " -l", function(err, stdout, stderr) { + exec(program_path + " " + parser_path + temp_fn_y + " " + lemon_flags, function(err, stdout, stderr) { err && console.log("ERROR: ", err); err && process.exit(1); post_process_parser(); - fs.unlinkSync(parser_path + temp_file_name); - fs.unlinkSync(parser_path + "temp_parser.js"); - fs.unlinkSync(parser_path + "temp_parser.out"); + fs.unlinkSync(parser_path + temp_fn_y); + fs.unlinkSync(parser_path + temp_fn_js); + fs.unlinkSync(parser_path + temp_fn_out); }); }; diff --git a/parsers/filters/lexer.js b/parsers/filters/lexer.js index 9146977..790be74 100644 --- a/parsers/filters/lexer.js +++ b/parsers/filters/lexer.js @@ -1,5 +1,6 @@ -/* Generated by re2c 1.0.3 on Mon Jan 28 17:32:49 2019 */ +/* Generated by re2c 1.0.3 on Tue Jan 29 10:00:10 2019 */ var types = [ + "SLASH", "LSB", "RSB", "LCB", @@ -188,6 +189,9 @@ Lexer.prototype = { case '.': this._state = 20; break; + case '/': + this._state = 22; + break; case '0': case '1': case '2': @@ -198,22 +202,22 @@ Lexer.prototype = { case '7': case '8': case '9': - this._state = 22; + this._state = 24; break; case ':': - this._state = 25; - break; - case '<': this._state = 27; break; - case '=': + case '<': this._state = 29; break; + case '=': + this._state = 31; + break; case '>': - this._state = 30; + this._state = 32; break; case 'A': - this._state = 32; + this._state = 34; break; case 'B': case 'C': @@ -256,40 +260,40 @@ Lexer.prototype = { case 'x': case 'y': case 'z': - this._state = 34; + this._state = 36; break; case 'F': case 'f': - this._state = 36; + this._state = 38; break; case 'L': case 'l': - this._state = 37; + this._state = 39; break; case 'N': case 'n': - this._state = 38; - break; - case 'O': - this._state = 39; - break; - case 'T': this._state = 40; break; - case '[': + case 'O': this._state = 41; break; - case ']': + case 'T': + this._state = 42; + break; + case '[': this._state = 43; break; - case 'a': + case ']': this._state = 45; break; + case 'a': + this._state = 47; + break; case 'o': - this._state = 46; + this._state = 48; break; case 't': - this._state = 47; + this._state = 49; break; default: this._state = 4; @@ -319,7 +323,7 @@ Lexer.prototype = { (function() { switch (this._yy_char) { case '=': - this._state = 48; + this._state = 50; break; default: this._state = 5; @@ -362,7 +366,7 @@ Lexer.prototype = { (function() { switch (this._yy_char) { case '.': - this._state = 50; + this._state = 52; break; case '0': case '1': @@ -374,7 +378,7 @@ Lexer.prototype = { case '7': case '8': case '9': - this._state = 22; + this._state = 24; break; default: this._state = 5; @@ -396,7 +400,7 @@ Lexer.prototype = { case '7': case '8': case '9': - this._state = 52; + this._state = 54; break; default: this._state = 21; @@ -410,12 +414,18 @@ Lexer.prototype = { return; } case 22: + ++this._yy_cursor; { + this._foundLexeme("SLASH"); + this._set_next(); + return; + } + case 24: this._yy_accept = 1; this._yy_char = this._string[(this._yy_marker = ++this._yy_cursor)]; (function() { switch (this._yy_char) { case '.': - this._state = 50; + this._state = 52; break; case '0': case '1': @@ -427,43 +437,25 @@ Lexer.prototype = { case '7': case '8': case '9': - this._state = 22; + this._state = 24; break; default: - this._state = 24; + this._state = 26; break; } }.bind(this))(); break; - case 24: + case 26: { this._foundLexeme("INTEGER_LITERAL");this._set_next(); return; } - case 25: + case 27: ++this._yy_cursor; { this._foundLexeme("COLON"); this._set_next(); return; } - case 27: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case '=': - this._state = 55; - break; - default: - this._state = 28; - break; - } - }.bind(this))(); - break; - case 28: - { - this._foundLexeme("LT");this._set_next(); - return; - } case 29: this._yy_char = this._string[++this._yy_cursor]; (function() { @@ -472,12 +464,17 @@ Lexer.prototype = { this._state = 57; break; default: - this._state = 5; + this._state = 30; break; } }.bind(this))(); break; case 30: + { + this._foundLexeme("LT");this._set_next(); + return; + } + case 31: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { @@ -485,41 +482,54 @@ Lexer.prototype = { this._state = 59; break; default: - this._state = 31; + this._state = 5; break; } }.bind(this))(); break; - case 31: - { - this._foundLexeme("GT");this._set_next(); - return; - } case 32: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'N': - case 'n': + case '=': this._state = 61; break; - case 'd': - this._state = 62; - break; default: - this._state = 35; + this._state = 33; break; } }.bind(this))(); break; case 33: { - this._foundLexeme("ID");this._set_next(); + this._foundLexeme("GT");this._set_next(); return; } case 34: this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 'N': + case 'n': + this._state = 63; + break; + case 'd': + this._state = 64; + break; + default: + this._state = 37; + break; + } + }.bind(this))(); + break; case 35: + { + this._foundLexeme("ID");this._set_next(); + return; + } + case 36: + this._yy_char = this._string[++this._yy_cursor]; + case 37: (function() { switch (this._yy_char) { case '0': @@ -585,35 +595,7 @@ Lexer.prototype = { case 'x': case 'y': case 'z': - this._state = 34; - break; - default: - this._state = 33; - break; - } - }.bind(this))(); - break; - case 36: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'A': - case 'a': - this._state = 63; - break; - default: - this._state = 35; - break; - } - }.bind(this))(); - break; - case 37: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'I': - case 'i': - this._state = 64; + this._state = 36; break; default: this._state = 35; @@ -625,16 +607,12 @@ Lexer.prototype = { this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'L': - case 'l': + case 'A': + case 'a': this._state = 65; break; - case 'O': - case 'o': - this._state = 66; - break; default: - this._state = 35; + this._state = 37; break; } }.bind(this))(); @@ -643,15 +621,12 @@ Lexer.prototype = { this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'R': - case 'r': - this._state = 67; - break; + case 'I': case 'i': - this._state = 69; + this._state = 66; break; default: - this._state = 35; + this._state = 37; break; } }.bind(this))(); @@ -660,80 +635,115 @@ Lexer.prototype = { this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'R': - case 'r': - this._state = 70; + case 'L': + case 'l': + this._state = 67; break; - case 'i': - this._state = 71; + case 'O': + case 'o': + this._state = 68; break; default: - this._state = 35; + this._state = 37; break; } }.bind(this))(); break; case 41: + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 'R': + case 'r': + this._state = 69; + break; + case 'i': + this._state = 71; + break; + default: + this._state = 37; + break; + } + }.bind(this))(); + break; + case 42: + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 'R': + case 'r': + this._state = 72; + break; + case 'i': + this._state = 73; + break; + default: + this._state = 37; + break; + } + }.bind(this))(); + break; + case 43: ++this._yy_cursor; { this._foundLexeme("LSB"); this._set_next(); return; } - case 43: + case 45: ++this._yy_cursor; { this._foundLexeme("RSB"); this._set_next(); return; } - case 45: + case 47: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { case 'N': case 'n': - this._state = 61; + this._state = 63; break; default: - this._state = 35; - break; - } - }.bind(this))(); - break; - case 46: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'R': - case 'r': - this._state = 67; - break; - default: - this._state = 35; - break; - } - }.bind(this))(); - break; - case 47: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'R': - case 'r': - this._state = 70; - break; - default: - this._state = 35; + this._state = 37; break; } }.bind(this))(); break; case 48: + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 'R': + case 'r': + this._state = 69; + break; + default: + this._state = 37; + break; + } + }.bind(this))(); + break; + case 49: + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 'R': + case 'r': + this._state = 72; + break; + default: + this._state = 37; + break; + } + }.bind(this))(); + break; + case 50: ++this._yy_cursor; { this._foundLexeme("NEQ"); this._set_next(); return; } - case 50: + case 52: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { @@ -747,28 +757,28 @@ Lexer.prototype = { case '7': case '8': case '9': - this._state = 52; + this._state = 54; break; default: - this._state = 51; + this._state = 53; break; } }.bind(this))(); break; - case 51: + case 53: this._yy_cursor = this._yy_marker; switch (this._yy_accept) { case 0: this._state = 5; break; case 1: - this._state = 24; + this._state = 26; break; default: - this._state = 54; + this._state = 56; break; } - case 52: + case 54: this._yy_accept = 2; this._yy_char = this._string[(this._yy_marker = ++this._yy_cursor)]; (function() { @@ -783,77 +793,50 @@ Lexer.prototype = { case '7': case '8': case '9': - this._state = 52; + this._state = 54; break; case 'e': - this._state = 72; + this._state = 74; break; default: - this._state = 54; + this._state = 56; break; } }.bind(this))(); break; - case 54: + case 56: { this._foundLexeme("FLOAT_LITERAL");this._set_next(); return; } - case 55: + case 57: ++this._yy_cursor; { this._foundLexeme("LTE"); this._set_next(); return; } - case 57: + case 59: ++this._yy_cursor; { this._foundLexeme("EQ"); this._set_next(); return; } - case 59: + case 61: ++this._yy_cursor; { this._foundLexeme("GTE"); this._set_next(); return; } - case 61: + case 63: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { case 'D': - case 'd': - this._state = 73; - break; - default: - this._state = 35; - break; - } - }.bind(this))(); - break; - case 62: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { case 'd': this._state = 75; break; default: - this._state = 35; - break; - } - }.bind(this))(); - break; - case 63: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'L': - case 'l': - this._state = 76; - break; - default: - this._state = 35; + this._state = 37; break; } }.bind(this))(); @@ -862,12 +845,11 @@ Lexer.prototype = { this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'K': - case 'k': + case 'd': this._state = 77; break; default: - this._state = 35; + this._state = 37; break; } }.bind(this))(); @@ -876,12 +858,12 @@ Lexer.prototype = { this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'I': - case 'i': + case 'L': + case 'l': this._state = 78; break; default: - this._state = 35; + this._state = 37; break; } }.bind(this))(); @@ -890,17 +872,45 @@ Lexer.prototype = { this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'T': - case 't': + case 'K': + case 'k': this._state = 79; break; default: - this._state = 35; + this._state = 37; break; } }.bind(this))(); break; case 67: + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 'I': + case 'i': + this._state = 80; + break; + default: + this._state = 37; + break; + } + }.bind(this))(); + break; + case 68: + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 'T': + case 't': + this._state = 81; + break; + default: + this._state = 37; + break; + } + }.bind(this))(); + break; + case 69: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { @@ -967,55 +977,28 @@ Lexer.prototype = { case 'x': case 'y': case 'z': - this._state = 34; + this._state = 36; break; default: - this._state = 68; - break; - } - }.bind(this))(); - break; - case 68: - { - this._foundLexeme("OR");this._set_next(); - return; - } - case 69: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'd': - this._state = 81; - break; - default: - this._state = 35; + this._state = 70; break; } }.bind(this))(); break; case 70: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'U': - case 'u': - this._state = 83; - break; - default: - this._state = 35; - break; - } - }.bind(this))(); - break; + { + this._foundLexeme("OR");this._set_next(); + return; + } case 71: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'm': - this._state = 84; + case 'd': + this._state = 83; break; default: - this._state = 35; + this._state = 37; break; } }.bind(this))(); @@ -1024,28 +1007,55 @@ Lexer.prototype = { this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case '-': + case 'U': + case 'u': this._state = 85; break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - this._state = 86; - break; default: - this._state = 51; + this._state = 37; break; } }.bind(this))(); break; case 73: + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 'm': + this._state = 86; + break; + default: + this._state = 37; + break; + } + }.bind(this))(); + break; + case 74: + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case '-': + this._state = 87; + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + this._state = 88; + break; + default: + this._state = 53; + break; + } + }.bind(this))(); + break; + case 75: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { @@ -1112,56 +1122,28 @@ Lexer.prototype = { case 'x': case 'y': case 'z': - this._state = 34; + this._state = 36; break; default: - this._state = 74; - break; - } - }.bind(this))(); - break; - case 74: - { - this._foundLexeme("AND");this._set_next(); - return; - } - case 75: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'r': - this._state = 88; - break; - default: - this._state = 35; + this._state = 76; break; } }.bind(this))(); break; case 76: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'S': - case 's': - this._state = 83; - break; - default: - this._state = 35; - break; - } - }.bind(this))(); - break; + { + this._foundLexeme("AND");this._set_next(); + return; + } case 77: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'E': - case 'e': - this._state = 89; + case 'r': + this._state = 90; break; default: - this._state = 35; + this._state = 37; break; } }.bind(this))(); @@ -1170,12 +1152,12 @@ Lexer.prototype = { this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'K': - case 'k': - this._state = 91; + case 'S': + case 's': + this._state = 85; break; default: - this._state = 35; + this._state = 37; break; } }.bind(this))(); @@ -1184,82 +1166,30 @@ Lexer.prototype = { this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': - this._state = 34; + this._state = 91; break; default: - this._state = 80; + this._state = 37; break; } }.bind(this))(); break; case 80: - { - this._foundLexeme("NOT");this._set_next(); - return; - } + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 'K': + case 'k': + this._state = 93; + break; + default: + this._state = 37; + break; + } + }.bind(this))(); + break; case 81: this._yy_char = this._string[++this._yy_cursor]; (function() { @@ -1327,7 +1257,7 @@ Lexer.prototype = { case 'x': case 'y': case 'z': - this._state = 34; + this._state = 36; break; default: this._state = 82; @@ -1337,37 +1267,10 @@ Lexer.prototype = { break; case 82: { - this._foundLexeme("OID");this._set_next(); + this._foundLexeme("NOT");this._set_next(); return; } case 83: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'E': - case 'e': - this._state = 92; - break; - default: - this._state = 35; - break; - } - }.bind(this))(); - break; - case 84: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'e': - this._state = 94; - break; - default: - this._state = 35; - break; - } - }.bind(this))(); - break; - case 85: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { @@ -1381,15 +1284,100 @@ Lexer.prototype = { case '7': case '8': case '9': - this._state = 86; + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': + this._state = 36; break; default: - this._state = 51; + this._state = 84; + break; + } + }.bind(this))(); + break; + case 84: + { + this._foundLexeme("OID");this._set_next(); + return; + } + case 85: + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 'E': + case 'e': + this._state = 94; + break; + default: + this._state = 37; break; } }.bind(this))(); break; case 86: + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 'e': + this._state = 96; + break; + default: + this._state = 37; + break; + } + }.bind(this))(); + break; + case 87: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { @@ -1403,28 +1391,15 @@ Lexer.prototype = { case '7': case '8': case '9': - this._state = 86; + this._state = 88; break; default: - this._state = 54; + this._state = 53; break; } }.bind(this))(); break; case 88: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'e': - this._state = 96; - break; - default: - this._state = 35; - break; - } - }.bind(this))(); - break; - case 89: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { @@ -1438,87 +1413,28 @@ Lexer.prototype = { case '7': case '8': case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': - this._state = 34; + this._state = 88; break; default: - this._state = 90; + this._state = 56; break; } }.bind(this))(); break; case 90: - { - this._foundLexeme("LIKE");this._set_next(); - return; - } - case 91: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'E': case 'e': - this._state = 97; + this._state = 98; break; default: - this._state = 35; + this._state = 37; break; } }.bind(this))(); break; - case 92: + case 91: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { @@ -1585,19 +1501,33 @@ Lexer.prototype = { case 'x': case 'y': case 'z': - this._state = 34; + this._state = 36; break; default: - this._state = 93; + this._state = 92; break; } }.bind(this))(); break; - case 93: + case 92: { - this._foundLexeme("BOOL_LITERAL");this._set_next(); + this._foundLexeme("LIKE");this._set_next(); return; } + case 93: + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 'E': + case 'e': + this._state = 99; + break; + default: + this._state = 37; + break; + } + }.bind(this))(); + break; case 94: this._yy_char = this._string[++this._yy_cursor]; (function() { @@ -1615,6 +1545,7 @@ Lexer.prototype = { case 'A': case 'B': case 'C': + case 'D': case 'E': case 'F': case 'G': @@ -1664,10 +1595,7 @@ Lexer.prototype = { case 'x': case 'y': case 'z': - this._state = 34; - break; - case 'D': - this._state = 99; + this._state = 36; break; default: this._state = 95; @@ -1677,23 +1605,105 @@ Lexer.prototype = { break; case 95: { - this._foundLexeme("TIME");this._set_next(); + this._foundLexeme("BOOL_LITERAL");this._set_next(); return; } case 96: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': case 's': - this._state = 100; + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': + this._state = 36; + break; + case 'D': + this._state = 101; break; default: - this._state = 35; + this._state = 97; break; } }.bind(this))(); break; case 97: + { + this._foundLexeme("TIME");this._set_next(); + return; + } + case 98: + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 's': + this._state = 102; + break; + default: + this._state = 37; + break; + } + }.bind(this))(); + break; + case 99: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { @@ -1760,54 +1770,28 @@ Lexer.prototype = { case 'x': case 'y': case 'z': - this._state = 34; + this._state = 36; break; default: - this._state = 98; - break; - } - }.bind(this))(); - break; - case 98: - { - this._foundLexeme("NLIKE");this._set_next(); - return; - } - case 99: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'i': - this._state = 101; - break; - default: - this._state = 35; + this._state = 100; break; } }.bind(this))(); break; case 100: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 's': - this._state = 102; - break; - default: - this._state = 35; - break; - } - }.bind(this))(); - break; + { + this._foundLexeme("NLIKE");this._set_next(); + return; + } case 101: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'f': - this._state = 104; + case 'i': + this._state = 103; break; default: - this._state = 35; + this._state = 37; break; } }.bind(this))(); @@ -1816,96 +1800,29 @@ Lexer.prototype = { this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': - this._state = 34; + this._state = 104; break; default: - this._state = 103; + this._state = 37; break; } }.bind(this))(); break; case 103: - { - this._foundLexeme("ADDRESS");this._set_next(); - return; - } - case 104: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { case 'f': - this._state = 105; + this._state = 106; break; default: - this._state = 35; + this._state = 37; break; } }.bind(this))(); break; - case 105: + case 104: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { @@ -1972,15 +1889,108 @@ Lexer.prototype = { case 'x': case 'y': case 'z': - this._state = 34; + this._state = 36; break; default: - this._state = 106; + this._state = 105; break; } }.bind(this))(); break; + case 105: + { + this._foundLexeme("ADDRESS");this._set_next(); + return; + } case 106: + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 'f': + this._state = 107; + break; + default: + this._state = 37; + break; + } + }.bind(this))(); + break; + case 107: + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': + this._state = 36; + break; + default: + this._state = 108; + break; + } + }.bind(this))(); + break; + case 108: { this._foundLexeme("TIMEDIFF");this._set_next(); return; diff --git a/parsers/filters/parser.js b/parsers/filters/parser.js deleted file mode 100644 index dc1201c..0000000 --- a/parsers/filters/parser.js +++ /dev/null @@ -1,2355 +0,0 @@ -/* - ** 2000-05-29 - ** - ** The author disclaims copyright to this source code. In place of - ** a legal notice, here is a blessing: - ** - ** May you do good and not evil. - ** May you find forgiveness for yourself and forgive others. - ** May you share freely, never taking more than you give. - ** - ** Based on SQLite distribution v3.17.0 - ** Adopted for JavaScript by Artem Butusov - ** - ************************************************************************* - ** Driver template for the LEMON parser generator. - ** - ** The "lemon" program processes an LALR(1) input grammar file, then uses - ** this template to construct a parser. The "lemon" program inserts text - ** at each "%%" line. Also, any "P-a-r-s-e" identifer prefix (without the - ** interstitial "-" characters) contained in this template is changed into - ** the value of the %name directive from the grammar. Otherwise, the content - ** of this template is copied straight through into the generate parser - ** source file. - ** - ** The following is the concatenation of all %include directives from the - ** input grammar file: - */ -/************ Begin %include sections from the grammar ************************/ - -// include something -/**************** End of %include directives **********************************/ -function Parser() { - /* These constants specify the various numeric values for terminal symbols - ** in a format understandable to "makeheaders". - ***************** Begin makeheaders token definitions *************************/ - this.TOKEN_OR = 1; - this.TOKEN_AND = 2; - this.TOKEN_NOT = 3; - this.TOKEN_INTEGER_LITERAL = 4; - this.TOKEN_FLOAT_LITERAL = 5; - this.TOKEN_BOOL_LITERAL = 6; - this.TOKEN_STRING_LITERAL = 7; - this.TOKEN_ID = 8; - this.TOKEN_EQ = 9; - this.TOKEN_NEQ = 10; - this.TOKEN_GT = 11; - this.TOKEN_GTE = 12; - this.TOKEN_LT = 13; - this.TOKEN_LTE = 14; - this.TOKEN_LIKE = 15; - this.TOKEN_NLIKE = 16; - this.TOKEN_LCB = 17; - this.TOKEN_RCB = 18; - this.TOKEN_COMMA = 19; - this.TOKEN_ADDRESS = 20; - this.TOKEN_LSB = 21; - this.TOKEN_RSB = 22; - this.TOKEN_DOT = 23; - this.TOKEN_OID = 24; - this.TOKEN_TIMEDIFF = 25; - this.TOKEN_COLON = 26; - /**************** End makeheaders token definitions ***************************/ - - /* The next sections is a series of control #defines. - ** various aspects of the generated parser. - ** YYNOCODE is a number of type YYCODETYPE that is not used for - ** any terminal or nonterminal symbol. - ** YYFALLBACK If defined, this indicates that one or more tokens - ** (also known as: "terminal symbols") have fall-back - ** values which should be used if the original symbol - ** would not parse. This permits keywords to sometimes - ** be used as identifiers, for example. - ** YYSTACKDEPTH is the maximum depth of the parser's stack. If - ** zero the stack is dynamically sized using realloc() - ** YYERRORSYMBOL is the code number of the error symbol. If not - ** defined, then do no error processing. - ** YYNSTATE the combined number of states. - ** YYNRULE the number of rules in the grammar - ** YY_MAX_SHIFT Maximum value for shift actions - ** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions - ** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions - ** YY_MIN_REDUCE Maximum value for reduce actions - ** YY_ERROR_ACTION The yy_action[] code for syntax error - ** YY_ACCEPT_ACTION The yy_action[] code for accept - ** YY_NO_ACTION The yy_action[] code for no-op - */ - /************* Begin control #defines *****************************************/ - this.YYNOCODE = 55; - this.YYSTACKDEPTH = 100; - this.YYFALLBACK = false; - this.YYNSTATE = 38; - this.YYNRULE = 49; - this.YY_MAX_SHIFT = 37; - this.YY_MIN_SHIFTREDUCE = 80; - this.YY_MAX_SHIFTREDUCE = 128; - this.YY_MIN_REDUCE = 129; - this.YY_MAX_REDUCE = 177; - this.YY_ERROR_ACTION = 178; - this.YY_ACCEPT_ACTION = 179; - this.YY_NO_ACTION = 180; - /************* End control #defines *******************************************/ - - /* Define the yytestcase() macro to be a no-op if is not already defined - ** otherwise. - ** - ** Applications can choose to define yytestcase() in the %include section - ** to a macro that can assist in verifying code coverage. For production - ** code the yytestcase() macro should be turned off. But it is useful - ** for testing. - */ - if (!this.yytestcase) { - this.yytestcase = function() {}; - } - - - /* Next are the tables used to determine what action to take based on the - ** current state and lookahead token. These tables are used to implement - ** functions that take a state number and lookahead value and return an - ** action integer. - ** - ** Suppose the action integer is N. Then the action is determined as - ** follows - ** - ** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead - ** token onto the stack and goto state N. - ** - ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then - ** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE. - ** - ** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE - ** and YY_MAX_REDUCE - ** - ** N == YY_ERROR_ACTION A syntax error has occurred. - ** - ** N == YY_ACCEPT_ACTION The parser accepts its input. - ** - ** N == YY_NO_ACTION No such action. Denotes unused - ** slots in the yy_action[] table. - ** - ** The action table is constructed as a single large table named yy_action[]. - ** Given state S and lookahead X, the action is computed as either: - ** - ** (A) N = yy_action[ yy_shift_ofst[S] + X ] - ** (B) N = yy_default[S] - ** - ** The (A) formula is preferred. The B formula is used instead if: - ** (1) The yy_shift_ofst[S]+X value is out of range, or - ** (2) yy_lookahead[yy_shift_ofst[S]+X] is not equal to X, or - ** (3) yy_shift_ofst[S] equal YY_SHIFT_USE_DFLT. - ** (Implementation note: YY_SHIFT_USE_DFLT is chosen so that - ** YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X. - ** Hence only tests (1) and (2) need to be evaluated.) - ** - ** The formulas above are for computing the action when the lookahead is - ** a terminal symbol. If the lookahead is a non-terminal (as occurs after - ** a reduce action) then the yy_reduce_ofst[] array is used in place of - ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of - ** YY_SHIFT_USE_DFLT. - ** - ** The following are the tables generated in this section: - ** - ** yy_action[] A single table containing all actions. - ** yy_lookahead[] A table containing the lookahead for each entry in - ** yy_action. Used to detect hash collisions. - ** yy_shift_ofst[] For each state, the offset into yy_action for - ** shifting terminals. - ** yy_reduce_ofst[] For each state, the offset into yy_action for - ** shifting non-terminals after a reduce. - ** yy_default[] Default action for each state. - ** - *********** Begin parsing tables **********************************************/ - this.yy_action = [ - /* 0 */ - 179, 24, 26, 83, 85, 87, 25, 22, 103, 104, - /* 10 */ - 105, 106, 107, 108, 109, 110, 111, 112, 113, 88, - /* 20 */ - 91, 120, 23, 88, 126, 128, 82, 90, 22, 103, - /* 30 */ - 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, - /* 40 */ - 94, 90, 122, 90, 121, 90, 22, 103, 104, 105, - /* 50 */ - 106, 107, 108, 109, 110, 111, 112, 113, 37, 32, - /* 60 */ - 31, 3, 4, 90, 22, 103, 104, 105, 106, 107, - /* 70 */ - 108, 109, 110, 111, 112, 113, 92, 27, 114, 16, - /* 80 */ - 28, 90, 22, 103, 104, 105, 106, 107, 108, 109, - /* 90 */ - 110, 111, 112, 113, 2, 82, 84, 86, 88, 91, - /* 100 */ - 102, 83, 85, 87, 89, 29, 19, 115, 1, 138, - /* 110 */ - 116, 36, 129, 3, 4, 33, 30, 130, 127, 120, - /* 120 */ - 35, 34, 126, 128, 101, 83, 85, 87, 89, 100, - /* 130 */ - 83, 85, 87, 89, 99, 83, 85, 87, 89, 17, - /* 140 */ - 2, 18, 20, 120, 88, 91, 126, 128, 120, 125, - /* 150 */ - 13, 126, 128, 120, 1, 15, 126, 128, 98, 83, - /* 160 */ - 85, 87, 89, 97, 83, 85, 87, 89, 96, 83, - /* 170 */ - 85, 87, 89, 119, 21, 14, 4, 120, 131, 131, - /* 180 */ - 126, 128, 120, 131, 131, 126, 128, 120, 131, 131, - /* 190 */ - 126, 128, 95, 83, 85, 87, 89, 12, 11, 10, - /* 200 */ - 9, 8, 7, 6, 5, 82, 84, 86, 88, 131, - /* 210 */ - 131, 120, 131, 131, 126, 128, 131, 131, 131, 131, - /* 220 */ - 131, 36, 131, 131, 131, 33, 30, - ]; - this.yy_lookahead = [ - /* 0 */ - 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, - /* 10 */ - 38, 39, 40, 41, 42, 43, 44, 45, 46, 7, - /* 20 */ - 8, 49, 29, 7, 52, 53, 4, 34, 35, 36, - /* 30 */ - 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, - /* 40 */ - 29, 34, 35, 34, 35, 34, 35, 36, 37, 38, - /* 50 */ - 39, 40, 41, 42, 43, 44, 45, 46, 29, 50, - /* 60 */ - 51, 1, 2, 34, 35, 36, 37, 38, 39, 40, - /* 70 */ - 41, 42, 43, 44, 45, 46, 29, 31, 18, 31, - /* 80 */ - 31, 34, 35, 36, 37, 38, 39, 40, 41, 42, - /* 90 */ - 43, 44, 45, 46, 3, 4, 5, 6, 7, 8, - /* 100 */ - 30, 31, 32, 33, 34, 31, 31, 34, 17, 0, - /* 110 */ - 34, 20, 0, 1, 2, 24, 25, 0, 22, 49, - /* 120 */ - 47, 48, 52, 53, 30, 31, 32, 33, 34, 30, - /* 130 */ - 31, 32, 33, 34, 30, 31, 32, 33, 34, 26, - /* 140 */ - 3, 26, 21, 49, 7, 8, 52, 53, 49, 22, - /* 150 */ - 21, 52, 53, 49, 17, 23, 52, 53, 30, 31, - /* 160 */ - 32, 33, 34, 30, 31, 32, 33, 34, 30, 31, - /* 170 */ - 32, 33, 34, 22, 19, 21, 2, 49, 54, 54, - /* 180 */ - 52, 53, 49, 54, 54, 52, 53, 49, 54, 54, - /* 190 */ - 52, 53, 30, 31, 32, 33, 34, 9, 10, 11, - /* 200 */ - 12, 13, 14, 15, 16, 4, 5, 6, 7, 54, - /* 210 */ - 54, 49, 54, 54, 52, 53, 54, 54, 54, 54, - /* 220 */ - 54, 20, 54, 54, 54, 24, 25, - ]; - this.YY_SHIFT_USE_DFLT = 227; - this.YY_SHIFT_COUNT = 37; - this.YY_SHIFT_MIN = 0; - this.YY_SHIFT_MAX = 201; - this.yy_shift_ofst = [ - /* 0 */ - 91, 137, 137, 137, 137, 201, 201, 201, 201, 201, - /* 10 */ - 201, 201, 201, 12, 16, 12, 22, 22, 22, 22, - /* 20 */ - 22, 16, 188, 60, 112, 109, 117, 96, 113, 115, - /* 30 */ - 121, 127, 132, 129, 151, 155, 154, 174, - ]; - this.YY_REDUCE_USE_DFLT = -29; - this.YY_REDUCE_COUNT = 21; - this.YY_REDUCE_MIN = -28; - this.YY_REDUCE_MAX = 162; - this.yy_reduce_ofst = [ - /* 0 */ - -28, -7, 11, 29, 47, 70, 94, 99, 104, 128, - /* 10 */ - 133, 138, 162, 9, 73, 7, 46, 48, 49, 74, - /* 20 */ - 75, 76, - ]; - this.yy_default = [ - /* 0 */ - 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, - /* 10 */ - 178, 178, 178, 173, 167, 178, 178, 178, 178, 178, - /* 20 */ - 178, 178, 178, 178, 178, 139, 178, 178, 178, 178, - /* 30 */ - 178, 178, 172, 178, 178, 166, 178, 142, - ]; - /********** End of lemon-generated parsing tables *****************************/ - - /* The next table maps tokens (terminal symbols) into fallback tokens. - ** If a construct like the following: - ** - ** %fallback ID X Y Z. - ** - ** appears in the grammar, then ID becomes a fallback token for X, Y, - ** and Z. Whenever one of the tokens X, Y, or Z is input to the parser - ** but it does not parse, the type of the token is changed to ID and - ** the parse is retried before an error is thrown. - ** - ** This feature can be used, for example, to cause some keywords in a language - ** to revert to identifiers if they keyword does not apply in the context where - ** it appears. - */ - this.yyFallback = []; - - /* The following structure represents a single element of the - ** parser's stack. Information stored includes: - ** - ** + The state number for the parser at this level of the stack. - ** - ** + The value of the token stored at this level of the stack. - ** (In other words, the "major" token.) - ** - ** + The semantic value stored at this level of the stack. This is - ** the information used by the action routines in the grammar. - ** It is sometimes called the "minor" token. - ** - ** After the "shift" half of a SHIFTREDUCE action, the stateno field - ** actually contains the reduce action for the second half of the - ** SHIFTREDUCE. - */ - //{ - // stateno, /* The state-number, or reduce action in SHIFTREDUCE */ - // major, /* The major token value. This is the code - // ** number for the token at this stack level */ - // minor, /* The user-supplied minor token value. This - // ** is the value of the token */ - //} - - /* The state of the parser is completely contained in an instance of - ** the following structure */ - this.yyhwm = 0; /* High-water mark of the stack */ - this.yyerrcnt = -1; /* Shifts left before out of the error */ - this.yystack = null; /* The parser's stack */ - this.yyidx = -1; /* Stack index of current element in the stack */ - - this.yyTraceCallback = null; - this.yyTracePrompt = ""; - - /* - ** Turn parser tracing on by giving a stream to which to write the trace - ** and a prompt to preface each trace message. Tracing is turned off - ** by making either argument NULL - ** - ** Inputs: - ** - ** - ** Outputs: - ** None. - */ - this.setTraceCallback = function(callback, prompt) { - this.yyTraceCallback = callback; - this.yyTracePrompt = prompt || ""; - } - - this.trace = function(message) { - this.yyTraceCallback(this.yyTracePrompt + message + "\n"); - } - - /* For tracing shifts, the names of all terminals and nonterminals - ** are required. The following table supplies these names */ - this.yyTokenName = [ - "$", "OR", "AND", "NOT", - "INTEGER_LITERAL", "FLOAT_LITERAL", "BOOL_LITERAL", "STRING_LITERAL", - "ID", "EQ", "NEQ", "GT", - "GTE", "LT", "LTE", "LIKE", - "NLIKE", "LCB", "RCB", "COMMA", - "ADDRESS", "LSB", "RSB", "DOT", - "OID", "TIMEDIFF", "COLON", "error", - "main", "expr", "literal", "integer_literal", - "float_literal", "bool_literal", "string_literal", "id", - "and", "or", "not", "eq", - "neq", "gt", "gte", "lt", - "lte", "like", "nlike", "address_literal_content", - "address_literal_content_or_empty", "address_literal", "oid_literal_content", "oid_literal_content_or_empty", - "oid_literal", "time_diff_literal", - ]; - - /* For tracing reduce actions, the names of all rules are required. - */ - this.yyRuleName = [ - /* 0 */ - "main ::= expr", - /* 1 */ - "main ::= literal", - /* 2 */ - "integer_literal ::= INTEGER_LITERAL", - /* 3 */ - "literal ::= integer_literal", - /* 4 */ - "float_literal ::= FLOAT_LITERAL", - /* 5 */ - "literal ::= float_literal", - /* 6 */ - "bool_literal ::= BOOL_LITERAL", - /* 7 */ - "literal ::= bool_literal", - /* 8 */ - "string_literal ::= STRING_LITERAL", - /* 9 */ - "literal ::= string_literal", - /* 10 */ - "id ::= string_literal", - /* 11 */ - "id ::= ID", - /* 12 */ - "and ::= expr AND expr", - /* 13 */ - "or ::= expr OR expr", - /* 14 */ - "not ::= NOT expr", - /* 15 */ - "eq ::= id EQ literal", - /* 16 */ - "neq ::= id NEQ literal", - /* 17 */ - "gt ::= id GT literal", - /* 18 */ - "gte ::= id GTE literal", - /* 19 */ - "lt ::= id LT literal", - /* 20 */ - "lte ::= id LTE literal", - /* 21 */ - "like ::= id LIKE literal", - /* 22 */ - "nlike ::= id NLIKE literal", - /* 23 */ - "expr ::= and", - /* 24 */ - "expr ::= or", - /* 25 */ - "expr ::= not", - /* 26 */ - "expr ::= eq", - /* 27 */ - "expr ::= neq", - /* 28 */ - "expr ::= gt", - /* 29 */ - "expr ::= gte", - /* 30 */ - "expr ::= lt", - /* 31 */ - "expr ::= lte", - /* 32 */ - "expr ::= like", - /* 33 */ - "expr ::= nlike", - /* 34 */ - "expr ::= LCB expr RCB", - /* 35 */ - "address_literal_content ::= string_literal", - /* 36 */ - "address_literal_content ::= address_literal_content COMMA string_literal", - /* 37 */ - "address_literal_content_or_empty ::= address_literal_content", - /* 38 */ - "address_literal_content_or_empty ::=", - /* 39 */ - "address_literal ::= ADDRESS LSB address_literal_content_or_empty RSB", - /* 40 */ - "literal ::= address_literal", - /* 41 */ - "oid_literal_content ::= id", - /* 42 */ - "oid_literal_content ::= oid_literal_content DOT id", - /* 43 */ - "oid_literal_content_or_empty ::= oid_literal_content", - /* 44 */ - "oid_literal_content_or_empty ::=", - /* 45 */ - "oid_literal ::= OID LSB oid_literal_content_or_empty RSB", - /* 46 */ - "literal ::= oid_literal", - /* 47 */ - "time_diff_literal ::= TIMEDIFF LSB integer_literal integer_literal COLON integer_literal COLON integer_literal integer_literal RSB", - /* 48 */ - "literal ::= time_diff_literal", - ]; - /* - ** Try to increase the size of the parser stack. Return the number - ** of errors. Return 0 on success. - */ - this.yyGrowStack = function() { - // fix me: yystksz*2 + 100 - this.yystack.push({ - stateno: undefined, - major: undefined, - minor: undefined - }); - } - - /* Initialize a new parser that has already been allocated. - */ - this.init = function() { - this.yyhwm = 0; - this.yyerrcnt = -1; - this.yyidx = 0; - if (this.YYSTACKDEPTH <= 0) { - this.yystack = []; - this.yyGrowStack(); - } else { - this.yystack = new Array(this.YYSTACKDEPTH); - for (var i = 0; i < this.YYSTACKDEPTH; i++) { - this.yystack[i] = { - stateno: undefined, - major: undefined, - minor: undefined - }; - } - } - var yytos = this.yystack[0]; - yytos.stateno = 0; - yytos.major = 0; - } - - /* The following function deletes the "minor type" or semantic value - ** associated with a symbol. The symbol can be either a terminal - ** or nonterminal. "yymajor" is the symbol code, and "yypminor" is - ** a pointer to the value to be deleted. The code used to do the - ** deletions is derived from the %destructor and/or %token_destructor - ** directives of the input grammar. - */ - this.yy_destructor = function( - yymajor, /* Type code for object to destroy */ - yyminor /* The object to be destroyed */ - ) { - switch (yymajor) { - /* Here is inserted the actions which take place when a - ** terminal or non-terminal is destroyed. This can happen - ** when the symbol is popped from the stack during a - ** reduce or during error processing or when a parser is - ** being destroyed before it is finished parsing. - ** - ** Note: during a reduce, the only symbols destroyed are those - ** which appear on the RHS of the rule, but which are *not* used - ** inside the C code. - */ - /********* Begin destructor definitions ***************************************/ - /********* End destructor definitions *****************************************/ - default: - break; /* If no destructor action specified: do nothing */ - } - } - - /* - ** Pop the parser's stack once. - ** - ** If there is a destructor routine associated with the token which - ** is popped from the stack, then call it. - */ - this.yy_pop_parser_stack = function() { - // assert( pParser->yytos!=0 ); - // assert( pParser->yytos > pParser->yystack ); - var yytos = this.yystack[this.yyidx]; - - if (this.yyTraceCallback) { - this.trace("Popping " + this.yyTokenName[yytos.major]); - } - this.yy_destructor(yytos.major, yytos.minor); - - this.yyidx--; - } - - /* - ** Clear all secondary memory allocations from the parser - */ - this.finalize = function() { - while (this.yyidx > 0) { - this.yy_pop_parser_stack(); - } - this.yystack = null; - } - - /* - ** Return the peak depth of the stack for a parser. - */ - this.getStackPeak = function() { - return this.yyhwm; - } - - /* - ** Find the appropriate action for a parser given the terminal - ** look-ahead token iLookAhead. - */ - this.yy_find_shift_action = function( - iLookAhead /* The look-ahead token */ - ) { - var yytos = this.yystack[this.yyidx]; - var stateno = yytos.stateno; - - if (stateno >= this.YY_MIN_REDUCE) { - return stateno; - } - - // assert( stateno <= YY_SHIFT_COUNT ); - - do { - var i = this.yy_shift_ofst[stateno]; - // assert( iLookAhead!=YYNOCODE ); - i += iLookAhead; - if (i < 0 || i >= this.yy_action.length || this.yy_lookahead[i] != iLookAhead) { - if (this.YYFALLBACK) { - var iFallback; /* Fallback token */ - if ((iLookAhead < this.yyFallback.length) && - (iFallback = this.yyFallback[iLookAhead]) != 0 - ) { - if (this.yyTraceCallback) { - this.trace("FALLBACK " + this.yyTokenName[iLookAhead] + " => " + this.yyTokenName[iFallback]); - } - } - // assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */ - iLookAhead = iFallback; - continue; - } - - if (this.YYWILDCARD) { - var j = i - iLookAhead + this.YYWILDCARD; - var cond1 = (this.YY_SHIFT_MIN + this.YYWILDCARD) < 0 ? j >= 0 : true; - var cond2 = (this.YY_SHIFT_MAX + this.YYWILDCARD) >= this.yy_action.length ? j < this.yy_action.length : true; - if (cond1 && cond2 && this.yy_lookahead[j] == this.YYWILDCARD && iLookAhead > 0) { - if (this.yyTraceCallback) { - this.trace("WILDCARD " + this.yyTokenName[iLookAhead] + " => " + this.yyTokenName[this.YYWILDCARD]); - } - return this.yy_action[j]; - } - } - - return this.yy_default[stateno]; - } else { - return this.yy_action[i]; - } - } while (true); - } - - /* - ** Find the appropriate action for a parser given the non-terminal - ** look-ahead token iLookAhead. - */ - this.yy_find_reduce_action = function( - stateno, /* Current state number */ - iLookAhead /* The look-ahead token */ - ) { - if (this.YYERRORSYMBOL) { - if (stateno > this.YY_REDUCE_COUNT) { - return this.yy_default[stateno]; - } - } else { - // assert( stateno<=YY_REDUCE_COUNT ); - } - - var i = this.yy_reduce_ofst[stateno]; - // assert( i!=YY_REDUCE_USE_DFLT ); - // assert( iLookAhead!=YYNOCODE ); - i += iLookAhead; - - if (this.YYERRORSYMBOL) { - if (i < 0 || i >= this.yy_action.length || this.yy_lookahead[i] != iLookAhead) { - return this.yy_default[stateno]; - } - } else { - // assert( i>=0 && i 0) { - this.yy_pop_parser_stack(); - } - /* Here code is inserted which will execute if the parser - ** stack every overflows */ - /******** Begin %stack_overflow code ******************************************/ - /******** End %stack_overflow code ********************************************/ - } - - /* - ** Print tracing information for a SHIFT action - */ - this.yyTraceShift = function(yyNewState) { - if (this.yyTraceCallback) { - var yytos = this.yystack[this.yyidx]; - if (yyNewState < this.YYNSTATE) { - this.trace("Shift '" + this.yyTokenName[yytos.major] + "', go to state " + yyNewState); - } else { - this.trace("Shift '" + this.yyTokenName[yytos.major] + "'"); - } - } - } - - /* - ** Perform a shift action. - */ - this.yy_shift = function( - yyNewState, /* The new state to shift in */ - yyMajor, /* The major token to shift in */ - yyMinor /* The minor token to shift in */ - ) { - this.yyidx++; - - if (this.yyidx > this.yyhwm) { - this.yyhwm++; - // assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) ); - } - - if (this.YYSTACKDEPTH > 0) { - if (this.yyidx >= this.YYSTACKDEPTH) { - this.yyidx--; - this.yyStackOverflow(); - return; - } - } else { - if (this.yyidx >= this.yystack.length) { - this.yyGrowStack(); - } - } - - if (yyNewState > this.YY_MAX_SHIFT) { - yyNewState += this.YY_MIN_REDUCE - this.YY_MIN_SHIFTREDUCE; - } - - var yytos = this.yystack[this.yyidx]; - yytos.stateno = yyNewState; - yytos.major = yyMajor; - yytos.minor = yyMinor; - - this.yyTraceShift(yyNewState); - } - - /* The following table contains information about every rule that - ** is used during the reduce. - */ - //{ - // lhs, /* Symbol on the left-hand side of the rule */ - // nrhs, /* Number of right-hand side symbols in the rule */ - //} - this.yyRuleInfo = [{ - lhs: 28, - nrhs: 1 - }, - { - lhs: 28, - nrhs: 1 - }, - { - lhs: 31, - nrhs: 1 - }, - { - lhs: 30, - nrhs: 1 - }, - { - lhs: 32, - nrhs: 1 - }, - { - lhs: 30, - nrhs: 1 - }, - { - lhs: 33, - nrhs: 1 - }, - { - lhs: 30, - nrhs: 1 - }, - { - lhs: 34, - nrhs: 1 - }, - { - lhs: 30, - nrhs: 1 - }, - { - lhs: 35, - nrhs: 1 - }, - { - lhs: 35, - nrhs: 1 - }, - { - lhs: 36, - nrhs: 3 - }, - { - lhs: 37, - nrhs: 3 - }, - { - lhs: 38, - nrhs: 2 - }, - { - lhs: 39, - nrhs: 3 - }, - { - lhs: 40, - nrhs: 3 - }, - { - lhs: 41, - nrhs: 3 - }, - { - lhs: 42, - nrhs: 3 - }, - { - lhs: 43, - nrhs: 3 - }, - { - lhs: 44, - nrhs: 3 - }, - { - lhs: 45, - nrhs: 3 - }, - { - lhs: 46, - nrhs: 3 - }, - { - lhs: 29, - nrhs: 1 - }, - { - lhs: 29, - nrhs: 1 - }, - { - lhs: 29, - nrhs: 1 - }, - { - lhs: 29, - nrhs: 1 - }, - { - lhs: 29, - nrhs: 1 - }, - { - lhs: 29, - nrhs: 1 - }, - { - lhs: 29, - nrhs: 1 - }, - { - lhs: 29, - nrhs: 1 - }, - { - lhs: 29, - nrhs: 1 - }, - { - lhs: 29, - nrhs: 1 - }, - { - lhs: 29, - nrhs: 1 - }, - { - lhs: 29, - nrhs: 3 - }, - { - lhs: 47, - nrhs: 1 - }, - { - lhs: 47, - nrhs: 3 - }, - { - lhs: 48, - nrhs: 1 - }, - { - lhs: 48, - nrhs: 0 - }, - { - lhs: 49, - nrhs: 4 - }, - { - lhs: 30, - nrhs: 1 - }, - { - lhs: 50, - nrhs: 1 - }, - { - lhs: 50, - nrhs: 3 - }, - { - lhs: 51, - nrhs: 1 - }, - { - lhs: 51, - nrhs: 0 - }, - { - lhs: 52, - nrhs: 4 - }, - { - lhs: 30, - nrhs: 1 - }, - { - lhs: 53, - nrhs: 10 - }, - { - lhs: 30, - nrhs: 1 - }, - ]; - - /* - ** Perform a reduce action and the shift that must immediately - ** follow the reduce. - */ - this.yy_reduce = function( - yyruleno /* Number of the rule by which to reduce */ - ) { - var yymsp = this.yystack[this.yyidx]; /* The top of the parser's stack */ - - if (yyruleno < this.yyRuleName.length) { - var yysize = this.yyRuleInfo[yyruleno].nrhs; - var ruleName = this.yyRuleName[yyruleno]; - var newStateNo = this.yystack[this.yyidx - yysize].stateno; - if (this.yyTraceCallback) { - this.trace("Reduce [" + ruleName + "], go to state " + newStateNo + "."); - } - } - - /* Check that the stack is large enough to grow by a single entry - ** if the RHS of the rule is empty. This ensures that there is room - ** enough on the stack to push the LHS value */ - if (this.yyRuleInfo[yyruleno].nrhs == 0) { - if (this.yyidx > this.yyhwm) { - this.yyhwm++; - // assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack)); - } - if (this.YYSTACKDEPTH > 0) { - if (this.yyidx >= this.YYSTACKDEPTH - 1) { - this.yyStackOverflow(); - return; - } - } else { - if (this.yyidx >= this.yystack.length - 1) { - this.yyGrowStack(); - yymsp = this.yystack[this.yyidx]; - } - } - } - - var yylhsminor; - switch (yyruleno) { - /* Beginning here are the reduction cases. A typical example - ** follows: - ** case 0: - ** #line - ** { ... } // User supplied code - ** #line - ** break; - */ - /********** Begin reduce actions **********************************************/ - case 0: - /* main ::= expr */ - case 1: - /* main ::= literal */ this.yytestcase(yyruleno == 1); { - _result.root_node = this.yystack[this.yyidx + 0].minor - } - break; - case 2: - /* integer_literal ::= INTEGER_LITERAL */ { - yylhsminor = new tokens.integer_literal({ - children: [ - new tokens.LEXEME({ - type: this.yystack[this.yyidx + 0].minor.lexeme, - value: this.yystack[this.yyidx + 0].minor.value, - start: this.yystack[this.yyidx + 0].minor.start, - end: this.yystack[this.yyidx + 0].minor.end - }) - ] - }); - } - this.yystack[this.yyidx + 0].minor = yylhsminor; - break; - case 3: - /* literal ::= integer_literal */ - case 5: - /* literal ::= float_literal */ this.yytestcase(yyruleno == 5); - case 7: - /* literal ::= bool_literal */ this.yytestcase(yyruleno == 7); - case 9: - /* literal ::= string_literal */ this.yytestcase(yyruleno == 9); - case 23: - /* expr ::= and */ this.yytestcase(yyruleno == 23); - case 24: - /* expr ::= or */ this.yytestcase(yyruleno == 24); - case 25: - /* expr ::= not */ this.yytestcase(yyruleno == 25); - case 26: - /* expr ::= eq */ this.yytestcase(yyruleno == 26); - case 27: - /* expr ::= neq */ this.yytestcase(yyruleno == 27); - case 28: - /* expr ::= gt */ this.yytestcase(yyruleno == 28); - case 29: - /* expr ::= gte */ this.yytestcase(yyruleno == 29); - case 30: - /* expr ::= lt */ this.yytestcase(yyruleno == 30); - case 31: - /* expr ::= lte */ this.yytestcase(yyruleno == 31); - case 32: - /* expr ::= like */ this.yytestcase(yyruleno == 32); - case 33: - /* expr ::= nlike */ this.yytestcase(yyruleno == 33); - case 37: - /* address_literal_content_or_empty ::= address_literal_content */ this.yytestcase(yyruleno == 37); - case 40: - /* literal ::= address_literal */ this.yytestcase(yyruleno == 40); - case 43: - /* oid_literal_content_or_empty ::= oid_literal_content */ this.yytestcase(yyruleno == 43); - case 46: - /* literal ::= oid_literal */ this.yytestcase(yyruleno == 46); - case 48: - /* literal ::= time_diff_literal */ this.yytestcase(yyruleno == 48); { - yylhsminor = this.yystack[this.yyidx + 0].minor; - } - this.yystack[this.yyidx + 0].minor = yylhsminor; - break; - case 4: - /* float_literal ::= FLOAT_LITERAL */ { - yylhsminor = new tokens.float_literal({ - children: [ - new tokens.LEXEME({ - type: this.yystack[this.yyidx + 0].minor.lexeme, - value: this.yystack[this.yyidx + 0].minor.value, - start: this.yystack[this.yyidx + 0].minor.start, - end: this.yystack[this.yyidx + 0].minor.end - }) - ] - }) - } - this.yystack[this.yyidx + 0].minor = yylhsminor; - break; - case 6: - /* bool_literal ::= BOOL_LITERAL */ { - yylhsminor = new tokens.bool_literal({ - children: [ - new tokens.LEXEME({ - type: this.yystack[this.yyidx + 0].minor.lexeme, - value: this.yystack[this.yyidx + 0].minor.value, - start: this.yystack[this.yyidx + 0].minor.start, - end: this.yystack[this.yyidx + 0].minor.end - }) - ] - }) - } - this.yystack[this.yyidx + 0].minor = yylhsminor; - break; - case 8: - /* string_literal ::= STRING_LITERAL */ { - yylhsminor = new tokens.string_literal({ - children: [ - new tokens.LEXEME({ - type: this.yystack[this.yyidx + 0].minor.lexeme, - value: this.yystack[this.yyidx + 0].minor.value, - start: this.yystack[this.yyidx + 0].minor.start, - end: this.yystack[this.yyidx + 0].minor.end - }) - ] - }); - } - this.yystack[this.yyidx + 0].minor = yylhsminor; - break; - case 10: - /* id ::= string_literal */ { - yylhsminor = new tokens.id({ - children: [this.yystack[this.yyidx + 0].minor] - }); - } - this.yystack[this.yyidx + 0].minor = yylhsminor; - break; - case 11: - /* id ::= ID */ { - yylhsminor = new tokens.id({ - children: [ - new tokens.LEXEME({ - type: this.yystack[this.yyidx + 0].minor.lexeme, - value: this.yystack[this.yyidx + 0].minor.value, - start: this.yystack[this.yyidx + 0].minor.start, - end: this.yystack[this.yyidx + 0].minor.end - }) - ] - }); - } - this.yystack[this.yyidx + 0].minor = yylhsminor; - break; - case 12: - /* and ::= expr AND expr */ { - yylhsminor = new tokens.and({ - lexpr: this.yystack[this.yyidx + -2].minor, - op: new tokens.LEXEME({ - type: this.yystack[this.yyidx + -1].minor.lexeme, - value: this.yystack[this.yyidx + -1].minor.value, - start: this.yystack[this.yyidx + -1].minor.start, - end: this.yystack[this.yyidx + -1].minor.end - }), - rexpr: this.yystack[this.yyidx + 0].minor - }) - } - this.yystack[this.yyidx + -2].minor = yylhsminor; - break; - case 13: - /* or ::= expr OR expr */ { - yylhsminor = new tokens.or({ - lexpr: this.yystack[this.yyidx + -2].minor, - op: new tokens.LEXEME({ - type: this.yystack[this.yyidx + -1].minor.lexeme, - value: this.yystack[this.yyidx + -1].minor.value, - start: this.yystack[this.yyidx + -1].minor.start, - end: this.yystack[this.yyidx + -1].minor.end - }), - rexpr: this.yystack[this.yyidx + 0].minor - }) - } - this.yystack[this.yyidx + -2].minor = yylhsminor; - break; - case 14: - /* not ::= NOT expr */ { - yylhsminor = new tokens.not({ - op: new tokens.LEXEME({ - type: this.yystack[this.yyidx + -1].minor.lexeme, - value: this.yystack[this.yyidx + -1].minor.value, - start: this.yystack[this.yyidx + -1].minor.start, - end: this.yystack[this.yyidx + -1].minor.end - }), - rexpr: this.yystack[this.yyidx + 0].minor - }) - } - this.yystack[this.yyidx + -1].minor = yylhsminor; - break; - case 15: - /* eq ::= id EQ literal */ { - yylhsminor = new tokens.eq({ - id: this.yystack[this.yyidx + -2].minor, - op: new tokens.LEXEME({ - type: this.yystack[this.yyidx + -1].minor.lexeme, - value: this.yystack[this.yyidx + -1].minor.value, - start: this.yystack[this.yyidx + -1].minor.start, - end: this.yystack[this.yyidx + -1].minor.end - }), - literal: this.yystack[this.yyidx + 0].minor - }); - } - this.yystack[this.yyidx + -2].minor = yylhsminor; - break; - case 16: - /* neq ::= id NEQ literal */ { - yylhsminor = new tokens.neq({ - id: this.yystack[this.yyidx + -2].minor, - op: new tokens.LEXEME({ - type: this.yystack[this.yyidx + -1].minor.lexeme, - value: this.yystack[this.yyidx + -1].minor.value, - start: this.yystack[this.yyidx + -1].minor.start, - end: this.yystack[this.yyidx + -1].minor.end - }), - literal: this.yystack[this.yyidx + 0].minor - }); - } - this.yystack[this.yyidx + -2].minor = yylhsminor; - break; - case 17: - /* gt ::= id GT literal */ { - yylhsminor = new tokens.gt({ - id: this.yystack[this.yyidx + -2].minor, - op: new tokens.LEXEME({ - type: this.yystack[this.yyidx + -1].minor.lexeme, - value: this.yystack[this.yyidx + -1].minor.value, - start: this.yystack[this.yyidx + -1].minor.start, - end: this.yystack[this.yyidx + -1].minor.end - }), - literal: this.yystack[this.yyidx + 0].minor - }); - } - this.yystack[this.yyidx + -2].minor = yylhsminor; - break; - case 18: - /* gte ::= id GTE literal */ { - yylhsminor = new tokens.gte({ - id: this.yystack[this.yyidx + -2].minor, - op: new tokens.LEXEME({ - type: this.yystack[this.yyidx + -1].minor.lexeme, - value: this.yystack[this.yyidx + -1].minor.value, - start: this.yystack[this.yyidx + -1].minor.start, - end: this.yystack[this.yyidx + -1].minor.end - }), - literal: this.yystack[this.yyidx + 0].minor - }); - } - this.yystack[this.yyidx + -2].minor = yylhsminor; - break; - case 19: - /* lt ::= id LT literal */ { - yylhsminor = new tokens.lt({ - id: this.yystack[this.yyidx + -2].minor, - op: new tokens.LEXEME({ - type: this.yystack[this.yyidx + -1].minor.lexeme, - value: this.yystack[this.yyidx + -1].minor.value, - start: this.yystack[this.yyidx + -1].minor.start, - end: this.yystack[this.yyidx + -1].minor.end - }), - literal: this.yystack[this.yyidx + 0].minor - }); - } - this.yystack[this.yyidx + -2].minor = yylhsminor; - break; - case 20: - /* lte ::= id LTE literal */ { - yylhsminor = new tokens.lte({ - id: this.yystack[this.yyidx + -2].minor, - op: new tokens.LEXEME({ - type: this.yystack[this.yyidx + -1].minor.lexeme, - value: this.yystack[this.yyidx + -1].minor.value, - start: this.yystack[this.yyidx + -1].minor.start, - end: this.yystack[this.yyidx + -1].minor.end - }), - literal: this.yystack[this.yyidx + 0].minor - }); - } - this.yystack[this.yyidx + -2].minor = yylhsminor; - break; - case 21: - /* like ::= id LIKE literal */ { - yylhsminor = new tokens.like({ - id: this.yystack[this.yyidx + -2].minor, - op: new tokens.LEXEME({ - type: this.yystack[this.yyidx + -1].minor.lexeme, - value: this.yystack[this.yyidx + -1].minor.value, - start: this.yystack[this.yyidx + -1].minor.start, - end: this.yystack[this.yyidx + -1].minor.end - }), - literal: this.yystack[this.yyidx + 0].minor - }); - } - this.yystack[this.yyidx + -2].minor = yylhsminor; - break; - case 22: - /* nlike ::= id NLIKE literal */ { - yylhsminor = new tokens.nlike({ - id: this.yystack[this.yyidx + -2].minor, - op: new tokens.LEXEME({ - type: this.yystack[this.yyidx + -1].minor.lexeme, - value: this.yystack[this.yyidx + -1].minor.value, - start: this.yystack[this.yyidx + -1].minor.start, - end: this.yystack[this.yyidx + -1].minor.end - }), - literal: this.yystack[this.yyidx + 0].minor - }); - } - this.yystack[this.yyidx + -2].minor = yylhsminor; - break; - case 34: - /* expr ::= LCB expr RCB */ { - yylhsminor = new tokens.sub_expr({ - LCB: new tokens.LEXEME({ - type: this.yystack[this.yyidx + -2].minor.lexeme, - value: this.yystack[this.yyidx + -2].minor.value, - start: this.yystack[this.yyidx + -2].minor.start, - end: this.yystack[this.yyidx + -2].minor.end - }), - expr: this.yystack[this.yyidx + -1].minor, - RCB: new tokens.LEXEME({ - type: this.yystack[this.yyidx + 0].minor.lexeme, - value: this.yystack[this.yyidx + 0].minor.value, - start: this.yystack[this.yyidx + 0].minor.start, - end: this.yystack[this.yyidx + 0].minor.end - }) - }); - } - this.yystack[this.yyidx + -2].minor = yylhsminor; - break; - case 35: - /* address_literal_content ::= string_literal */ { - yylhsminor = new tokens.address_literal_content({ - children: [this.yystack[this.yyidx + 0].minor] - }); - } - this.yystack[this.yyidx + 0].minor = yylhsminor; - break; - case 36: - /* address_literal_content ::= address_literal_content COMMA string_literal */ - case 42: - /* oid_literal_content ::= oid_literal_content DOT id */ this.yytestcase(yyruleno == 42); { - this.yystack[this.yyidx + -2].minor.add(this.yystack[this.yyidx + 0].minor); - yylhsminor = this.yystack[this.yyidx + -2].minor; - } - this.yystack[this.yyidx + -2].minor = yylhsminor; - break; - case 38: - /* address_literal_content_or_empty ::= */ { - this.yystack[this.yyidx + 1].minor = new tokens.address_literal_content({ - children: [] - }); - } - break; - case 39: - /* address_literal ::= ADDRESS LSB address_literal_content_or_empty RSB */ { - yylhsminor = new tokens.address_literal({ - children: this.yystack[this.yyidx + -1].minor.children, - keyword: new tokens.LEXEME({ - type: this.yystack[this.yyidx + -3].minor.lexeme, - value: this.yystack[this.yyidx + -3].minor.value, - start: this.yystack[this.yyidx + -3].minor.start, - end: this.yystack[this.yyidx + -3].minor.end - }), - LSB: new tokens.LEXEME({ - type: this.yystack[this.yyidx + -2].minor.lexeme, - value: this.yystack[this.yyidx + -2].minor.value, - start: this.yystack[this.yyidx + -2].minor.start, - end: this.yystack[this.yyidx + -2].minor.end - }), - RSB: new tokens.LEXEME({ - type: this.yystack[this.yyidx + 0].minor.lexeme, - value: this.yystack[this.yyidx + 0].minor.value, - start: this.yystack[this.yyidx + 0].minor.start, - end: this.yystack[this.yyidx + 0].minor.end - }) - }); - } - this.yystack[this.yyidx + -3].minor = yylhsminor; - break; - case 41: - /* oid_literal_content ::= id */ { - yylhsminor = new tokens.oid_literal_content({ - children: [this.yystack[this.yyidx + 0].minor] - }); - } - this.yystack[this.yyidx + 0].minor = yylhsminor; - break; - case 44: - /* oid_literal_content_or_empty ::= */ { - this.yystack[this.yyidx + 1].minor = new tokens.oid_literal_content({ - children: [] - }); - } - break; - case 45: - /* oid_literal ::= OID LSB oid_literal_content_or_empty RSB */ { - yylhsminor = new tokens.oid_literal({ - children: this.yystack[this.yyidx + -1].minor.children, - keyword: new tokens.LEXEME({ - type: this.yystack[this.yyidx + -3].minor.lexeme, - value: this.yystack[this.yyidx + -3].minor.value, - start: this.yystack[this.yyidx + -3].minor.start, - end: this.yystack[this.yyidx + -3].minor.end - }), - LSB: new tokens.LEXEME({ - type: this.yystack[this.yyidx + -2].minor.lexeme, - value: this.yystack[this.yyidx + -2].minor.value, - start: this.yystack[this.yyidx + -2].minor.start, - end: this.yystack[this.yyidx + -2].minor.end - }), - RSB: new tokens.LEXEME({ - type: this.yystack[this.yyidx + 0].minor.lexeme, - value: this.yystack[this.yyidx + 0].minor.value, - start: this.yystack[this.yyidx + 0].minor.start, - end: this.yystack[this.yyidx + 0].minor.end - }) - }); - } - this.yystack[this.yyidx + -3].minor = yylhsminor; - break; - case 47: - /* time_diff_literal ::= TIMEDIFF LSB integer_literal integer_literal COLON integer_literal COLON integer_literal integer_literal RSB */ { - yylhsminor = new tokens.time_diff_literal({ - keyword: new tokens.LEXEME({ - type: this.yystack[this.yyidx + -9].minor.lexeme, - value: this.yystack[this.yyidx + -9].minor.value, - start: this.yystack[this.yyidx + -9].minor.start, - end: this.yystack[this.yyidx + -9].minor.end - }), - LSB: new tokens.LEXEME({ - type: this.yystack[this.yyidx + -8].minor.lexeme, - value: this.yystack[this.yyidx + -8].minor.value, - start: this.yystack[this.yyidx + -8].minor.start, - end: this.yystack[this.yyidx + -8].minor.end - }), - RSB: new tokens.LEXEME({ - type: this.yystack[this.yyidx + 0].minor.lexeme, - value: this.yystack[this.yyidx + 0].minor.value, - start: this.yystack[this.yyidx + 0].minor.start, - end: this.yystack[this.yyidx + 0].minor.end - }), - days: this.yystack[this.yyidx + -7].minor, - hours: this.yystack[this.yyidx + -6].minor, - minutes: this.yystack[this.yyidx + -4].minor, - seconds: this.yystack[this.yyidx + -2].minor, - microseconds: this.yystack[this.yyidx + -1].minor, - }); - } - this.yystack[this.yyidx + -9].minor = yylhsminor; - break; - default: - break; - /********** End reduce actions ************************************************/ - }; - // assert( yyruleno this.YY_MAX_SHIFT) { - yyact += this.YY_MIN_REDUCE - this.YY_MIN_SHIFTREDUCE; - } - this.yyidx -= yysize - 1; - yymsp = this.yystack[this.yyidx]; - yymsp.stateno = yyact; - yymsp.major = yygoto; - this.yyTraceShift(yyact); - } else { - // assert( yyact == YY_ACCEPT_ACTION ); - this.yyidx -= yysize; - this.yy_accept(); - } - } - - /* - ** The following code executes when the parse fails - */ - this.yy_parse_failed = function() { - if (this.yyTraceCallback) { - this.trace("Fail!"); - } - while (this.yyidx > 0) { - this.yy_pop_parser_stack(); - } - /* Here code is inserted which will be executed whenever the - ** parser fails */ - /************ Begin %parse_failure code ***************************************/ - /************ End %parse_failure code *****************************************/ - } - - /* - ** The following code executes when a syntax error first occurs. - */ - this.yy_syntax_error = function( - yymajor, /* The major type of the error token */ - yyminor /* The minor type of the error token */ - ) { - var TOKEN = yyminor; - /************ Begin %syntax_error code ****************************************/ - - console.log("Syntax error"); - /************ End %syntax_error code ******************************************/ - } - - /* - ** The following is executed when the parser accepts - */ - this.yy_accept = function() { - if (this.yyTraceCallback) { - this.trace("Accept!"); - } - if (!this.YYNOERRORRECOVERY) { - this.yyerrcnt = -1; - } - // assert( yypParser->yytos==yypParser->yystack ); - /* Here code is inserted which will be executed whenever the - ** parser accepts */ - /*********** Begin %parse_accept code *****************************************/ - /*********** End %parse_accept code *******************************************/ - } - - /* The main parser program. - ** The first argument is a pointer to a structure obtained from - ** "ParserAlloc" which describes the current state of the parser. - ** The second argument is the major token number. The third is - ** the minor token. The fourth optional argument is whatever the - ** user wants (and specified in the grammar) and is available for - ** use by the action routines. - ** - ** Inputs: - **
    - **
  • A pointer to the parser (an opaque structure.) - **
  • The major token number. - **
  • The minor token number. - **
  • An option argument of a grammar-specified type. - **
- ** - ** Outputs: - ** None. - */ - this.parse = function( - yymajor, /* The major token code number */ - yyminor /* The value for the token */ - ) { - var yyact; /* The parser action. */ - var yyendofinput; /* True if we are at the end of input */ - var yyerrorhit = 0; /* True if yymajor has invoked an error */ - - //assert( yypParser->yytos!=0 ); - - if (yymajor === undefined || yymajor === null) { - yymajor = 0; - } - - yyendofinput = yymajor == 0; - - if (this.yyTraceCallback) { - this.trace("Input '" + this.yyTokenName[yymajor] + "'"); - } - - do { - yyact = this.yy_find_shift_action(yymajor); - if (yyact <= this.YY_MAX_SHIFTREDUCE) { // check me? - this.yy_shift(yyact, yymajor, yyminor); - if (!this.YYNOERRORRECOVERY) { - this.yyerrcnt--; - } - yymajor = this.YYNOCODE; - } else if (yyact <= this.YY_MAX_REDUCE) { // check me? - this.yy_reduce(yyact - this.YY_MIN_REDUCE); // check me? - } else { - // assert( yyact == YY_ERROR_ACTION ); - if (this.yyTraceCallback) { - this.trace("Syntax Error!"); - } - if (this.YYERRORSYMBOL) { - /* A syntax error has occurred. - ** The response to an error depends upon whether or not the - ** grammar defines an error token "ERROR". - ** - ** This is what we do if the grammar does define ERROR: - ** - ** * Call the %syntax_error function. - ** - ** * Begin popping the stack until we enter a state where - ** it is legal to shift the error symbol, then shift - ** the error symbol. - ** - ** * Set the error count to three. - ** - ** * Begin accepting and shifting new tokens. No new error - ** processing will occur until three tokens have been - ** shifted successfully. - ** - */ - if (this.yyerrcnt < 0) { - this.yy_syntax_error(yymajor, yyminor); - } - var yymx = this.yystack[this.yyidx].major; - if (yymx == this.YYERRORSYMBOL || yyerrorhit) { - if (this.yyTraceCallback) { - this.trace("Discard input token " + this.yyTokenName[yymajor]); - } - this.yy_destructor(yymajor, yyminor); - yymajor = this.YYNOCODE; - } else { - while (this.yyidx >= 0 && - yymx != this.YYERRORSYMBOL && - (yyact = this.yy_find_reduce_action( - this.yystack[this.yyidx].stateno, - this.YYERRORSYMBOL)) >= this.YY_MIN_REDUCE // check me? - ) { - this.yy_pop_parser_stack(); - } - if (this.yyidx < 0 || yymajor == 0) { - this.yy_destructor(yymajor, yyminor); - this.yy_parse_failed(); - if (!this.YYNOERRORRECOVERY) { - this.yyerrcnt = -1; - } - yymajor = this.YYNOCODE; - } else if (yymx != this.YYERRORSYMBOL) { - this.yy_shift(yyact, this.YYERRORSYMBOL, yyminor); // check me? - } - } - this.yyerrcnt = 3; - yyerrorhit = 1; - } else if (this.YYNOERRORRECOVERY) { - /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to - ** do any kind of error recovery. Instead, simply invoke the syntax - ** error routine and continue going as if nothing had happened. - ** - ** Applications can set this macro (for example inside %include) if - ** they intend to abandon the parse upon the first syntax error seen. - */ - this.yy_syntax_error(yymajor, yyminor); - this.yy_destructor(yymajor, yyminor); - yymajor = this.YYNOCODE; - } else { - /* YYERRORSYMBOL is not defined */ - /* This is what we do if the grammar does not define ERROR: - ** - ** * Report an error message, and throw away the input token. - ** - ** * If the input token is $, then fail the parse. - ** - ** As before, subsequent error messages are suppressed until - ** three input tokens have been successfully shifted. - */ - if (this.yyerrcnt <= 0) { - this.yy_syntax_error(yymajor, yyminor); - } - this.yyerrcnt = 3; - this.yy_destructor(yymajor, yyminor); - if (yyendofinput) { - this.yy_parse_failed(); - if (!this.YYNOERRORRECOVERY) { - this.yyerrcnt = -1; - } - } - yymajor = this.YYNOCODE; - } - } - } while (yymajor != this.YYNOCODE && this.yyidx > 0); - - if (this.yyTraceCallback) { - var remainingTokens = []; - for (var i = 1; i <= this.yyidx; i++) { - remainingTokens.push(this.yyTokenName[this.yystack[i].major]); - } - this.trace("Return. Stack=[" + remainingTokens.join(" ") + "]"); - } - } - - this.init(); - -} // function Parser() - -/** - * Created by Aleksey Chichenkov on 1/28/19. - */ - -var fs = require("fs"); -var Lexer = require('./lexer.js'); - -var tokens = (function() { - - var std = (function() { - var protos = "__protos__"; - var keys = "__keys__"; - - - /** - * Return unique data - * - * @param {Object[]} _arr - prototypes of inheritance classes - * @param {Object} _main - prototype of resulting class - * - * @return {Object} - * */ - var unique = function(_arr, _main) { - var result = Object.create(null); - var to_remove = []; - - for (var i = 0, e = _arr.length; i != e; ++i) { - var item = _arr[i]; - - for (var key in item) { - if (key in result) { - to_remove.push(key); - continue; - } - - result[key] = item[key]; - } - - if (keys in item) { - for (var ii = 0, ee = item[keys].length; ii != ee; ++ii) { - var key = item[keys][ii]; - if (key in result) { - to_remove.push(key); - continue; - } - - result[key] = item[key]; - } - } - } - - for (var i = 0; i != to_remove.length; ++i) { - delete result[to_remove[i]]; - } - - for (var key in _main) { - result[key] = _main[key]; - } - - return result; - }; - - /** - * Create OOP class - * - * @param {Function[]} _constrs - inheritance classes - * @param {Object} _proto - prototype of resulting class - * @param {Object?} _static - static data - * - * @return {Function} - * */ - var class_creator = function(_constrs, _proto, _static) { - _constrs = _constrs || []; - _proto = _proto || []; - _static = _static || []; - - var constr; - if (_proto && _proto.hasOwnProperty("constructor")) { - constr = _proto.constructor; - delete _proto.constructor; - } else { - constr = function() { - for (var i = 0; i != _constrs.length; ++i) { - _constrs[i].apply(this, arguments); - } - }; - } - - var proto = Object.create(null); - Object.defineProperty(proto, protos, { - "value": [] - }); - Object.defineProperty(proto, keys, { - "value": [] - }); - - /************************FOR MEMBERS*******************************/ - for (var i = 0, e = _constrs.length; i != e; ++i) { - proto[protos].push(_constrs[i].prototype); - } - - var m_un = unique(proto[protos], _proto); - for (var key in m_un) { - proto[keys].push(key); - - Object.defineProperty(proto, key, { - "value": m_un[key] - }); - } - /************************FOR MEMBERS END***************************/ - - /************************FOR STATICS*******************************/ - var s_un = unique(_constrs, _static); - for (var key in s_un) { - Object.defineProperty(constr, key, { - "value": s_un[key], - "enumerable": true - }); - } - /************************FOR STATICS END***************************/ - - - Object.defineProperties(constr, { - "pr": { - "value": proto - }, - "prototype": { - "value": proto - } - }); - - Object.freeze(proto); - Object.freeze(constr); - - return constr; - }; - - /** - * Check if target has prototype - * - * @param {Object} _target - checkable instance - * @param {Object} _proto - posible prototype - * - * */ - var check = function(_target, _proto) { - for (var i = 0; i != _target[protos].length; ++i) { - var t_proto = _target[protos][i]; - if (t_proto == _proto) { - return true; - } - - if (t_proto[protos]) { - if (check(t_proto, _proto)) - return true; - } - } - - return false; - }; - - /** - * Check if target is instance of class - * - * @param {Object} _target - checkable instance - * @param {Function} _constr - posible constructor - * - * */ - var class_check = function(_target, _constr) { - if (_target instanceof _constr) { - return true; - } - - return check(_target, _constr.prototype); - }; - - return { - class: class_creator, - class_check: class_check - }; - })(); - var tools = { - merge: function(_obj) { - var target = Object.create(null); - var i = 0, - e = arguments.length; - for (; i != e; ++i) { - var options = arguments[i]; - - for (var key in options) { - if (options[key] === undefined && target === options[key]) - continue; - - target[key] = options[key]; - } - } - - return target; - } - }; - - var Node = std.class([], { - constructor: function Node(_options) { - var base = tools.merge({ - children: [] - }, _options); - - this.children = base.children; - }, - add: function(_n) { - this.children.push(_n); - return this; - } - }); - - var Lexeme = std.class([Node], { - constructor: function Lexeme(_options) { - var base = tools.merge({ - start: -1, - end: -1, - type: null, - value: null - }, _options); - - Node.call(this, base); - - this.start = base.start; - this.end = base.end; - this.type = base.type; - this.value = base.value; - } - }); - - var Rule = std.class([Node], { - constructor: function NonTerminal(_options) { - var base = tools.merge({}, _options); - - Node.call(this, base); - } - }); - - var terminal_literal = std.class([Rule], { - constructor: function terminal_literal(_options) { - var base = tools.merge({}, _options); - - Rule.call(this, base); - }, - position: function() { - var first_child = this.children[0]; - - return { - start: first_child.start, - end: first_child.end, - } - } - }); - - var string_literal = std.class([terminal_literal], { - constructor: function string_literal(_options) { - var base = tools.merge({}, _options); - - terminal_literal.call(this, base); - } - }); - - var integer_literal = std.class([terminal_literal], { - constructor: function integer_literal(_options) { - var base = tools.merge({}, _options); - - terminal_literal.call(this, base); - } - }); - - var float_literal = std.class([terminal_literal], { - constructor: function float_literal(_options) { - var base = tools.merge({}, _options); - - terminal_literal.call(this, base); - } - }); - - var bool_literal = std.class([terminal_literal], { - constructor: function bool_literal(_options) { - var base = tools.merge({}, _options); - - terminal_literal.call(this, base); - } - }); - - var id = std.class([Rule], { - constructor: function id(_options) { - var base = tools.merge({}, _options); - - Rule.call(this, base); - }, - position: function() { - var first_child = this.children[0]; - - if (std.class_check(first_child, Lexeme)) { - return { - start: first_child.start, - end: first_child.end, - } - } else { - return this.position(); - } - } - }); - - // var literal = std.class([Rule], { - // constructor: function literal(_options) { - // var base = tools.merge({}, _options); - // - // Rule.call(this, base); - // } - // }); - - var expr_compares = std.class([Rule], { - constructor: function expr_compares(_options) { - var base = tools.merge({ - lexpr: null, - op: null, - rexpr: null - }, _options); - - Rule.call(this, base); - - this.lexpr = base.lexpr; - this.op = base.op; - this.rexpr = base.rexpr; - }, - position: function() { - return { - start: this.lexpr.position().start, - end: this.rexpr.position().end, - } - } - }); - - var and = std.class([Rule], { - constructor: function and(_options) { - var base = tools.merge({}, _options); - - expr_compares.call(this, base); - } - }); - - var or = std.class([Rule], { - constructor: function or(_options) { - var base = tools.merge({}, _options); - - expr_compares.call(this, base); - } - }); - - var not = std.class([Rule], { - constructor: function not(_options) { - var base = tools.merge({ - op: null, - rexpr: null - }, _options); - - Rule.call(this, base); - - this.op = base.op; - this.rexpr = base.rexpr; - }, - position: function() { - return { - start: this.op.start, - end: this.rexpr.position().end, - } - } - }); - - var endpoint_compares = std.class([Rule], { - constructor: function endpoint_compares(_options) { - var base = tools.merge({ - id: null, - op: null, - literal: null - }, _options); - - Rule.call(this, base); - - this.id = base.id; - this.op = base.op; - this.literal = base.literal; - }, - position: function() { - return { - start: this.id.start, - end: this.literal.end - } - } - }); - - var eq = std.class([endpoint_compares], { - constructor: function eq(_options) { - var base = tools.merge({}, _options); - - endpoint_compares.call(this, base); - }, - }); - - var neq = std.class([endpoint_compares], { - constructor: function neq(_options) { - var base = tools.merge({}, _options); - - endpoint_compares.call(this, base); - }, - }); - - var gt = std.class([endpoint_compares], { - constructor: function gt(_options) { - var base = tools.merge({}, _options); - - endpoint_compares.call(this, base); - } - }); - - var gte = std.class([endpoint_compares], { - constructor: function gte(_options) { - var base = tools.merge({}, _options); - - endpoint_compares.call(this, base); - } - }); - - var lt = std.class([endpoint_compares], { - constructor: function lt(_options) { - var base = tools.merge({}, _options); - - endpoint_compares.call(this, base); - } - }); - - var lte = std.class([endpoint_compares], { - constructor: function lte(_options) { - var base = tools.merge({}, _options); - - endpoint_compares.call(this, base); - } - }); - - var like = std.class([endpoint_compares], { - constructor: function like(_options) { - var base = tools.merge({}, _options); - - endpoint_compares.call(this, base); - } - }); - - var nlike = std.class([endpoint_compares], { - constructor: function nlike(_options) { - var base = tools.merge({}, _options); - - endpoint_compares.call(this, base); - } - }); - - // var expr = std.class([Rule], { - // constructor: function expr(_options) { - // var base = tools.merge({}, _options); - // - // Rule.call(this, base); - // } - // }); - - var sub_expr = std.class([Rule], { - constructor: function expr(_options) { - var base = tools.merge({ - LCB: null, - expr: null, - RCB: null, - }, _options); - - Rule.call(this, base); - - this.LCB = base.LCB; - this.expr = base.expr; - this.RCB = base.RCB; - }, - position: function() { - return { - start: this.LCB.start, - end: this.RCB.end - } - } - }); - - var address_literal_content = std.class([Rule], { - constructor: function address_literal_content(_options) { - var base = tools.merge({}, _options); - - Rule.call(this, base); - } - }); - - var address_literal = std.class([Rule], { - constructor: function address_literal(_options) { - var base = tools.merge({ - keyword: null, - LSB: null, - RSB: null, - }, _options); - - Rule.call(this, base); - - this.keyword = base.keyword; - this.LSB = base.LSB; - this.RSB = base.RSB; - }, - position: function() { - return { - start: this.ADDRESS.start, - end: this.RSB.end - } - } - }); - - var oid_literal_content = std.class([Rule], { - constructor: function oid_literal_content(_options) { - var base = tools.merge({}, _options); - - Rule.call(this, base); - } - }); - - var oid_literal = std.class([Rule], { - constructor: function oid_literal(_options) { - var base = tools.merge({ - keyword: null, - LSB: null, - RSB: null, - }, _options); - - Rule.call(this, base); - - this.keyword = base.keyword; - this.LSB = base.LSB; - this.RSB = base.RSB; - }, - position: function() { - return { - start: this.keyword.start, - end: this.RSB.end - } - } - }); - - var time_diff_literal = std.class([Rule], { - constructor: function time_diff_literal(_options) { - var base = tools.merge({ - keyword: null, - LSB: null, - RSB: null, - days: -1, - hours: -1, - minutes: -1, - seconds: -1, - microseconds: -1 - }, _options); - - Rule.call(this, base); - - this.keyword = base.keyword; - this.LSB = base.LSB; - this.RSB = base.RSB; - this.days = base.days; - this.hours = base.hours; - this.minutes = base.minutes; - this.seconds = base.seconds; - this.microseconds = base.microseconds; - }, - position: function() { - return { - start: this.keyword.start, - end: this.RSB.end - } - } - }); - - - - return { - // terminal - LEXEME: Lexeme, - - // not terminal - id: id, - string_literal: string_literal, - integer_literal: integer_literal, - float_literal: float_literal, - bool_literal: bool_literal, - address_literal: address_literal, - oid_literal: oid_literal, - time_diff_literal: time_diff_literal, - - or: or, - and: and, - not: not, - - eq: eq, - neq: neq, - gt: gt, - gte: gte, - lt: lt, - lte: lte, - like: like, - nlike: nlike, - - // expr: expr, - sub_expr: sub_expr, - address_literal_content: address_literal_content, - oid_literal_content: oid_literal_content, - } - -})(); - - - - -var _result = {}; -var LemonJS = function(_input) { - _result = Object.create(null); - var parser = new Parser(); - var lexer = new Lexer(_input); - var token; - while (token = lexer.next()) { - if (token.error === 0) { - console.log("PARSE", token.lexeme); - parser.parse(parser["TOKEN_" + token.lexeme], token); - } - } - parser.parse(); - return _result; -}; - - -if (!fs.existsSync("tests")) { - fs.mkdirSync("tests"); -} - -var test_and = LemonJS("abc == 1 and abc1 == 2 and (bbc == 5)"); -fs.writeFileSync("tests/test_and.json", JSON.stringify(test_and, true, 3)); - -var test_address = LemonJS('abc == Address ["a", "b", "c"]'); -fs.writeFileSync("tests/test_address.json", JSON.stringify(test_address, true, 3)); - -var test_float = LemonJS('abc == 23.2'); -fs.writeFileSync("tests/test_float.json", JSON.stringify(test_float, true, 3)); - -var test_string = LemonJS('abc == "sadfasdf"'); -fs.writeFileSync("tests/test_string.json", JSON.stringify(test_string, true, 3)); - -var test_bool = LemonJS('abc == true or cab == false'); -fs.writeFileSync("tests/test_bool.json", JSON.stringify(test_bool, true, 3)); - -var test_not = LemonJS('not cab == false'); -fs.writeFileSync("tests/test_not.json", JSON.stringify(test_not, true, 3)); - -var test_oid = LemonJS('abc == Oid [a.b.d]'); -fs.writeFileSync("tests/test_oid.json", JSON.stringify(test_oid, true, 3)); - -var test_timediff = LemonJS('add == TimeDiff [17924 15:01:24 441000]'); -fs.writeFileSync("tests/test_timediff.json", JSON.stringify(test_timediff, true, 3)); - -var test_timediff_single = LemonJS('TimeDiff [17924 15:01:24 441000]'); -fs.writeFileSync("tests/test_timediff_single.json", JSON.stringify(test_timediff_single, true, 3)); \ No newline at end of file diff --git a/parsers/filters/parser.out b/parsers/filters/parser.out deleted file mode 100644 index 8aef67e..0000000 --- a/parsers/filters/parser.out +++ /dev/null @@ -1,784 +0,0 @@ -State 0: - main ::= * expr - main ::= * literal - integer_literal ::= * INTEGER_LITERAL - literal ::= * integer_literal - float_literal ::= * FLOAT_LITERAL - literal ::= * float_literal - bool_literal ::= * BOOL_LITERAL - literal ::= * bool_literal - string_literal ::= * STRING_LITERAL - literal ::= * string_literal - id ::= * string_literal - id ::= * ID - and ::= * expr AND expr - or ::= * expr OR expr - not ::= * NOT expr - eq ::= * id EQ literal - neq ::= * id NEQ literal - gt ::= * id GT literal - gte ::= * id GTE literal - lt ::= * id LT literal - lte ::= * id LTE literal - like ::= * id LIKE literal - nlike ::= * id NLIKE literal - expr ::= * and - expr ::= * or - expr ::= * not - expr ::= * eq - expr ::= * neq - expr ::= * gt - expr ::= * gte - expr ::= * lt - expr ::= * lte - expr ::= * like - expr ::= * nlike - expr ::= * LCB expr RCB - address_literal ::= * ADDRESS LSB address_literal_content_or_empty RSB - literal ::= * address_literal - oid_literal ::= * OID LSB oid_literal_content_or_empty RSB - literal ::= * oid_literal - time_diff_literal ::= * TIMEDIFF LSB integer_literal integer_literal COLON integer_literal COLON integer_literal integer_literal RSB - literal ::= * time_diff_literal - - NOT shift 2 - INTEGER_LITERAL shift-reduce 2 integer_literal ::= INTEGER_LITERAL - FLOAT_LITERAL shift-reduce 4 float_literal ::= FLOAT_LITERAL - BOOL_LITERAL shift-reduce 6 bool_literal ::= BOOL_LITERAL - STRING_LITERAL shift-reduce 8 string_literal ::= STRING_LITERAL - ID shift-reduce 11 id ::= ID - LCB shift 1 - ADDRESS shift 36 - OID shift 33 - TIMEDIFF shift 30 - main accept - expr shift 24 - literal shift 26 - integer_literal shift-reduce 3 literal ::= integer_literal - float_literal shift-reduce 5 literal ::= float_literal - bool_literal shift-reduce 7 literal ::= bool_literal - string_literal shift 25 - id shift 22 - and shift-reduce 23 expr ::= and - or shift-reduce 24 expr ::= or - not shift-reduce 25 expr ::= not - eq shift-reduce 26 expr ::= eq - neq shift-reduce 27 expr ::= neq - gt shift-reduce 28 expr ::= gt - gte shift-reduce 29 expr ::= gte - lt shift-reduce 30 expr ::= lt - lte shift-reduce 31 expr ::= lte - like shift-reduce 32 expr ::= like - nlike shift-reduce 33 expr ::= nlike - address_literal shift-reduce 40 literal ::= address_literal - oid_literal shift-reduce 46 literal ::= oid_literal - time_diff_literal shift-reduce 48 literal ::= time_diff_literal - -State 1: - string_literal ::= * STRING_LITERAL - id ::= * string_literal - id ::= * ID - and ::= * expr AND expr - or ::= * expr OR expr - not ::= * NOT expr - eq ::= * id EQ literal - neq ::= * id NEQ literal - gt ::= * id GT literal - gte ::= * id GTE literal - lt ::= * id LT literal - lte ::= * id LTE literal - like ::= * id LIKE literal - nlike ::= * id NLIKE literal - expr ::= * and - expr ::= * or - expr ::= * not - expr ::= * eq - expr ::= * neq - expr ::= * gt - expr ::= * gte - expr ::= * lt - expr ::= * lte - expr ::= * like - expr ::= * nlike - expr ::= * LCB expr RCB - expr ::= LCB * expr RCB - - NOT shift 2 - STRING_LITERAL shift-reduce 8 string_literal ::= STRING_LITERAL - ID shift-reduce 11 id ::= ID - LCB shift 1 - expr shift 23 - string_literal shift-reduce 10 id ::= string_literal - id shift 22 - and shift-reduce 23 expr ::= and - or shift-reduce 24 expr ::= or - not shift-reduce 25 expr ::= not - eq shift-reduce 26 expr ::= eq - neq shift-reduce 27 expr ::= neq - gt shift-reduce 28 expr ::= gt - gte shift-reduce 29 expr ::= gte - lt shift-reduce 30 expr ::= lt - lte shift-reduce 31 expr ::= lte - like shift-reduce 32 expr ::= like - nlike shift-reduce 33 expr ::= nlike - -State 2: - string_literal ::= * STRING_LITERAL - id ::= * string_literal - id ::= * ID - and ::= * expr AND expr - or ::= * expr OR expr - not ::= * NOT expr - not ::= NOT * expr - eq ::= * id EQ literal - neq ::= * id NEQ literal - gt ::= * id GT literal - gte ::= * id GTE literal - lt ::= * id LT literal - lte ::= * id LTE literal - like ::= * id LIKE literal - nlike ::= * id NLIKE literal - expr ::= * and - expr ::= * or - expr ::= * not - expr ::= * eq - expr ::= * neq - expr ::= * gt - expr ::= * gte - expr ::= * lt - expr ::= * lte - expr ::= * like - expr ::= * nlike - expr ::= * LCB expr RCB - - NOT shift 2 - STRING_LITERAL shift-reduce 8 string_literal ::= STRING_LITERAL - ID shift-reduce 11 id ::= ID - LCB shift 1 - expr shift-reduce 14 not ::= NOT expr - string_literal shift-reduce 10 id ::= string_literal - id shift 22 - and shift-reduce 23 expr ::= and - or shift-reduce 24 expr ::= or - not shift-reduce 25 expr ::= not - eq shift-reduce 26 expr ::= eq - neq shift-reduce 27 expr ::= neq - gt shift-reduce 28 expr ::= gt - gte shift-reduce 29 expr ::= gte - lt shift-reduce 30 expr ::= lt - lte shift-reduce 31 expr ::= lte - like shift-reduce 32 expr ::= like - nlike shift-reduce 33 expr ::= nlike - -State 3: - string_literal ::= * STRING_LITERAL - id ::= * string_literal - id ::= * ID - and ::= * expr AND expr - or ::= * expr OR expr - or ::= expr OR * expr - not ::= * NOT expr - eq ::= * id EQ literal - neq ::= * id NEQ literal - gt ::= * id GT literal - gte ::= * id GTE literal - lt ::= * id LT literal - lte ::= * id LTE literal - like ::= * id LIKE literal - nlike ::= * id NLIKE literal - expr ::= * and - expr ::= * or - expr ::= * not - expr ::= * eq - expr ::= * neq - expr ::= * gt - expr ::= * gte - expr ::= * lt - expr ::= * lte - expr ::= * like - expr ::= * nlike - expr ::= * LCB expr RCB - - NOT shift 2 - STRING_LITERAL shift-reduce 8 string_literal ::= STRING_LITERAL - ID shift-reduce 11 id ::= ID - LCB shift 1 - expr shift 37 - string_literal shift-reduce 10 id ::= string_literal - id shift 22 - and shift-reduce 23 expr ::= and - or shift-reduce 24 expr ::= or - not shift-reduce 25 expr ::= not - eq shift-reduce 26 expr ::= eq - neq shift-reduce 27 expr ::= neq - gt shift-reduce 28 expr ::= gt - gte shift-reduce 29 expr ::= gte - lt shift-reduce 30 expr ::= lt - lte shift-reduce 31 expr ::= lte - like shift-reduce 32 expr ::= like - nlike shift-reduce 33 expr ::= nlike - -State 4: - string_literal ::= * STRING_LITERAL - id ::= * string_literal - id ::= * ID - and ::= * expr AND expr - and ::= expr AND * expr - or ::= * expr OR expr - not ::= * NOT expr - eq ::= * id EQ literal - neq ::= * id NEQ literal - gt ::= * id GT literal - gte ::= * id GTE literal - lt ::= * id LT literal - lte ::= * id LTE literal - like ::= * id LIKE literal - nlike ::= * id NLIKE literal - expr ::= * and - expr ::= * or - expr ::= * not - expr ::= * eq - expr ::= * neq - expr ::= * gt - expr ::= * gte - expr ::= * lt - expr ::= * lte - expr ::= * like - expr ::= * nlike - expr ::= * LCB expr RCB - - NOT shift 2 - STRING_LITERAL shift-reduce 8 string_literal ::= STRING_LITERAL - ID shift-reduce 11 id ::= ID - LCB shift 1 - expr shift-reduce 12 and ::= expr AND expr - string_literal shift-reduce 10 id ::= string_literal - id shift 22 - and shift-reduce 23 expr ::= and - or shift-reduce 24 expr ::= or - not shift-reduce 25 expr ::= not - eq shift-reduce 26 expr ::= eq - neq shift-reduce 27 expr ::= neq - gt shift-reduce 28 expr ::= gt - gte shift-reduce 29 expr ::= gte - lt shift-reduce 30 expr ::= lt - lte shift-reduce 31 expr ::= lte - like shift-reduce 32 expr ::= like - nlike shift-reduce 33 expr ::= nlike - -State 5: - integer_literal ::= * INTEGER_LITERAL - literal ::= * integer_literal - float_literal ::= * FLOAT_LITERAL - literal ::= * float_literal - bool_literal ::= * BOOL_LITERAL - literal ::= * bool_literal - string_literal ::= * STRING_LITERAL - literal ::= * string_literal - nlike ::= id NLIKE * literal - address_literal ::= * ADDRESS LSB address_literal_content_or_empty RSB - literal ::= * address_literal - oid_literal ::= * OID LSB oid_literal_content_or_empty RSB - literal ::= * oid_literal - time_diff_literal ::= * TIMEDIFF LSB integer_literal integer_literal COLON integer_literal COLON integer_literal integer_literal RSB - literal ::= * time_diff_literal - - INTEGER_LITERAL shift-reduce 2 integer_literal ::= INTEGER_LITERAL - FLOAT_LITERAL shift-reduce 4 float_literal ::= FLOAT_LITERAL - BOOL_LITERAL shift-reduce 6 bool_literal ::= BOOL_LITERAL - STRING_LITERAL shift-reduce 8 string_literal ::= STRING_LITERAL - ADDRESS shift 36 - OID shift 33 - TIMEDIFF shift 30 - literal shift-reduce 22 nlike ::= id NLIKE literal - integer_literal shift-reduce 3 literal ::= integer_literal - float_literal shift-reduce 5 literal ::= float_literal - bool_literal shift-reduce 7 literal ::= bool_literal - string_literal shift-reduce 9 literal ::= string_literal - address_literal shift-reduce 40 literal ::= address_literal - oid_literal shift-reduce 46 literal ::= oid_literal - time_diff_literal shift-reduce 48 literal ::= time_diff_literal - -State 6: - integer_literal ::= * INTEGER_LITERAL - literal ::= * integer_literal - float_literal ::= * FLOAT_LITERAL - literal ::= * float_literal - bool_literal ::= * BOOL_LITERAL - literal ::= * bool_literal - string_literal ::= * STRING_LITERAL - literal ::= * string_literal - like ::= id LIKE * literal - address_literal ::= * ADDRESS LSB address_literal_content_or_empty RSB - literal ::= * address_literal - oid_literal ::= * OID LSB oid_literal_content_or_empty RSB - literal ::= * oid_literal - time_diff_literal ::= * TIMEDIFF LSB integer_literal integer_literal COLON integer_literal COLON integer_literal integer_literal RSB - literal ::= * time_diff_literal - - INTEGER_LITERAL shift-reduce 2 integer_literal ::= INTEGER_LITERAL - FLOAT_LITERAL shift-reduce 4 float_literal ::= FLOAT_LITERAL - BOOL_LITERAL shift-reduce 6 bool_literal ::= BOOL_LITERAL - STRING_LITERAL shift-reduce 8 string_literal ::= STRING_LITERAL - ADDRESS shift 36 - OID shift 33 - TIMEDIFF shift 30 - literal shift-reduce 21 like ::= id LIKE literal - integer_literal shift-reduce 3 literal ::= integer_literal - float_literal shift-reduce 5 literal ::= float_literal - bool_literal shift-reduce 7 literal ::= bool_literal - string_literal shift-reduce 9 literal ::= string_literal - address_literal shift-reduce 40 literal ::= address_literal - oid_literal shift-reduce 46 literal ::= oid_literal - time_diff_literal shift-reduce 48 literal ::= time_diff_literal - -State 7: - integer_literal ::= * INTEGER_LITERAL - literal ::= * integer_literal - float_literal ::= * FLOAT_LITERAL - literal ::= * float_literal - bool_literal ::= * BOOL_LITERAL - literal ::= * bool_literal - string_literal ::= * STRING_LITERAL - literal ::= * string_literal - lte ::= id LTE * literal - address_literal ::= * ADDRESS LSB address_literal_content_or_empty RSB - literal ::= * address_literal - oid_literal ::= * OID LSB oid_literal_content_or_empty RSB - literal ::= * oid_literal - time_diff_literal ::= * TIMEDIFF LSB integer_literal integer_literal COLON integer_literal COLON integer_literal integer_literal RSB - literal ::= * time_diff_literal - - INTEGER_LITERAL shift-reduce 2 integer_literal ::= INTEGER_LITERAL - FLOAT_LITERAL shift-reduce 4 float_literal ::= FLOAT_LITERAL - BOOL_LITERAL shift-reduce 6 bool_literal ::= BOOL_LITERAL - STRING_LITERAL shift-reduce 8 string_literal ::= STRING_LITERAL - ADDRESS shift 36 - OID shift 33 - TIMEDIFF shift 30 - literal shift-reduce 20 lte ::= id LTE literal - integer_literal shift-reduce 3 literal ::= integer_literal - float_literal shift-reduce 5 literal ::= float_literal - bool_literal shift-reduce 7 literal ::= bool_literal - string_literal shift-reduce 9 literal ::= string_literal - address_literal shift-reduce 40 literal ::= address_literal - oid_literal shift-reduce 46 literal ::= oid_literal - time_diff_literal shift-reduce 48 literal ::= time_diff_literal - -State 8: - integer_literal ::= * INTEGER_LITERAL - literal ::= * integer_literal - float_literal ::= * FLOAT_LITERAL - literal ::= * float_literal - bool_literal ::= * BOOL_LITERAL - literal ::= * bool_literal - string_literal ::= * STRING_LITERAL - literal ::= * string_literal - lt ::= id LT * literal - address_literal ::= * ADDRESS LSB address_literal_content_or_empty RSB - literal ::= * address_literal - oid_literal ::= * OID LSB oid_literal_content_or_empty RSB - literal ::= * oid_literal - time_diff_literal ::= * TIMEDIFF LSB integer_literal integer_literal COLON integer_literal COLON integer_literal integer_literal RSB - literal ::= * time_diff_literal - - INTEGER_LITERAL shift-reduce 2 integer_literal ::= INTEGER_LITERAL - FLOAT_LITERAL shift-reduce 4 float_literal ::= FLOAT_LITERAL - BOOL_LITERAL shift-reduce 6 bool_literal ::= BOOL_LITERAL - STRING_LITERAL shift-reduce 8 string_literal ::= STRING_LITERAL - ADDRESS shift 36 - OID shift 33 - TIMEDIFF shift 30 - literal shift-reduce 19 lt ::= id LT literal - integer_literal shift-reduce 3 literal ::= integer_literal - float_literal shift-reduce 5 literal ::= float_literal - bool_literal shift-reduce 7 literal ::= bool_literal - string_literal shift-reduce 9 literal ::= string_literal - address_literal shift-reduce 40 literal ::= address_literal - oid_literal shift-reduce 46 literal ::= oid_literal - time_diff_literal shift-reduce 48 literal ::= time_diff_literal - -State 9: - integer_literal ::= * INTEGER_LITERAL - literal ::= * integer_literal - float_literal ::= * FLOAT_LITERAL - literal ::= * float_literal - bool_literal ::= * BOOL_LITERAL - literal ::= * bool_literal - string_literal ::= * STRING_LITERAL - literal ::= * string_literal - gte ::= id GTE * literal - address_literal ::= * ADDRESS LSB address_literal_content_or_empty RSB - literal ::= * address_literal - oid_literal ::= * OID LSB oid_literal_content_or_empty RSB - literal ::= * oid_literal - time_diff_literal ::= * TIMEDIFF LSB integer_literal integer_literal COLON integer_literal COLON integer_literal integer_literal RSB - literal ::= * time_diff_literal - - INTEGER_LITERAL shift-reduce 2 integer_literal ::= INTEGER_LITERAL - FLOAT_LITERAL shift-reduce 4 float_literal ::= FLOAT_LITERAL - BOOL_LITERAL shift-reduce 6 bool_literal ::= BOOL_LITERAL - STRING_LITERAL shift-reduce 8 string_literal ::= STRING_LITERAL - ADDRESS shift 36 - OID shift 33 - TIMEDIFF shift 30 - literal shift-reduce 18 gte ::= id GTE literal - integer_literal shift-reduce 3 literal ::= integer_literal - float_literal shift-reduce 5 literal ::= float_literal - bool_literal shift-reduce 7 literal ::= bool_literal - string_literal shift-reduce 9 literal ::= string_literal - address_literal shift-reduce 40 literal ::= address_literal - oid_literal shift-reduce 46 literal ::= oid_literal - time_diff_literal shift-reduce 48 literal ::= time_diff_literal - -State 10: - integer_literal ::= * INTEGER_LITERAL - literal ::= * integer_literal - float_literal ::= * FLOAT_LITERAL - literal ::= * float_literal - bool_literal ::= * BOOL_LITERAL - literal ::= * bool_literal - string_literal ::= * STRING_LITERAL - literal ::= * string_literal - gt ::= id GT * literal - address_literal ::= * ADDRESS LSB address_literal_content_or_empty RSB - literal ::= * address_literal - oid_literal ::= * OID LSB oid_literal_content_or_empty RSB - literal ::= * oid_literal - time_diff_literal ::= * TIMEDIFF LSB integer_literal integer_literal COLON integer_literal COLON integer_literal integer_literal RSB - literal ::= * time_diff_literal - - INTEGER_LITERAL shift-reduce 2 integer_literal ::= INTEGER_LITERAL - FLOAT_LITERAL shift-reduce 4 float_literal ::= FLOAT_LITERAL - BOOL_LITERAL shift-reduce 6 bool_literal ::= BOOL_LITERAL - STRING_LITERAL shift-reduce 8 string_literal ::= STRING_LITERAL - ADDRESS shift 36 - OID shift 33 - TIMEDIFF shift 30 - literal shift-reduce 17 gt ::= id GT literal - integer_literal shift-reduce 3 literal ::= integer_literal - float_literal shift-reduce 5 literal ::= float_literal - bool_literal shift-reduce 7 literal ::= bool_literal - string_literal shift-reduce 9 literal ::= string_literal - address_literal shift-reduce 40 literal ::= address_literal - oid_literal shift-reduce 46 literal ::= oid_literal - time_diff_literal shift-reduce 48 literal ::= time_diff_literal - -State 11: - integer_literal ::= * INTEGER_LITERAL - literal ::= * integer_literal - float_literal ::= * FLOAT_LITERAL - literal ::= * float_literal - bool_literal ::= * BOOL_LITERAL - literal ::= * bool_literal - string_literal ::= * STRING_LITERAL - literal ::= * string_literal - neq ::= id NEQ * literal - address_literal ::= * ADDRESS LSB address_literal_content_or_empty RSB - literal ::= * address_literal - oid_literal ::= * OID LSB oid_literal_content_or_empty RSB - literal ::= * oid_literal - time_diff_literal ::= * TIMEDIFF LSB integer_literal integer_literal COLON integer_literal COLON integer_literal integer_literal RSB - literal ::= * time_diff_literal - - INTEGER_LITERAL shift-reduce 2 integer_literal ::= INTEGER_LITERAL - FLOAT_LITERAL shift-reduce 4 float_literal ::= FLOAT_LITERAL - BOOL_LITERAL shift-reduce 6 bool_literal ::= BOOL_LITERAL - STRING_LITERAL shift-reduce 8 string_literal ::= STRING_LITERAL - ADDRESS shift 36 - OID shift 33 - TIMEDIFF shift 30 - literal shift-reduce 16 neq ::= id NEQ literal - integer_literal shift-reduce 3 literal ::= integer_literal - float_literal shift-reduce 5 literal ::= float_literal - bool_literal shift-reduce 7 literal ::= bool_literal - string_literal shift-reduce 9 literal ::= string_literal - address_literal shift-reduce 40 literal ::= address_literal - oid_literal shift-reduce 46 literal ::= oid_literal - time_diff_literal shift-reduce 48 literal ::= time_diff_literal - -State 12: - integer_literal ::= * INTEGER_LITERAL - literal ::= * integer_literal - float_literal ::= * FLOAT_LITERAL - literal ::= * float_literal - bool_literal ::= * BOOL_LITERAL - literal ::= * bool_literal - string_literal ::= * STRING_LITERAL - literal ::= * string_literal - eq ::= id EQ * literal - address_literal ::= * ADDRESS LSB address_literal_content_or_empty RSB - literal ::= * address_literal - oid_literal ::= * OID LSB oid_literal_content_or_empty RSB - literal ::= * oid_literal - time_diff_literal ::= * TIMEDIFF LSB integer_literal integer_literal COLON integer_literal COLON integer_literal integer_literal RSB - literal ::= * time_diff_literal - - INTEGER_LITERAL shift-reduce 2 integer_literal ::= INTEGER_LITERAL - FLOAT_LITERAL shift-reduce 4 float_literal ::= FLOAT_LITERAL - BOOL_LITERAL shift-reduce 6 bool_literal ::= BOOL_LITERAL - STRING_LITERAL shift-reduce 8 string_literal ::= STRING_LITERAL - ADDRESS shift 36 - OID shift 33 - TIMEDIFF shift 30 - literal shift-reduce 15 eq ::= id EQ literal - integer_literal shift-reduce 3 literal ::= integer_literal - float_literal shift-reduce 5 literal ::= float_literal - bool_literal shift-reduce 7 literal ::= bool_literal - string_literal shift-reduce 9 literal ::= string_literal - address_literal shift-reduce 40 literal ::= address_literal - oid_literal shift-reduce 46 literal ::= oid_literal - time_diff_literal shift-reduce 48 literal ::= time_diff_literal - -State 13: - string_literal ::= * STRING_LITERAL - id ::= * string_literal - id ::= * ID - oid_literal_content ::= * id - oid_literal_content ::= * oid_literal_content DOT id - oid_literal_content_or_empty ::= * oid_literal_content - (44) oid_literal_content_or_empty ::= * - oid_literal ::= OID LSB * oid_literal_content_or_empty RSB - - STRING_LITERAL shift-reduce 8 string_literal ::= STRING_LITERAL - ID shift-reduce 11 id ::= ID - string_literal shift-reduce 10 id ::= string_literal - id shift-reduce 41 oid_literal_content ::= id - oid_literal_content shift 32 - oid_literal_content_or_empty shift 31 - {default} reduce 44 oid_literal_content_or_empty ::= - -State 14: - string_literal ::= * STRING_LITERAL - address_literal_content ::= * string_literal - address_literal_content ::= * address_literal_content COMMA string_literal - address_literal_content_or_empty ::= * address_literal_content - (38) address_literal_content_or_empty ::= * - address_literal ::= ADDRESS LSB * address_literal_content_or_empty RSB - - STRING_LITERAL shift-reduce 8 string_literal ::= STRING_LITERAL - string_literal shift-reduce 35 address_literal_content ::= string_literal - address_literal_content shift 35 -address_literal_content_or_empty shift 34 - {default} reduce 38 address_literal_content_or_empty ::= - -State 15: - string_literal ::= * STRING_LITERAL - id ::= * string_literal - id ::= * ID - oid_literal_content ::= oid_literal_content DOT * id - - STRING_LITERAL shift-reduce 8 string_literal ::= STRING_LITERAL - ID shift-reduce 11 id ::= ID - string_literal shift-reduce 10 id ::= string_literal - id shift-reduce 42 oid_literal_content ::= oid_literal_content DOT id - -State 16: - integer_literal ::= * INTEGER_LITERAL - time_diff_literal ::= TIMEDIFF LSB integer_literal integer_literal COLON integer_literal COLON integer_literal * integer_literal RSB - - INTEGER_LITERAL shift-reduce 2 integer_literal ::= INTEGER_LITERAL - integer_literal shift 27 - -State 17: - integer_literal ::= * INTEGER_LITERAL - time_diff_literal ::= TIMEDIFF LSB integer_literal integer_literal COLON integer_literal COLON * integer_literal integer_literal RSB - - INTEGER_LITERAL shift-reduce 2 integer_literal ::= INTEGER_LITERAL - integer_literal shift 16 - -State 18: - integer_literal ::= * INTEGER_LITERAL - time_diff_literal ::= TIMEDIFF LSB integer_literal integer_literal COLON * integer_literal COLON integer_literal integer_literal RSB - - INTEGER_LITERAL shift-reduce 2 integer_literal ::= INTEGER_LITERAL - integer_literal shift 28 - -State 19: - integer_literal ::= * INTEGER_LITERAL - time_diff_literal ::= TIMEDIFF LSB integer_literal * integer_literal COLON integer_literal COLON integer_literal integer_literal RSB - - INTEGER_LITERAL shift-reduce 2 integer_literal ::= INTEGER_LITERAL - integer_literal shift 29 - -State 20: - integer_literal ::= * INTEGER_LITERAL - time_diff_literal ::= TIMEDIFF LSB * integer_literal integer_literal COLON integer_literal COLON integer_literal integer_literal RSB - - INTEGER_LITERAL shift-reduce 2 integer_literal ::= INTEGER_LITERAL - integer_literal shift 19 - -State 21: - string_literal ::= * STRING_LITERAL - address_literal_content ::= address_literal_content COMMA * string_literal - - STRING_LITERAL shift-reduce 8 string_literal ::= STRING_LITERAL - string_literal shift-reduce 36 address_literal_content ::= address_literal_content COMMA string_literal - -State 22: - eq ::= id * EQ literal - neq ::= id * NEQ literal - gt ::= id * GT literal - gte ::= id * GTE literal - lt ::= id * LT literal - lte ::= id * LTE literal - like ::= id * LIKE literal - nlike ::= id * NLIKE literal - - EQ shift 12 - NEQ shift 11 - GT shift 10 - GTE shift 9 - LT shift 8 - LTE shift 7 - LIKE shift 6 - NLIKE shift 5 - -State 23: - and ::= expr * AND expr - or ::= expr * OR expr - expr ::= LCB expr * RCB - - OR shift 3 - AND shift 4 - RCB shift-reduce 34 expr ::= LCB expr RCB - -State 24: - (0) main ::= expr * - and ::= expr * AND expr - or ::= expr * OR expr - - $ reduce 0 main ::= expr - OR shift 3 - AND shift 4 - -State 25: - (9) literal ::= string_literal * - (10) id ::= string_literal * - - $ reduce 9 literal ::= string_literal - {default} reduce 10 id ::= string_literal - -State 26: - (1) main ::= literal * - - $ reduce 1 main ::= literal - -State 27: - time_diff_literal ::= TIMEDIFF LSB integer_literal integer_literal COLON integer_literal COLON integer_literal integer_literal * RSB - - RSB shift-reduce 47 time_diff_literal ::= TIMEDIFF LSB integer_literal integer_literal COLON integer_literal COLON integer_literal integer_literal RSB - -State 28: - time_diff_literal ::= TIMEDIFF LSB integer_literal integer_literal COLON integer_literal * COLON integer_literal integer_literal RSB - - COLON shift 17 - -State 29: - time_diff_literal ::= TIMEDIFF LSB integer_literal integer_literal * COLON integer_literal COLON integer_literal integer_literal RSB - - COLON shift 18 - -State 30: - time_diff_literal ::= TIMEDIFF * LSB integer_literal integer_literal COLON integer_literal COLON integer_literal integer_literal RSB - - LSB shift 20 - -State 31: - oid_literal ::= OID LSB oid_literal_content_or_empty * RSB - - RSB shift-reduce 45 oid_literal ::= OID LSB oid_literal_content_or_empty RSB - -State 32: - oid_literal_content ::= oid_literal_content * DOT id - (43) oid_literal_content_or_empty ::= oid_literal_content * - - DOT shift 15 - {default} reduce 43 oid_literal_content_or_empty ::= oid_literal_content - -State 33: - oid_literal ::= OID * LSB oid_literal_content_or_empty RSB - - LSB shift 13 - -State 34: - address_literal ::= ADDRESS LSB address_literal_content_or_empty * RSB - - RSB shift-reduce 39 address_literal ::= ADDRESS LSB address_literal_content_or_empty RSB - -State 35: - address_literal_content ::= address_literal_content * COMMA string_literal - (37) address_literal_content_or_empty ::= address_literal_content * - - COMMA shift 21 - {default} reduce 37 address_literal_content_or_empty ::= address_literal_content - -State 36: - address_literal ::= ADDRESS * LSB address_literal_content_or_empty RSB - - LSB shift 14 - -State 37: - and ::= expr * AND expr - or ::= expr * OR expr - (13) or ::= expr OR expr * - - AND shift 4 - {default} reduce 13 or ::= expr OR expr - ----------------------------------------------------- -Symbols: - 0: $: - 1: OR - 2: AND - 3: NOT - 4: INTEGER_LITERAL - 5: FLOAT_LITERAL - 6: BOOL_LITERAL - 7: STRING_LITERAL - 8: ID - 9: EQ - 10: NEQ - 11: GT - 12: GTE - 13: LT - 14: LTE - 15: LIKE - 16: NLIKE - 17: LCB - 18: RCB - 19: COMMA - 20: ADDRESS - 21: LSB - 22: RSB - 23: DOT - 24: OID - 25: TIMEDIFF - 26: COLON - 27: error: - 28: main: NOT INTEGER_LITERAL FLOAT_LITERAL BOOL_LITERAL STRING_LITERAL ID LCB ADDRESS OID TIMEDIFF - 29: expr: NOT STRING_LITERAL ID LCB - 30: literal: INTEGER_LITERAL FLOAT_LITERAL BOOL_LITERAL STRING_LITERAL ADDRESS OID TIMEDIFF - 31: integer_literal: INTEGER_LITERAL - 32: float_literal: FLOAT_LITERAL - 33: bool_literal: BOOL_LITERAL - 34: string_literal: STRING_LITERAL - 35: id: STRING_LITERAL ID - 36: and: NOT STRING_LITERAL ID LCB - 37: or: NOT STRING_LITERAL ID LCB - 38: not: NOT - 39: eq: STRING_LITERAL ID - 40: neq: STRING_LITERAL ID - 41: gt: STRING_LITERAL ID - 42: gte: STRING_LITERAL ID - 43: lt: STRING_LITERAL ID - 44: lte: STRING_LITERAL ID - 45: like: STRING_LITERAL ID - 46: nlike: STRING_LITERAL ID - 47: address_literal_content: STRING_LITERAL - 48: address_literal_content_or_empty: STRING_LITERAL - 49: address_literal: ADDRESS - 50: oid_literal_content: STRING_LITERAL ID - 51: oid_literal_content_or_empty: STRING_LITERAL ID - 52: oid_literal: OID - 53: time_diff_literal: TIMEDIFF diff --git a/parsers/filters/parser.y b/parsers/filters/parser.y index deb40be..7a414b1 100644 --- a/parsers/filters/parser.y +++ b/parsers/filters/parser.y @@ -11,7 +11,29 @@ } %code { - &&REPLACER{process.js}&& + &&REPLACER{parsers/filters/test_code_environment.js}&& + + var _result = {}; + var LemonJS = function(_input) { + _result = Object.create(null); + var parser = new Parser(); + var lexer = new Lexer(_input); + var token; + var lexemes = []; + while (token = lexer.next()) { + if (token.error === 0) { + console.log("PARSE", token.lexeme); + parser.parse(parser["TOKEN_" + token.lexeme], token); + lexemes.push(token); + } + } + parser.parse(); + + return { + tree: _result.root_node, + lexemes: lexemes + }; + }; } %syntax_error { @@ -447,3 +469,36 @@ literal(A) ::= time_diff_literal(B) . { A = B; } +time_literal(A) ::= TIME(KWD) LSB(B) integer_literal(DAY) SLASH integer_literal(MONTH) SLASH integer_literal(YEAR) integer_literal(HH) COLON integer_literal(MM) COLON integer_literal(SS) integer_literal(MS) RSB(C) . { + A = new tokens.time_literal({ + keyword: new tokens.LEXEME({ + type: KWD.lexeme, + value: KWD.value, + start: KWD.start, + end: KWD.end + }), + LSB: new tokens.LEXEME({ + type: B.lexeme, + value: B.value, + start: B.start, + end: B.end + }), + RSB: new tokens.LEXEME({ + type: C.lexeme, + value: C.value, + start: C.start, + end: C.end + }), + day: DAY, + month: MONTH, + year: YEAR, + hours: HH, + minutes: MM, + seconds: SS, + microseconds: MS, + }); +} + +literal(A) ::= time_literal(B) . { + A = B; +} \ No newline at end of file diff --git a/process.js b/parsers/filters/real_code_environment.js similarity index 61% rename from process.js rename to parsers/filters/real_code_environment.js index fd36e18..922998b 100644 --- a/process.js +++ b/parsers/filters/real_code_environment.js @@ -5,29 +5,38 @@ var fs = require("fs"); var Lexer = require('./lexer.js'); -var tokens = (function () { - - var std = (function () { - var protos = "__protos__"; - var keys = "__keys__"; +var std = (function () { + var protos = "__protos__"; + var keys = "__keys__"; - /** - * Return unique data - * - * @param {Object[]} _arr - prototypes of inheritance classes - * @param {Object} _main - prototype of resulting class - * - * @return {Object} - * */ - var unique = function (_arr, _main) { - var result = Object.create(null); - var to_remove = []; + /** + * Return unique data + * + * @param {Object[]} _arr - prototypes of inheritance classes + * @param {Object} _main - prototype of resulting class + * + * @return {Object} + * */ + var unique = function (_arr, _main) { + var result = Object.create(null); + var to_remove = []; - for (var i = 0, e = _arr.length; i != e; ++i) { - var item = _arr[i]; + for (var i = 0, e = _arr.length; i != e; ++i) { + var item = _arr[i]; - for (var key in item) { + for (var key in item) { + if (key in result) { + to_remove.push(key); + continue; + } + + result[key] = item[key]; + } + + if (keys in item) { + for (var ii = 0, ee = item[keys].length; ii != ee; ++ii) { + var key = item[keys][ii]; if (key in result) { to_remove.push(key); continue; @@ -35,169 +44,159 @@ var tokens = (function () { result[key] = item[key]; } + } + } - if (keys in item) { - for (var ii = 0, ee = item[keys].length; ii != ee; ++ii) { - var key = item[keys][ii]; - if (key in result) { - to_remove.push(key); - continue; - } + for (var i = 0; i != to_remove.length; ++i) { + delete result[to_remove[i]]; + } - result[key] = item[key]; - } + for (var key in _main) { + result[key] = _main[key]; + } + + return result; + }; + + /** + * Create OOP class + * + * @param {Function[]} _constrs - inheritance classes + * @param {Object} _proto - prototype of resulting class + * @param {Object?} _static - static data + * + * @return {Function} + * */ + var class_creator = function (_constrs, _proto, _static) { + _constrs = _constrs || []; + _proto = _proto || []; + _static = _static || []; + + var constr; + if (_proto && _proto.hasOwnProperty("constructor")) { + constr = _proto.constructor; + delete _proto.constructor; + } else { + constr = function () { + for (var i = 0; i != _constrs.length; ++i) { + _constrs[i].apply(this, arguments); } - } + }; + } - for (var i = 0; i != to_remove.length; ++i) { - delete result[to_remove[i]]; - } + var proto = Object.create(null); + Object.defineProperty(proto, protos, { + "value": [] + }); + Object.defineProperty(proto, keys, { + "value": [] + }); - for (var key in _main) { - result[key] = _main[key]; - } + /************************FOR MEMBERS*******************************/ + for (var i = 0, e = _constrs.length; i != e; ++i) { + proto[protos].push(_constrs[i].prototype); + } - return result; - }; + var m_un = unique(proto[protos], _proto); + for (var key in m_un) { + proto[keys].push(key); - /** - * Create OOP class - * - * @param {Function[]} _constrs - inheritance classes - * @param {Object} _proto - prototype of resulting class - * @param {Object?} _static - static data - * - * @return {Function} - * */ - var class_creator = function (_constrs, _proto, _static) { - _constrs = _constrs || []; - _proto = _proto || []; - _static = _static || []; - - var constr; - if (_proto && _proto.hasOwnProperty("constructor")) { - constr = _proto.constructor; - delete _proto.constructor; - } else { - constr = function () { - for (var i = 0; i != _constrs.length; ++i) { - _constrs[i].apply(this, arguments); - } - }; - } - - var proto = Object.create(null); - Object.defineProperty(proto, protos, { - "value": [] + Object.defineProperty(proto, key, { + "value": m_un[key] }); - Object.defineProperty(proto, keys, { - "value": [] + } + /************************FOR MEMBERS END***************************/ + + /************************FOR STATICS*******************************/ + var s_un = unique(_constrs, _static); + for (var key in s_un) { + Object.defineProperty(constr, key, { + "value": s_un[key], + "enumerable": true }); + } + /************************FOR STATICS END***************************/ - /************************FOR MEMBERS*******************************/ - for (var i = 0, e = _constrs.length; i != e; ++i) { - proto[protos].push(_constrs[i].prototype); + + Object.defineProperties(constr, { + "pr": { + "value": proto + }, + "prototype": { + "value": proto } + }); - var m_un = unique(proto[protos], _proto); - for (var key in m_un) { - proto[keys].push(key); + Object.freeze(proto); + Object.freeze(constr); - Object.defineProperty(proto, key, { - "value": m_un[key] - }); - } - /************************FOR MEMBERS END***************************/ + return constr; + }; - /************************FOR STATICS*******************************/ - var s_un = unique(_constrs, _static); - for (var key in s_un) { - Object.defineProperty(constr, key, { - "value": s_un[key], - "enumerable": true - }); - } - /************************FOR STATICS END***************************/ - - - Object.defineProperties(constr, { - "pr": { - "value": proto - }, - "prototype": { - "value": proto - } - }); - - Object.freeze(proto); - Object.freeze(constr); - - return constr; - }; - - /** - * Check if target has prototype - * - * @param {Object} _target - checkable instance - * @param {Object} _proto - posible prototype - * - * */ - var check = function (_target, _proto) { - for (var i = 0; i != _target[protos].length; ++i) { - var t_proto = _target[protos][i]; - if (t_proto == _proto) { - return true; - } - - if (t_proto[protos]) { - if (check(t_proto, _proto)) - return true; - } - } - - return false; - }; - - /** - * Check if target is instance of class - * - * @param {Object} _target - checkable instance - * @param {Function} _constr - posible constructor - * - * */ - var class_check = function (_target, _constr) { - if (_target instanceof _constr) { + /** + * Check if target has prototype + * + * @param {Object} _target - checkable instance + * @param {Object} _proto - posible prototype + * + * */ + var check = function (_target, _proto) { + for (var i = 0; i != _target[protos].length; ++i) { + var t_proto = _target[protos][i]; + if (t_proto == _proto) { return true; } - return check(_target, _constr.prototype); - }; - - return { - class: class_creator, - class_check: class_check - }; - })(); - - var tools = { - merge: function (_obj) { - var target = Object.create(null); - var i = 0, e = arguments.length; - for (; i != e; ++i) { - var options = arguments[i]; - - for (var key in options) { - if (options[key] === undefined && target === options[key]) - continue; - - target[key] = options[key]; - } + if (t_proto[protos]) { + if (check(t_proto, _proto)) + return true; } - - return target; } + + return false; }; + /** + * Check if target is instance of class + * + * @param {Object} _target - checkable instance + * @param {Function} _constr - posible constructor + * + * */ + var class_check = function (_target, _constr) { + if (_target instanceof _constr) { + return true; + } + + return check(_target, _constr.prototype); + }; + + return { + class: class_creator, + class_check: class_check + }; +})(); + +var tools = { + merge: function (_obj) { + var target = Object.create(null); + var i = 0, e = arguments.length; + for (; i != e; ++i) { + var options = arguments[i]; + + for (var key in options) { + if (options[key] === undefined && target === options[key]) + continue; + + target[key] = options[key]; + } + } + + return target; + } +}; + +var tokens = (function () { var Node = std.class([], { constructor: function Node(_options) { var base = tools.merge({ @@ -496,7 +495,7 @@ var tokens = (function () { }, position: function () { return { - start: this.ADDRESS.start, + start: this.keyword.start, end: this.RSB.end } } @@ -564,7 +563,41 @@ var tokens = (function () { } }); + var time_literal = std.class([Rule], { + constructor: function time_literal(_options) { + var base = tools.merge({ + keyword: null, + LSB: null, + RSB: null, + day: -1, + month: -1, + year: -1, + hours: -1, + minutes: -1, + seconds: -1, + microseconds: -1 + }, _options); + Rule.call(this, base); + + this.keyword = base.keyword; + this.LSB = base.LSB; + this.RSB = base.RSB; + this.day = base.day; + this.month = base.month; + this.year = base.year; + this.hours = base.hours; + this.minutes = base.minutes; + this.seconds = base.seconds; + this.microseconds = base.microseconds; + }, + position: function () { + return { + start: this.keyword.start, + end: this.RSB.end + } + } + }); return { // terminal @@ -579,6 +612,7 @@ var tokens = (function () { address_literal: address_literal, oid_literal: oid_literal, time_diff_literal: time_diff_literal, + time_literal: time_literal, or: or, and: and, @@ -599,55 +633,4 @@ var tokens = (function () { oid_literal_content: oid_literal_content, } -})(); - - - - -var _result = {}; -var LemonJS = function (_input) { - _result = Object.create(null); - var parser = new Parser(); - var lexer = new Lexer(_input); - var token; - while (token = lexer.next()) { - if(token.error === 0) { - console.log("PARSE", token.lexeme); - parser.parse(parser["TOKEN_" + token.lexeme], token); - } - } - parser.parse(); - return _result; -}; - - -if(!fs.existsSync("tests")) { - fs.mkdirSync("tests"); -} - -var test_and = LemonJS("abc == 1 and abc1 == 2 and (bbc == 5)"); -fs.writeFileSync("tests/test_and.json", JSON.stringify(test_and, true, 3)); - -var test_address = LemonJS('abc == Address ["a", "b", "c"]'); -fs.writeFileSync("tests/test_address.json", JSON.stringify(test_address, true, 3)); - -var test_float = LemonJS('abc == 23.2'); -fs.writeFileSync("tests/test_float.json", JSON.stringify(test_float, true, 3)); - -var test_string = LemonJS('abc == "sadfasdf"'); -fs.writeFileSync("tests/test_string.json", JSON.stringify(test_string, true, 3)); - -var test_bool = LemonJS('abc == true or cab == false'); -fs.writeFileSync("tests/test_bool.json", JSON.stringify(test_bool, true, 3)); - -var test_not = LemonJS('not cab == false'); -fs.writeFileSync("tests/test_not.json", JSON.stringify(test_not, true, 3)); - -var test_oid = LemonJS('abc == Oid [a.b.d]'); -fs.writeFileSync("tests/test_oid.json", JSON.stringify(test_oid, true, 3)); - -var test_timediff = LemonJS('add == TimeDiff [17924 15:01:24 441000]'); -fs.writeFileSync("tests/test_timediff.json", JSON.stringify(test_timediff, true, 3)); - -var test_timediff_single = LemonJS('TimeDiff [17924 15:01:24 441000]'); -fs.writeFileSync("tests/test_timediff_single.json", JSON.stringify(test_timediff_single, true, 3)); +})(); \ No newline at end of file diff --git a/parsers/filters/test_code_environment.js b/parsers/filters/test_code_environment.js new file mode 100644 index 0000000..e69de29 diff --git a/test.js b/test.js new file mode 100644 index 0000000..2d4a120 --- /dev/null +++ b/test.js @@ -0,0 +1,52 @@ +/** + * Created by Aleksey Chichenkov on 1/29/19. + */ + +var fs = require("fs"); +var exec = require('child_process').exec; + +exec("node main.js -o=config.js -t=node", function(err, stdout, stderr) { + err && console.log("ERROR: ", err); + err && process.exit(1); + + test(); +}); + +var test = function() { + var LemonJS = require("./parsers/filters/parser.js"); + + if(!fs.existsSync("tests")) { + fs.mkdirSync("tests"); + } + + var test_and = LemonJS("abc == 1 and abc1 == 2 and (bbc == 5)").tree; + fs.writeFileSync("tests/test_and.json", JSON.stringify(test_and, true, 3)); + + var test_address = LemonJS('abc == Address ["a", "b", "c"]').tree; + fs.writeFileSync("tests/test_address.json", JSON.stringify(test_address, true, 3)); + + var test_float = LemonJS('abc == 23.2').tree; + fs.writeFileSync("tests/test_float.json", JSON.stringify(test_float, true, 3)); + + var test_string = LemonJS('abc == "sadfasdf"').tree; + fs.writeFileSync("tests/test_string.json", JSON.stringify(test_string, true, 3)); + + var test_bool = LemonJS('abc == true or cab == false').tree; + fs.writeFileSync("tests/test_bool.json", JSON.stringify(test_bool, true, 3)); + + var test_not = LemonJS('not cab == false').tree; + fs.writeFileSync("tests/test_not.json", JSON.stringify(test_not, true, 3)); + + var test_oid = LemonJS('abc == Oid [a.b.d]').tree; + fs.writeFileSync("tests/test_oid.json", JSON.stringify(test_oid, true, 3)); + + var test_timediff = LemonJS('add == TimeDiff [17924 15:01:24 441000]').tree; + fs.writeFileSync("tests/test_timediff.json", JSON.stringify(test_timediff, true, 3)); + + var test_time = LemonJS('add == Time [29/12/2019 15:01:24 441000]').tree; + fs.writeFileSync("tests/test_time.json", JSON.stringify(test_time, true, 3)); + +}; + + +