diff --git a/parsers/filters/lexer.js b/parsers/filters/lexer.js index 0badc26..9146977 100644 --- a/parsers/filters/lexer.js +++ b/parsers/filters/lexer.js @@ -1,4 +1,4 @@ -/* Generated by re2c 1.0.3 on Fri Jan 25 16:37:52 2019 */ +/* Generated by re2c 1.0.3 on Mon Jan 28 17:32:49 2019 */ var types = [ "LSB", "RSB", @@ -20,6 +20,7 @@ var types = [ "OR", "NOT", "ADDRESS", + "OID", "TIME", "TIMEDIFF", "INTEGER_LITERAL", @@ -61,7 +62,7 @@ Lexer.prototype = { end: this._yy_cursor }; - console.log(print_f("LEXER: Not found close quote start: %s", this._yy_cursor)); + console.log(print_f("Not found close quote start: %s", this._yy_cursor)); }, _unknownSymbol: function() { this._error = true; @@ -71,19 +72,20 @@ Lexer.prototype = { end: this._yy_cursor }; - console.log(print_f("LEXER: Found unknown symbol on position: %s", this._yy_cursor)); + console.log(print_f("Found unknown symbol on position: %s", this._yy_cursor)); }, _foundLexeme: function(_lexeme) { - console.log(print_f("LEXER: found lex: %s; start: %s; end: %s; result => %s", _lexeme, this._yy_lex_start, this._yy_cursor, this._string.substring(this._yy_lex_start, this._yy_cursor))); + console.log(print_f("found lex: %s; start: %s; end: %s; result => %s", _lexeme, this._yy_lex_start, this._yy_cursor, this._string.substring(this._yy_lex_start, this._yy_cursor))); this._last_found_lexeme = { error: 0, lexeme: _lexeme, + value: this._string.substring(this._yy_lex_start, this._yy_cursor), start: this._yy_lex_start, end: this._yy_cursor }; }, _endOfString: function() { - console.log(print_f("LEXER: search end\n")); + console.log(print_f("search end\n")); this._end = true; this._last_found_lexeme = { error: -2 @@ -269,7 +271,6 @@ Lexer.prototype = { this._state = 38; break; case 'O': - case 'o': this._state = 39; break; case 'T': @@ -284,9 +285,12 @@ Lexer.prototype = { case 'a': this._state = 45; break; - case 't': + case 'o': this._state = 46; break; + case 't': + this._state = 47; + break; default: this._state = 4; break; @@ -295,27 +299,27 @@ Lexer.prototype = { break; case 2: ++this._yy_cursor; { - this._endOfString(); - return; - } + this._endOfString(); + return; + } case 4: ++this._yy_cursor; case 5: - { - this._unknownSymbol();this._set_next(); - return; - } + { + this._unknownSymbol();this._set_next(); + return; + } case 6: ++this._yy_cursor; { - this._set_next(); - break; - } + this._set_next(); + break; + } case 8: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { case '=': - this._state = 47; + this._state = 48; break; default: this._state = 5; @@ -325,40 +329,40 @@ Lexer.prototype = { break; case 9: ++this._yy_cursor; { - this._state = 100000000; - break; - } + this._state = 100000000; + break; + } case 11: ++this._yy_cursor; { - this._foundLexeme("REM"); - this._set_next(); - return; - } + this._foundLexeme("REM"); + this._set_next(); + return; + } case 13: ++this._yy_cursor; { - this._foundLexeme("LCB"); - this._set_next(); - return; - } + this._foundLexeme("LCB"); + this._set_next(); + return; + } case 15: ++this._yy_cursor; { - this._foundLexeme("RCB"); - this._set_next(); - return; - } + this._foundLexeme("RCB"); + this._set_next(); + return; + } case 17: ++this._yy_cursor; { - this._foundLexeme("COMMA"); - this._set_next(); - return; - } + this._foundLexeme("COMMA"); + this._set_next(); + return; + } case 19: this._yy_accept = 0; this._yy_char = this._string[(this._yy_marker = ++this._yy_cursor)]; (function() { switch (this._yy_char) { case '.': - this._state = 49; + this._state = 50; break; case '0': case '1': @@ -392,7 +396,7 @@ Lexer.prototype = { case '7': case '8': case '9': - this._state = 51; + this._state = 52; break; default: this._state = 21; @@ -401,17 +405,17 @@ Lexer.prototype = { }.bind(this))(); break; case 21: - { - this._foundLexeme("DOT");this._set_next(); - return; - } + { + this._foundLexeme("DOT");this._set_next(); + return; + } case 22: this._yy_accept = 1; this._yy_char = this._string[(this._yy_marker = ++this._yy_cursor)]; (function() { switch (this._yy_char) { case '.': - this._state = 49; + this._state = 50; break; case '0': case '1': @@ -432,22 +436,22 @@ Lexer.prototype = { }.bind(this))(); break; case 24: - { - this._foundLexeme("INTEGER_LITERAL");this._set_next(); - return; - } + { + this._foundLexeme("INTEGER_LITERAL");this._set_next(); + return; + } case 25: ++this._yy_cursor; { - this._foundLexeme("COLON"); - this._set_next(); - return; - } + 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 = 54; + this._state = 55; break; default: this._state = 28; @@ -456,16 +460,16 @@ Lexer.prototype = { }.bind(this))(); break; case 28: - { - this._foundLexeme("LT");this._set_next(); - return; - } + { + this._foundLexeme("LT");this._set_next(); + return; + } case 29: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { case '=': - this._state = 56; + this._state = 57; break; default: this._state = 5; @@ -478,7 +482,7 @@ Lexer.prototype = { (function() { switch (this._yy_char) { case '=': - this._state = 58; + this._state = 59; break; default: this._state = 31; @@ -487,20 +491,20 @@ Lexer.prototype = { }.bind(this))(); break; case 31: - { - this._foundLexeme("GT");this._set_next(); - return; - } + { + 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': - this._state = 60; + this._state = 61; break; case 'd': - this._state = 61; + this._state = 62; break; default: this._state = 35; @@ -509,10 +513,10 @@ Lexer.prototype = { }.bind(this))(); break; case 33: - { - this._foundLexeme("ID");this._set_next(); - return; - } + { + this._foundLexeme("ID");this._set_next(); + return; + } case 34: this._yy_char = this._string[++this._yy_cursor]; case 35: @@ -595,7 +599,7 @@ Lexer.prototype = { switch (this._yy_char) { case 'A': case 'a': - this._state = 62; + this._state = 63; break; default: this._state = 35; @@ -609,7 +613,7 @@ Lexer.prototype = { switch (this._yy_char) { case 'I': case 'i': - this._state = 63; + this._state = 64; break; default: this._state = 35; @@ -623,11 +627,11 @@ Lexer.prototype = { switch (this._yy_char) { case 'L': case 'l': - this._state = 64; + this._state = 65; break; case 'O': case 'o': - this._state = 65; + this._state = 66; break; default: this._state = 35; @@ -641,7 +645,10 @@ Lexer.prototype = { switch (this._yy_char) { case 'R': case 'r': - this._state = 66; + this._state = 67; + break; + case 'i': + this._state = 69; break; default: this._state = 35; @@ -655,10 +662,10 @@ Lexer.prototype = { switch (this._yy_char) { case 'R': case 'r': - this._state = 68; + this._state = 70; break; case 'i': - this._state = 69; + this._state = 71; break; default: this._state = 35; @@ -668,23 +675,23 @@ Lexer.prototype = { break; case 41: ++this._yy_cursor; { - this._foundLexeme("LSB"); - this._set_next(); - return; - } + this._foundLexeme("LSB"); + this._set_next(); + return; + } case 43: ++this._yy_cursor; { - this._foundLexeme("RSB"); - this._set_next(); - return; - } + this._foundLexeme("RSB"); + this._set_next(); + return; + } case 45: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { case 'N': case 'n': - this._state = 60; + this._state = 61; break; default: this._state = 35; @@ -698,7 +705,7 @@ Lexer.prototype = { switch (this._yy_char) { case 'R': case 'r': - this._state = 68; + this._state = 67; break; default: this._state = 35; @@ -707,12 +714,26 @@ Lexer.prototype = { }.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; + break; + } + }.bind(this))(); + break; + case 48: ++this._yy_cursor; { - this._foundLexeme("NEQ"); - this._set_next(); - return; - } - case 49: + this._foundLexeme("NEQ"); + this._set_next(); + return; + } + case 50: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { @@ -726,15 +747,15 @@ Lexer.prototype = { case '7': case '8': case '9': - this._state = 51; + this._state = 52; break; default: - this._state = 50; + this._state = 51; break; } }.bind(this))(); break; - case 50: + case 51: this._yy_cursor = this._yy_marker; switch (this._yy_accept) { case 0: @@ -744,10 +765,10 @@ Lexer.prototype = { this._state = 24; break; default: - this._state = 53; + this._state = 54; break; } - case 51: + case 52: this._yy_accept = 2; this._yy_char = this._string[(this._yy_marker = ++this._yy_cursor)]; (function() { @@ -762,58 +783,45 @@ Lexer.prototype = { case '7': case '8': case '9': - this._state = 51; + this._state = 52; break; case 'e': - this._state = 70; + this._state = 72; break; default: - this._state = 53; + this._state = 54; break; } }.bind(this))(); break; - case 53: - { - this._foundLexeme("FLOAT_LITERAL");this._set_next(); - return; - } case 54: + { + this._foundLexeme("FLOAT_LITERAL");this._set_next(); + return; + } + case 55: ++this._yy_cursor; { - this._foundLexeme("LTE"); - this._set_next(); - return; - } - case 56: + this._foundLexeme("LTE"); + this._set_next(); + return; + } + case 57: ++this._yy_cursor; { - this._foundLexeme("EQ"); - this._set_next(); - return; - } - case 58: + this._foundLexeme("EQ"); + this._set_next(); + return; + } + case 59: ++this._yy_cursor; { - this._foundLexeme("GTE"); - this._set_next(); - return; - } - case 60: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'D': - case 'd': - this._state = 71; - break; - default: - this._state = 35; - break; - } - }.bind(this))(); - break; + this._foundLexeme("GTE"); + this._set_next(); + return; + } case 61: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { + case 'D': case 'd': this._state = 73; break; @@ -827,9 +835,8 @@ Lexer.prototype = { this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'L': - case 'l': - this._state = 74; + case 'd': + this._state = 75; break; default: this._state = 35; @@ -841,9 +848,9 @@ Lexer.prototype = { this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'K': - case 'k': - this._state = 75; + case 'L': + case 'l': + this._state = 76; break; default: this._state = 35; @@ -855,9 +862,9 @@ Lexer.prototype = { this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'I': - case 'i': - this._state = 76; + case 'K': + case 'k': + this._state = 77; break; default: this._state = 35; @@ -869,9 +876,9 @@ Lexer.prototype = { this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'T': - case 't': - this._state = 77; + case 'I': + case 'i': + this._state = 78; break; default: this._state = 35; @@ -880,6 +887,20 @@ Lexer.prototype = { }.bind(this))(); break; case 66: + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 'T': + case 't': + this._state = 79; + break; + default: + this._state = 35; + break; + } + }.bind(this))(); + break; + case 67: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { @@ -949,36 +970,22 @@ Lexer.prototype = { this._state = 34; break; default: - this._state = 67; + this._state = 68; break; } }.bind(this))(); break; - case 67: - { - this._foundLexeme("OR");this._set_next(); - return; - } case 68: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'U': - case 'u': - this._state = 79; - break; - default: - this._state = 35; - break; - } - }.bind(this))(); - break; + { + this._foundLexeme("OR");this._set_next(); + return; + } case 69: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'm': - this._state = 80; + case 'd': + this._state = 81; break; default: this._state = 35; @@ -987,11 +994,38 @@ Lexer.prototype = { }.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; + case 71: + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 'm': + this._state = 84; + break; + default: + this._state = 35; + break; + } + }.bind(this))(); + break; + case 72: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { case '-': - this._state = 81; + this._state = 85; break; case '0': case '1': @@ -1003,15 +1037,15 @@ Lexer.prototype = { case '7': case '8': case '9': - this._state = 82; + this._state = 86; break; default: - this._state = 50; + this._state = 51; break; } }.bind(this))(); break; - case 71: + case 73: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { @@ -1081,50 +1115,22 @@ Lexer.prototype = { this._state = 34; break; default: - this._state = 72; - break; - } - }.bind(this))(); - break; - case 72: - { - this._foundLexeme("AND");this._set_next(); - return; - } - case 73: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'r': - this._state = 84; - break; - default: - this._state = 35; + this._state = 74; break; } }.bind(this))(); break; case 74: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'S': - case 's': - this._state = 79; - break; - default: - this._state = 35; - break; - } - }.bind(this))(); - break; + { + this._foundLexeme("AND");this._set_next(); + return; + } case 75: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'E': - case 'e': - this._state = 85; + case 'r': + this._state = 88; break; default: this._state = 35; @@ -1136,9 +1142,9 @@ Lexer.prototype = { this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'K': - case 'k': - this._state = 87; + case 'S': + case 's': + this._state = 83; break; default: this._state = 35; @@ -1147,6 +1153,34 @@ Lexer.prototype = { }.bind(this))(); break; case 77: + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 'E': + case 'e': + this._state = 89; + break; + default: + this._state = 35; + break; + } + }.bind(this))(); + break; + case 78: + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 'K': + case 'k': + this._state = 91; + break; + default: + this._state = 35; + break; + } + }.bind(this))(); + break; + case 79: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { @@ -1216,43 +1250,16 @@ Lexer.prototype = { this._state = 34; break; default: - this._state = 78; - break; - } - }.bind(this))(); - break; - case 78: - { - this._foundLexeme("NOT");this._set_next(); - return; - } - case 79: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'E': - case 'e': - this._state = 88; - break; - default: - this._state = 35; + this._state = 80; break; } }.bind(this))(); break; case 80: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'e': - this._state = 90; - break; - default: - this._state = 35; - break; - } - }.bind(this))(); - break; + { + this._foundLexeme("NOT");this._set_next(); + return; + } case 81: this._yy_char = this._string[++this._yy_cursor]; (function() { @@ -1267,32 +1274,82 @@ Lexer.prototype = { case '7': case '8': case '9': - this._state = 82; + 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; break; default: - this._state = 50; + this._state = 82; break; } }.bind(this))(); break; case 82: + { + this._foundLexeme("OID");this._set_next(); + return; + } + case 83: 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': - this._state = 82; + case 'E': + case 'e': + this._state = 92; break; default: - this._state = 53; + this._state = 35; break; } }.bind(this))(); @@ -1302,7 +1359,7 @@ Lexer.prototype = { (function() { switch (this._yy_char) { case 'e': - this._state = 92; + this._state = 94; break; default: this._state = 35; @@ -1324,82 +1381,32 @@ 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 = 86; break; default: - this._state = 86; + this._state = 51; break; } }.bind(this))(); break; case 86: - { - this._foundLexeme("LIKE");this._set_next(); - return; - } - case 87: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'E': - case 'e': - this._state = 93; + 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 = 35; + this._state = 54; break; } }.bind(this))(); @@ -1408,169 +1415,7 @@ 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; - break; - default: - this._state = 89; - break; - } - }.bind(this))(); - break; - case 89: - { - this._foundLexeme("BOOL_LITERAL");this._set_next(); - return; - } - case 90: - 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': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': - this._state = 34; - break; - case 'D': - this._state = 95; - break; - default: - this._state = 91; - break; - } - }.bind(this))(); - break; - case 91: - { - this._foundLexeme("TIME");this._set_next(); - return; - } - case 92: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 's': this._state = 96; break; default: @@ -1579,7 +1424,7 @@ Lexer.prototype = { } }.bind(this))(); break; - case 93: + case 89: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { @@ -1649,21 +1494,22 @@ Lexer.prototype = { this._state = 34; break; default: - this._state = 94; + this._state = 90; break; } }.bind(this))(); break; - case 94: - { - this._foundLexeme("NLIKE");this._set_next(); - return; - } - case 95: + 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 'i': + case 'E': + case 'e': this._state = 97; break; default: @@ -1672,12 +1518,174 @@ Lexer.prototype = { } }.bind(this))(); break; + case 92: + 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; + break; + default: + this._state = 93; + break; + } + }.bind(this))(); + break; + case 93: + { + this._foundLexeme("BOOL_LITERAL");this._set_next(); + return; + } + case 94: + 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': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': + this._state = 34; + break; + case 'D': + this._state = 99; + break; + default: + this._state = 95; + break; + } + }.bind(this))(); + break; + case 95: + { + this._foundLexeme("TIME");this._set_next(); + return; + } case 96: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { case 's': - this._state = 98; + this._state = 100; break; default: this._state = 35; @@ -1686,19 +1694,6 @@ Lexer.prototype = { }.bind(this))(); break; case 97: - this._yy_char = this._string[++this._yy_cursor]; - (function() { - switch (this._yy_char) { - case 'f': - this._state = 100; - break; - default: - this._state = 35; - break; - } - }.bind(this))(); - break; - case 98: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { @@ -1768,22 +1763,35 @@ Lexer.prototype = { this._state = 34; break; default: - this._state = 99; + this._state = 98; break; } }.bind(this))(); break; + case 98: + { + this._foundLexeme("NLIKE");this._set_next(); + return; + } case 99: - { - this._foundLexeme("ADDRESS");this._set_next(); - return; - } + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 'i': + this._state = 101; + break; + default: + this._state = 35; + break; + } + }.bind(this))(); + break; case 100: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { - case 'f': - this._state = 101; + case 's': + this._state = 102; break; default: this._state = 35; @@ -1792,6 +1800,19 @@ Lexer.prototype = { }.bind(this))(); break; case 101: + this._yy_char = this._string[++this._yy_cursor]; + (function() { + switch (this._yy_char) { + case 'f': + this._state = 104; + break; + default: + this._state = 35; + break; + } + }.bind(this))(); + break; + case 102: this._yy_char = this._string[++this._yy_cursor]; (function() { switch (this._yy_char) { @@ -1861,21 +1882,114 @@ Lexer.prototype = { this._state = 34; break; default: - this._state = 102; + this._state = 103; break; } }.bind(this))(); break; - case 102: - { - this._foundLexeme("TIMEDIFF");this._set_next(); - return; - } + 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; + break; + default: + this._state = 35; + break; + } + }.bind(this))(); + break; + case 105: + 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; + break; + default: + this._state = 106; + break; + } + }.bind(this))(); + break; + case 106: + { + this._foundLexeme("TIMEDIFF");this._set_next(); + return; + } case 100000000: - { - this._searchString();this._set_next(); - return; - } + { + this._searchString();this._set_next(); + return; + } } } } diff --git a/parsers/filters/parser.js b/parsers/filters/parser.js index dafe5e6..dc1201c 100644 --- a/parsers/filters/parser.js +++ b/parsers/filters/parser.js @@ -37,15 +37,28 @@ function Parser() { this.TOKEN_AND = 2; this.TOKEN_NOT = 3; this.TOKEN_INTEGER_LITERAL = 4; - this.TOKEN_STRING_LITERAL = 5; - this.TOKEN_ID = 6; - this.TOKEN_EQ = 7; - this.TOKEN_LCB = 8; - this.TOKEN_RCB = 9; - this.TOKEN_COMMA = 10; - this.TOKEN_ADDRESS = 11; - this.TOKEN_LSB = 12; - this.TOKEN_RSB = 13; + 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. @@ -72,19 +85,19 @@ function Parser() { ** YY_NO_ACTION The yy_action[] code for no-op */ /************* Begin control #defines *****************************************/ - this.YYNOCODE = 27; + this.YYNOCODE = 55; this.YYSTACKDEPTH = 100; this.YYFALLBACK = false; - this.YYNSTATE = 12; - this.YYNRULE = 17; - this.YY_MAX_SHIFT = 11; - this.YY_MIN_SHIFTREDUCE = 26; - this.YY_MAX_SHIFTREDUCE = 42; - this.YY_MIN_REDUCE = 43; - this.YY_MAX_REDUCE = 59; - this.YY_ERROR_ACTION = 60; - this.YY_ACCEPT_ACTION = 61; - this.YY_NO_ACTION = 62; + 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 @@ -158,47 +171,135 @@ function Parser() { *********** Begin parsing tables **********************************************/ this.yy_action = [ /* 0 */ - 61, 6, 27, 2, 30, 11, 34, 35, 5, 10, + 179, 24, 26, 83, 85, 87, 25, 22, 103, 104, /* 10 */ - 36, 30, 11, 34, 35, 33, 9, 7, 30, 11, + 105, 106, 107, 108, 109, 110, 111, 112, 113, 88, /* 20 */ - 34, 35, 28, 32, 29, 31, 43, 1, 2, 37, + 91, 120, 23, 88, 126, 128, 82, 90, 22, 103, /* 30 */ - 42, 41, 38, 8, 4, 3, + 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 */ - 15, 16, 4, 2, 19, 20, 21, 22, 16, 11, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, /* 10 */ - 9, 19, 20, 21, 22, 16, 23, 24, 19, 20, + 38, 39, 40, 41, 42, 43, 44, 45, 46, 7, /* 20 */ - 21, 22, 17, 18, 5, 6, 0, 8, 2, 5, + 8, 49, 29, 7, 52, 53, 4, 34, 35, 36, /* 30 */ - 25, 13, 5, 10, 12, 7, + 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 = 36; - this.YY_SHIFT_COUNT = 11; - this.YY_SHIFT_MIN = -2; - this.YY_SHIFT_MAX = 28; + 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 */ - 19, 19, 19, -2, 24, 1, 26, 18, 27, 23, + 91, 137, 137, 137, 137, 201, 201, 201, 201, 201, /* 10 */ - 22, 28, + 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 = -16; - this.YY_REDUCE_COUNT = 4; - this.YY_REDUCE_MIN = -15; - this.YY_REDUCE_MAX = 5; + 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 */ - -15, -8, -1, 5, -7, + -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 */ - 60, 60, 60, 60, 57, 60, 60, 60, 60, 56, + 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, /* 10 */ - 60, 60, + 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 *****************************/ @@ -281,12 +382,19 @@ function Parser() { ** are required. The following table supplies these names */ this.yyTokenName = [ "$", "OR", "AND", "NOT", - "INTEGER_LITERAL", "STRING_LITERAL", "ID", "EQ", - "LCB", "RCB", "COMMA", "ADDRESS", - "LSB", "RSB", "error", "main", - "expr", "integer", "literal", "string", - "id", "eq", "and", "address_literal_content", - "address_literal_content_or_empty", "address_literal", + "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. @@ -295,37 +403,101 @@ function Parser() { /* 0 */ "main ::= expr", /* 1 */ - "integer ::= INTEGER_LITERAL", + "main ::= literal", /* 2 */ - "literal ::= integer", + "integer_literal ::= INTEGER_LITERAL", /* 3 */ - "string ::= STRING_LITERAL", + "literal ::= integer_literal", /* 4 */ - "id ::= string", + "float_literal ::= FLOAT_LITERAL", /* 5 */ - "id ::= ID", + "literal ::= float_literal", /* 6 */ - "eq ::= id EQ literal", + "bool_literal ::= BOOL_LITERAL", /* 7 */ - "and ::= expr AND expr", + "literal ::= bool_literal", /* 8 */ - "expr ::= eq", + "string_literal ::= STRING_LITERAL", /* 9 */ - "expr ::= and", + "literal ::= string_literal", /* 10 */ - "expr ::= LCB expr RCB", + "id ::= string_literal", /* 11 */ - "address_literal_content ::= STRING_LITERAL", + "id ::= ID", /* 12 */ - "address_literal_content ::= address_literal_content COMMA STRING_LITERAL", + "and ::= expr AND expr", /* 13 */ - "address_literal_content_or_empty ::= address_literal_content", + "or ::= expr OR expr", /* 14 */ - "address_literal_content_or_empty ::=", + "not ::= NOT expr", /* 15 */ - "address_literal ::= ADDRESS LSB address_literal_content_or_empty RSB", + "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 @@ -594,71 +766,199 @@ function Parser() { // nrhs, /* Number of right-hand side symbols in the rule */ //} this.yyRuleInfo = [{ - lhs: 15, + lhs: 28, nrhs: 1 }, { - lhs: 17, + lhs: 28, nrhs: 1 }, { - lhs: 18, + lhs: 31, nrhs: 1 }, { - lhs: 19, + lhs: 30, nrhs: 1 }, { - lhs: 20, + lhs: 32, nrhs: 1 }, { - lhs: 20, + lhs: 30, nrhs: 1 }, { - lhs: 21, + 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: 22, + lhs: 37, nrhs: 3 }, { - lhs: 16, - nrhs: 1 + lhs: 38, + nrhs: 2 }, { - lhs: 16, - nrhs: 1 - }, - { - lhs: 16, + lhs: 39, nrhs: 3 }, { - lhs: 23, - nrhs: 1 - }, - { - lhs: 23, + lhs: 40, nrhs: 3 }, { - lhs: 24, + 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: 24, + 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: 25, + lhs: 49, nrhs: 4 }, { - lhs: 18, + 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 }, ]; @@ -714,120 +1014,131 @@ function Parser() { */ /********** Begin reduce actions **********************************************/ case 0: - /* main ::= expr */ { + /* main ::= expr */ + case 1: + /* main ::= literal */ this.yytestcase(yyruleno == 1); { _result.root_node = this.yystack[this.yyidx + 0].minor } break; - case 1: - /* integer ::= INTEGER_LITERAL */ { - yylhsminor = new Node({ - type: "INTEGER_LITERAL", - lexeme: this.yystack[this.yyidx + 0].minor.lexeme, - 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 2: - /* literal ::= integer */ { - yylhsminor = new Node({ - type: "literal", - children: [this.yystack[this.yyidx + 0].minor] - }) - } - this.yystack[this.yyidx + 0].minor = yylhsminor; - break; - case 3: - /* string ::= STRING_LITERAL */ { - yylhsminor = new Node({ - type: "STRING_LITERAL", - lexeme: this.yystack[this.yyidx + 0].minor.lexeme, - 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 4: - /* id ::= string */ { - yylhsminor = new Node({ - type: "id", - children: [this.yystack[this.yyidx + 0].minor] + /* 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: - /* id ::= ID */ { - yylhsminor = new Node({ - type: "ID", - lexeme: this.yystack[this.yyidx + 0].minor.lexeme, - start: this.yystack[this.yyidx + 0].minor.start, - end: this.yystack[this.yyidx + 0].minor.end + /* 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: - /* eq ::= id EQ literal */ { - yylhsminor = new Node({ - type: "eq", + /* bool_literal ::= BOOL_LITERAL */ { + yylhsminor = new tokens.bool_literal({ children: [ - this.yystack[this.yyidx + -2].minor, - new Node({ - type: "EQ", - lexeme: this.yystack[this.yyidx + -1].minor.lexeme, - start: this.yystack[this.yyidx + -1].minor.start, - end: this.yystack[this.yyidx + -1].minor.end - }), - this.yystack[this.yyidx + 0].minor + 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 7: - /* and ::= expr AND expr */ { - yylhsminor = new Node({ - type: "and", - children: [ - this.yystack[this.yyidx + -2].minor, - this.yystack[this.yyidx + 0].minor - ] - }) - } - this.yystack[this.yyidx + -2].minor = yylhsminor; - break; - case 8: - /* expr ::= eq */ { - yylhsminor = new Node({ - type: "expr", - children: [this.yystack[this.yyidx + 0].minor] - }) - } this.yystack[this.yyidx + 0].minor = yylhsminor; break; - case 9: - /* expr ::= and */ - case 13: - /* address_literal_content_or_empty ::= address_literal_content */ this.yytestcase(yyruleno == 13); { - yylhsminor = this.yystack[this.yyidx + 0].minor; + 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: - /* expr ::= LCB expr RCB */ { - this.yystack[this.yyidx + -2].minor = this.yystack[this.yyidx + -1].minor; + /* id ::= string_literal */ { + yylhsminor = new tokens.id({ + children: [this.yystack[this.yyidx + 0].minor] + }); } + this.yystack[this.yyidx + 0].minor = yylhsminor; break; case 11: - /* address_literal_content ::= STRING_LITERAL */ { - yylhsminor = new Node({ + /* id ::= ID */ { + yylhsminor = new tokens.id({ children: [ - new Node({ - type: "STRING_LITERAL", - lexeme: this.yystack[this.yyidx + 0].minor.lexeme, + 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 }) @@ -837,41 +1148,310 @@ function Parser() { this.yystack[this.yyidx + 0].minor = yylhsminor; break; case 12: - /* address_literal_content ::= address_literal_content COMMA STRING_LITERAL */ { - this.yystack[this.yyidx + -2].minor.add(new Node({ - type: "STRING_LITERAL", - lexeme: this.yystack[this.yyidx + 0].minor.lexeme, - start: this.yystack[this.yyidx + 0].minor.start, - end: this.yystack[this.yyidx + 0].minor.end - })); - yylhsminor = this.yystack[this.yyidx + -2].minor; + /* 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: - /* address_literal_content_or_empty ::= */ { - this.yystack[this.yyidx + 1].minor = new Node({ - type: "address_literal_content" - }); + /* 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: - /* address_literal ::= ADDRESS LSB address_literal_content_or_empty RSB */ { - this.yystack[this.yyidx + -3].minor = new Node({ - type: "address_literal", - children: this.yystack[this.yyidx + -1].minor.children + /* 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: - /* literal ::= address_literal */ { - yylhsminor = new Node({ - type: "literal", + /* 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 ************************************************/ @@ -1108,45 +1688,668 @@ function Parser() { * Created by Aleksey Chichenkov on 1/28/19. */ +var fs = require("fs"); var Lexer = require('./lexer.js'); -var Node = function(_options) { - this.type = _options.type || "none"; - this.children = _options.children || []; - this.lexeme = _options.lexeme || null; - this.start = _options.start || 0; - this.end = _options.end || 0; -}; +var tokens = (function() { -Node.prototype = { - add: function(_node) { - this.children.push(_node); + 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("abc == 1 and abc1 == 2 and (bbc == 5)"); var lexer = new Lexer(_input); - var token; while (token = lexer.next()) { - console.log("PARSE", token.lexeme); - parser.parse(parser["TOKEN_" + token.lexeme], token); + if (token.error === 0) { + console.log("PARSE", token.lexeme); + parser.parse(parser["TOKEN_" + token.lexeme], token); + } } parser.parse(); return _result; }; -var fs = require("fs"); -fs.mkdirSync("tests"); +if (!fs.existsSync("tests")) { + fs.mkdirSync("tests"); +} var test_and = LemonJS("abc == 1 and abc1 == 2 and (bbc == 5)"); -fs.writeFileSync("tests/out_test_and.json", JSON.stringify(test_and, true, 3)); +fs.writeFileSync("tests/test_and.json", JSON.stringify(test_and, true, 3)); var test_address = LemonJS('abc == Address ["a", "b", "c"]'); -fs.writeFileSync("tests/out_tree_address.json", JSON.stringify(test_address, true, 3)); \ No newline at end of file +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 index ee9bc1b..8aef67e 100644 --- a/parsers/filters/parser.out +++ b/parsers/filters/parser.out @@ -1,129 +1,730 @@ State 0: main ::= * expr - string ::= * STRING_LITERAL - id ::= * string + 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 - eq ::= * id EQ literal and ::= * expr AND expr - expr ::= * eq + 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 - STRING_LITERAL shift-reduce 3 string ::= STRING_LITERAL - ID shift-reduce 5 id ::= ID + 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 6 - string shift-reduce 4 id ::= string - id shift 11 - eq shift-reduce 8 expr ::= eq - and shift-reduce 9 expr ::= and + 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 ::= * STRING_LITERAL - id ::= * string + string_literal ::= * STRING_LITERAL + id ::= * string_literal id ::= * ID - eq ::= * id EQ literal and ::= * expr AND expr - expr ::= * eq + 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 - STRING_LITERAL shift-reduce 3 string ::= STRING_LITERAL - ID shift-reduce 5 id ::= ID + NOT shift 2 + STRING_LITERAL shift-reduce 8 string_literal ::= STRING_LITERAL + ID shift-reduce 11 id ::= ID LCB shift 1 - expr shift 5 - string shift-reduce 4 id ::= string - id shift 11 - eq shift-reduce 8 expr ::= eq - and shift-reduce 9 expr ::= and + 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 ::= * STRING_LITERAL - id ::= * string + string_literal ::= * STRING_LITERAL + id ::= * string_literal id ::= * ID - eq ::= * id EQ literal and ::= * expr AND expr - and ::= expr AND * expr - expr ::= * eq + 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 - STRING_LITERAL shift-reduce 3 string ::= STRING_LITERAL - ID shift-reduce 5 id ::= ID + NOT shift 2 + STRING_LITERAL shift-reduce 8 string_literal ::= STRING_LITERAL + ID shift-reduce 11 id ::= ID LCB shift 1 - expr shift-reduce 7 and ::= expr AND expr - string shift-reduce 4 id ::= string - id shift 11 - eq shift-reduce 8 expr ::= eq - and shift-reduce 9 expr ::= and + 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: - integer ::= * INTEGER_LITERAL - literal ::= * integer + 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 1 integer ::= INTEGER_LITERAL - ADDRESS shift 10 - integer shift-reduce 2 literal ::= integer - literal shift-reduce 6 eq ::= id EQ literal - address_literal shift-reduce 16 literal ::= address_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 4: - address_literal_content ::= * STRING_LITERAL - address_literal_content ::= * address_literal_content COMMA STRING_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 - (14) address_literal_content_or_empty ::= * + (38) address_literal_content_or_empty ::= * address_literal ::= ADDRESS LSB * address_literal_content_or_empty RSB - STRING_LITERAL shift-reduce 11 address_literal_content ::= STRING_LITERAL - address_literal_content shift 9 -address_literal_content_or_empty shift 7 - {default} reduce 14 address_literal_content_or_empty ::= + 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 5: +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 - AND shift 2 - RCB shift-reduce 10 expr ::= LCB expr RCB + OR shift 3 + AND shift 4 + RCB shift-reduce 34 expr ::= LCB expr RCB -State 6: +State 24: (0) main ::= expr * and ::= expr * AND expr + or ::= expr * OR expr $ reduce 0 main ::= expr - AND shift 2 + OR shift 3 + AND shift 4 -State 7: +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 15 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 8: - address_literal_content ::= address_literal_content COMMA * STRING_LITERAL +State 35: + address_literal_content ::= address_literal_content * COMMA string_literal + (37) address_literal_content_or_empty ::= address_literal_content * - STRING_LITERAL shift-reduce 12 address_literal_content ::= address_literal_content COMMA STRING_LITERAL + COMMA shift 21 + {default} reduce 37 address_literal_content_or_empty ::= address_literal_content -State 9: - address_literal_content ::= address_literal_content * COMMA STRING_LITERAL - (13) address_literal_content_or_empty ::= address_literal_content * - - COMMA shift 8 - {default} reduce 13 address_literal_content_or_empty ::= address_literal_content - -State 10: +State 36: address_literal ::= ADDRESS * LSB address_literal_content_or_empty RSB - LSB shift 4 + LSB shift 14 -State 11: - eq ::= id * EQ literal +State 37: + and ::= expr * AND expr + or ::= expr * OR expr + (13) or ::= expr OR expr * - EQ shift 3 + AND shift 4 + {default} reduce 13 or ::= expr OR expr ---------------------------------------------------- Symbols: @@ -132,24 +733,52 @@ Symbols: 2: AND 3: NOT 4: INTEGER_LITERAL - 5: STRING_LITERAL - 6: ID - 7: EQ - 8: LCB - 9: RCB - 10: COMMA - 11: ADDRESS - 12: LSB - 13: RSB - 14: error: - 15: main: STRING_LITERAL ID LCB - 16: expr: STRING_LITERAL ID LCB - 17: integer: INTEGER_LITERAL - 18: literal: INTEGER_LITERAL ADDRESS - 19: string: STRING_LITERAL - 20: id: STRING_LITERAL ID - 21: eq: STRING_LITERAL ID - 22: and: STRING_LITERAL ID LCB - 23: address_literal_content: STRING_LITERAL - 24: address_literal_content_or_empty: STRING_LITERAL - 25: address_literal: ADDRESS + 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 407c569..deb40be 100644 --- a/parsers/filters/parser.y +++ b/parsers/filters/parser.y @@ -22,94 +22,16 @@ main ::= expr(A) . { _result.root_node = A } -integer(A) ::= INTEGER_LITERAL(B) . { - A = new Node({ - type: "INTEGER_LITERAL", - lexeme: B.lexeme, - start: B.start, - end: B.end - }) +main ::= literal(A) . { + _result.root_node = A } -literal(A) ::= integer(B) . { - A = new Node({ - type: "literal", - children: [B] - }) -} - -string(A) ::= STRING_LITERAL(B) . { - A = new Node({ - type: "STRING_LITERAL", - lexeme: B.lexeme, - start: B.start, - end: B.end - }) -} - -id(A) ::= string(B) . { - A = new Node({ - type: "id", - children: [B] - }); -} - -id(A) ::= ID(B) . { - A = new Node({ - type: "ID", - lexeme: B.lexeme, - start: B.start, - end: B.end - }) -} - -eq(A) ::= id(B) EQ(C) literal(D) . { - A = new Node({ - type: "eq", +integer_literal(A) ::= INTEGER_LITERAL(B) . { + A = new tokens.integer_literal({ children: [ - B, - new Node({ - type: "EQ", - lexeme: C.lexeme, - start: C.start, - end: C.end - }), - D - ] - }) -} - -and(A) ::= expr(B) AND expr(D) . { - A = new Node({ - type: "and", - children: [ - B, - D - ] - }) -} - -expr(A) ::= eq(B) . { - A = new Node({ - type: "expr", - children: [B] - }) -} - -expr(A) ::= and(B) . { - A = B; -} - -expr(A) ::= LCB expr(C) RCB . { - A = C; -} - -address_literal_content(A) ::= STRING_LITERAL(B) . { - A = new Node({ - children: [ - new Node({ - type: "STRING_LITERAL", - lexeme: B.lexeme, + new tokens.LEXEME({ + type: B.lexeme, + value: B.value, start: B.start, end: B.end }) @@ -117,13 +39,292 @@ address_literal_content(A) ::= STRING_LITERAL(B) . { }); } -address_literal_content(A) ::= address_literal_content(B) COMMA STRING_LITERAL(C) . { - B.add(new Node({ - type: "STRING_LITERAL", - lexeme: C.lexeme, - start: C.start, - end: C.end - })); +literal(A) ::= integer_literal(B) . { + A = B; +} + +float_literal(A) ::= FLOAT_LITERAL(B) . { + A = new tokens.float_literal({ + children: [ + new tokens.LEXEME({ + type: B.lexeme, + value: B.value, + start: B.start, + end: B.end + }) + ] + }) +} + +literal(A) ::= float_literal(B) . { + A = B; +} + +bool_literal(A) ::= BOOL_LITERAL(B) . { + A = new tokens.bool_literal({ + children: [ + new tokens.LEXEME({ + type: B.lexeme, + value: B.value, + start: B.start, + end: B.end + }) + ] + }) +} + +literal(A) ::= bool_literal(B) . { + A = B; +} + +string_literal(A) ::= STRING_LITERAL(B) . { + A = new tokens.string_literal({ + children: [ + new tokens.LEXEME({ + type: B.lexeme, + value: B.value, + start: B.start, + end: B.end + }) + ] + }); +} + +literal(A) ::= string_literal(B) . { + A = B; +} + +id(A) ::= string_literal(B) . { + A = new tokens.id({ + children: [B] + }); +} + +id(A) ::= ID(B) . { + A = new tokens.id({ + children: [ + new tokens.LEXEME({ + type: B.lexeme, + value: B.value, + start: B.start, + end: B.end + }) + ] + }); +} + +and(A) ::= expr(B) AND(C) expr(D) . { + A = new tokens.and({ + lexpr: B, + op: new tokens.LEXEME({ + type: C.lexeme, + value: C.value, + start: C.start, + end: C.end + }), + rexpr: D + }) +} + +or(A) ::= expr(B) OR(C) expr(D) . { + A = new tokens.or({ + lexpr: B, + op: new tokens.LEXEME({ + type: C.lexeme, + value: C.value, + start: C.start, + end: C.end + }), + rexpr: D + }) +} + +not(A) ::= NOT(C) expr(D) . { + A = new tokens.not({ + op: new tokens.LEXEME({ + type: C.lexeme, + value: C.value, + start: C.start, + end: C.end + }), + rexpr: D + }) +} + +eq(A) ::= id(B) EQ(C) literal(D) . { + A = new tokens.eq({ + id: B, + op: new tokens.LEXEME({ + type: C.lexeme, + value: C.value, + start: C.start, + end: C.end + }), + literal: D + }); +} + +neq(A) ::= id(B) NEQ(C) literal(D) . { + A = new tokens.neq({ + id: B, + op: new tokens.LEXEME({ + type: C.lexeme, + value: C.value, + start: C.start, + end: C.end + }), + literal: D + }); +} + +gt(A) ::= id(B) GT(C) literal(D) . { + A = new tokens.gt({ + id: B, + op: new tokens.LEXEME({ + type: C.lexeme, + value: C.value, + start: C.start, + end: C.end + }), + literal: D + }); +} + +gte(A) ::= id(B) GTE(C) literal(D) . { + A = new tokens.gte({ + id: B, + op: new tokens.LEXEME({ + type: C.lexeme, + value: C.value, + start: C.start, + end: C.end + }), + literal: D + }); +} + +lt(A) ::= id(B) LT(C) literal(D) . { + A = new tokens.lt({ + id: B, + op: new tokens.LEXEME({ + type: C.lexeme, + value: C.value, + start: C.start, + end: C.end + }), + literal: D + }); +} + +lte(A) ::= id(B) LTE(C) literal(D) . { + A = new tokens.lte({ + id: B, + op: new tokens.LEXEME({ + type: C.lexeme, + value: C.value, + start: C.start, + end: C.end + }), + literal: D + }); +} + +like(A) ::= id(B) LIKE(C) literal(D) . { + A = new tokens.like({ + id: B, + op: new tokens.LEXEME({ + type: C.lexeme, + value: C.value, + start: C.start, + end: C.end + }), + literal: D + }); +} + +nlike(A) ::= id(B) NLIKE(C) literal(D) . { + A = new tokens.nlike({ + id: B, + op: new tokens.LEXEME({ + type: C.lexeme, + value: C.value, + start: C.start, + end: C.end + }), + literal: D + }); +} + +expr(A) ::= and(B) . { + A = B; +} + +expr(A) ::= or(B) . { + A = B; +} + +expr(A) ::= not(B) . { + A = B; +} + +expr(A) ::= eq(B) . { + A = B; +} + +expr(A) ::= neq(B) . { + A = B; +} + +expr(A) ::= gt(B) . { + A = B; +} + +expr(A) ::= gte(B) . { + A = B; +} + +expr(A) ::= lt(B) . { + A = B; +} + +expr(A) ::= lte(B) . { + A = B; +} + +expr(A) ::= like(B) . { + A = B; +} + +expr(A) ::= nlike(B) . { + A = B; +} + +expr(A) ::= LCB(B) expr(C) RCB(D) . { + A = new tokens.sub_expr({ + LCB: new tokens.LEXEME({ + type: B.lexeme, + value: B.value, + start: B.start, + end: B.end + }), + expr: C, + RCB: new tokens.LEXEME({ + type: D.lexeme, + value: D.value, + start: D.start, + end: D.end + }) + }); +} + +address_literal_content(A) ::= string_literal(B) . { + A = new tokens.address_literal_content({ + children: [B] + }); +} + +address_literal_content(A) ::= address_literal_content(B) COMMA string_literal(C) . { + B.add(C); A = B; } @@ -132,21 +333,117 @@ address_literal_content_or_empty(A) ::= address_literal_content(B) . { } address_literal_content_or_empty(A) ::= . { - A = new Node({ - type: "address_literal_content" + A = new tokens.address_literal_content({ + children: [] }); } -address_literal(A) ::= ADDRESS LSB address_literal_content_or_empty(C) RSB . { - A = new Node({ - type: "address_literal", - children: C.children +address_literal(A) ::= ADDRESS(B) LSB(C) address_literal_content_or_empty(D) RSB(E) . { + A = new tokens.address_literal({ + children: D.children, + keyword: new tokens.LEXEME({ + type: B.lexeme, + value: B.value, + start: B.start, + end: B.end + }), + LSB: new tokens.LEXEME({ + type: C.lexeme, + value: C.value, + start: C.start, + end: C.end + }), + RSB: new tokens.LEXEME({ + type: E.lexeme, + value: E.value, + start: E.start, + end: E.end + }) }); } literal(A) ::= address_literal(B) . { - A = new Node({ - type: "literal", + A = B; +} + +oid_literal_content(A) ::= id(B) . { + A = new tokens.oid_literal_content({ children: [B] }); } + +oid_literal_content(A) ::= oid_literal_content(B) DOT id(C) . { + B.add(C); + A = B; +} + +oid_literal_content_or_empty(A) ::= oid_literal_content(B) . { + A = B; +} + +oid_literal_content_or_empty(A) ::= . { + A = new tokens.oid_literal_content({ + children: [] + }); +} + +oid_literal(A) ::= OID(B) LSB(C) oid_literal_content_or_empty(D) RSB(E) . { + A = new tokens.oid_literal({ + children: D.children, + keyword: new tokens.LEXEME({ + type: B.lexeme, + value: B.value, + start: B.start, + end: B.end + }), + LSB: new tokens.LEXEME({ + type: C.lexeme, + value: C.value, + start: C.start, + end: C.end + }), + RSB: new tokens.LEXEME({ + type: E.lexeme, + value: E.value, + start: E.start, + end: E.end + }) + }); +} + +literal(A) ::= oid_literal(B) . { + A = B; +} + +time_diff_literal(A) ::= TIMEDIFF(KWD) LSB(B) integer_literal(DAYS) integer_literal(HH) COLON integer_literal(MM) COLON integer_literal(SS) integer_literal(MS) RSB(C) . { + A = new tokens.time_diff_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 + }), + days: DAYS, + hours: HH, + minutes: MM, + seconds: SS, + microseconds: MS, + }); +} + +literal(A) ::= time_diff_literal(B) . { + A = B; +} + diff --git a/process.js b/process.js index b1dea3f..fd36e18 100644 --- a/process.js +++ b/process.js @@ -178,6 +178,7 @@ var tokens = (function () { class_check: class_check }; })(); + var tools = { merge: function (_obj) { var target = Object.create(null); @@ -237,20 +238,51 @@ var tokens = (function () { } }); - var string_literal = std.class([Rule], { - constructor: function string_literal(_options) { + 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); - var integer_literal = std.class([Rule], { + terminal_literal.call(this, base); + } + }); + + var integer_literal = std.class([terminal_literal], { constructor: function integer_literal(_options) { var base = tools.merge({}, _options); - Rule.call(this, base); + 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); } }); @@ -259,87 +291,312 @@ var tokens = (function () { 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 eq = std.class([Rule], { - constructor: function eq(_options) { - var base = tools.merge({ - id: null, - EQ: null, - literal: null - }, _options); - - Rule.call(this, base); - - this.id = base.id; - this.EQ = base.EQ; - this.literal = base.literal; - }, - set_id: function (_n) { - this._id = _n; - }, - set_EQ: function (_n) { - this._EQ = _n; - }, - set_literal: function (_n) { - this._literal = _n; - } - }); - - var and = std.class([Rule], { - constructor: function and(_options) { + var expr_compares = std.class([Rule], { + constructor: function expr_compares(_options) { var base = tools.merge({ lexpr: null, - AND: null, + op: null, rexpr: null }, _options); Rule.call(this, base); this.lexpr = base.lexpr; - this.AND = base.AND; + this.op = base.op; this.rexpr = base.rexpr; }, - set_lexpr: function (_n) { - this._lexpr = _n; - }, - set_AND: function (_n) { - this._AND = _n; - }, - set_rexpr: function (_n) { - this._rexpr = _n; + position: function () { + return { + start: this.lexpr.position().start, + end: this.rexpr.position().end, + } } }); - var expr = std.class([Rule], { + 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 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, - // non terminal + // not terminal + id: id, string_literal: string_literal, integer_literal: integer_literal, - id: id, - literal: literal, - eq: eq, + 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, - expr: expr, + 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, } })(); @@ -349,22 +606,48 @@ var tokens = (function () { 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()) { - console.log("PARSE", token.lexeme); - parser.parse(parser["TOKEN_" + token.lexeme], token); + if(token.error === 0) { + console.log("PARSE", token.lexeme); + parser.parse(parser["TOKEN_" + token.lexeme], token); + } } parser.parse(); return _result; }; -fs.mkdirSync("tests"); +if(!fs.existsSync("tests")) { + fs.mkdirSync("tests"); +} var test_and = LemonJS("abc == 1 and abc1 == 2 and (bbc == 5)"); -fs.writeFileSync("tests/out_test_and.json", JSON.stringify(test_and, true, 3)); +fs.writeFileSync("tests/test_and.json", JSON.stringify(test_and, true, 3)); var test_address = LemonJS('abc == Address ["a", "b", "c"]'); -fs.writeFileSync("tests/out_tree_address.json", JSON.stringify(test_address, true, 3)); +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)); diff --git a/tests/out_test_and.json b/tests/out_test_and.json deleted file mode 100644 index 31c6466..0000000 --- a/tests/out_test_and.json +++ /dev/null @@ -1,153 +0,0 @@ -{ - "root_node": { - "type": "and", - "children": [ - { - "type": "and", - "children": [ - { - "type": "expr", - "children": [ - { - "type": "eq", - "children": [ - { - "type": "ID", - "children": [], - "lexeme": "ID", - "start": 0, - "end": 3 - }, - { - "type": "EQ", - "children": [], - "lexeme": "EQ", - "start": 4, - "end": 6 - }, - { - "type": "literal", - "children": [ - { - "type": "INTEGER_LITERAL", - "children": [], - "lexeme": "INTEGER_LITERAL", - "start": 7, - "end": 8 - } - ], - "lexeme": null, - "start": 0, - "end": 0 - } - ], - "lexeme": null, - "start": 0, - "end": 0 - } - ], - "lexeme": null, - "start": 0, - "end": 0 - }, - { - "type": "expr", - "children": [ - { - "type": "eq", - "children": [ - { - "type": "ID", - "children": [], - "lexeme": "ID", - "start": 13, - "end": 17 - }, - { - "type": "EQ", - "children": [], - "lexeme": "EQ", - "start": 18, - "end": 20 - }, - { - "type": "literal", - "children": [ - { - "type": "INTEGER_LITERAL", - "children": [], - "lexeme": "INTEGER_LITERAL", - "start": 21, - "end": 22 - } - ], - "lexeme": null, - "start": 0, - "end": 0 - } - ], - "lexeme": null, - "start": 0, - "end": 0 - } - ], - "lexeme": null, - "start": 0, - "end": 0 - } - ], - "lexeme": null, - "start": 0, - "end": 0 - }, - { - "type": "expr", - "children": [ - { - "type": "eq", - "children": [ - { - "type": "ID", - "children": [], - "lexeme": "ID", - "start": 28, - "end": 31 - }, - { - "type": "EQ", - "children": [], - "lexeme": "EQ", - "start": 32, - "end": 34 - }, - { - "type": "literal", - "children": [ - { - "type": "INTEGER_LITERAL", - "children": [], - "lexeme": "INTEGER_LITERAL", - "start": 35, - "end": 36 - } - ], - "lexeme": null, - "start": 0, - "end": 0 - } - ], - "lexeme": null, - "start": 0, - "end": 0 - } - ], - "lexeme": null, - "start": 0, - "end": 0 - } - ], - "lexeme": null, - "start": 0, - "end": 0 - } -} \ No newline at end of file diff --git a/tests/out_tree_address.json b/tests/out_tree_address.json deleted file mode 100644 index 809b86e..0000000 --- a/tests/out_tree_address.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "root_node": { - "type": "expr", - "children": [ - { - "type": "eq", - "children": [ - { - "type": "ID", - "children": [], - "lexeme": "ID", - "start": 0, - "end": 3 - }, - { - "type": "EQ", - "children": [], - "lexeme": "EQ", - "start": 4, - "end": 6 - }, - { - "type": "literal", - "children": [ - { - "type": "address_literal", - "children": [ - { - "type": "STRING_LITERAL", - "children": [], - "lexeme": "STRING_LITERAL", - "start": 16, - "end": 19 - }, - { - "type": "STRING_LITERAL", - "children": [], - "lexeme": "STRING_LITERAL", - "start": 21, - "end": 24 - }, - { - "type": "STRING_LITERAL", - "children": [], - "lexeme": "STRING_LITERAL", - "start": 26, - "end": 29 - } - ], - "lexeme": null, - "start": 0, - "end": 0 - } - ], - "lexeme": null, - "start": 0, - "end": 0 - } - ], - "lexeme": null, - "start": 0, - "end": 0 - } - ], - "lexeme": null, - "start": 0, - "end": 0 - } -} \ No newline at end of file