oid add to lexer

This commit is contained in:
Aleksey Chichenkov 2019-01-28 18:36:41 +03:00
parent a5991c4e55
commit 37563c749f
3 changed files with 10 additions and 8 deletions

10
lexer.l
View File

@ -19,6 +19,7 @@ var types = [
"OR", "OR",
"NOT", "NOT",
"ADDRESS", "ADDRESS",
"OID",
"TIME", "TIME",
"TIMEDIFF", "TIMEDIFF",
"INTEGER_LITERAL", "INTEGER_LITERAL",
@ -74,9 +75,10 @@ Lexer.prototype = {
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))); 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 = { this._last_found_lexeme = {
error: 0, error: 0,
lexeme: _lexeme, lexeme: _lexeme,
start: this._yy_lex_start, value: this._string.substring(this._yy_lex_start, this._yy_cursor),
end: this._yy_cursor start: this._yy_lex_start,
end: this._yy_cursor
}; };
}, },
_endOfString: function(){ _endOfString: function(){
@ -187,6 +189,7 @@ Lexer.prototype = {
ADDRESS = "Address"; ADDRESS = "Address";
TIME = "Time"; TIME = "Time";
OID = "Oid";
TIMEDIFF = "TimeDiff"; TIMEDIFF = "TimeDiff";
BOOL_LITERAL = 'true'|'false'; BOOL_LITERAL = 'true'|'false';
@ -227,6 +230,7 @@ Lexer.prototype = {
ADDRESS { this._foundLexeme("ADDRESS"); this._set_next(); return; } ADDRESS { this._foundLexeme("ADDRESS"); this._set_next(); return; }
TIME { this._foundLexeme("TIME"); this._set_next(); return; } TIME { this._foundLexeme("TIME"); this._set_next(); return; }
TIMEDIFF { this._foundLexeme("TIMEDIFF"); this._set_next(); return; } TIMEDIFF { this._foundLexeme("TIMEDIFF"); this._set_next(); return; }
OID { this._foundLexeme("OID"); this._set_next(); return; }
INTEGER_LITERAL { this._foundLexeme("INTEGER_LITERAL"); this._set_next(); return; } INTEGER_LITERAL { this._foundLexeme("INTEGER_LITERAL"); this._set_next(); return; }
FLOAT_LITERAL { this._foundLexeme("FLOAT_LITERAL"); this._set_next(); return; } FLOAT_LITERAL { this._foundLexeme("FLOAT_LITERAL"); this._set_next(); return; }

View File

@ -42,7 +42,7 @@ var post_process_lexer = function (_string) {
if(args["t"] !== undefined) { if(args["t"] !== undefined) {
switch (args["t"]) { switch (args["t"]) {
case "web": case "web":
_string = "(function(){\n" + _string + "return Lexer; \n})"; _string = "(function(){\n" + _string + "return Lexer; \n})()";
break; break;
case "node": case "node":
_string += "\n module.exports = Lexer"; _string += "\n module.exports = Lexer";

View File

@ -8,10 +8,6 @@ exec("node main.js -o=lexer_test.js -t=node", function(err, stdout, stderr) {
err && console.log("ERROR: ", err); err && console.log("ERROR: ", err);
err && process.exit(1); err && process.exit(1);
var file = fs.readFileSync("lexer_test.js", "utf8");
file += "\n module.exports = Lexer";
fs.writeFileSync("lexer_test.js", file);
test(); test();
fs.unlinkSync("lexer_test.js"); fs.unlinkSync("lexer_test.js");
@ -46,6 +42,7 @@ var test = function() {
(new Lexer("NLIKE")).search(); (new Lexer("NLIKE")).search();
(new Lexer("nlike")).search(); (new Lexer("nlike")).search();
(new Lexer("Address")).search(); (new Lexer("Address")).search();
(new Lexer("Oid")).search();
(new Lexer("Time")).search(); (new Lexer("Time")).search();
(new Lexer("TimeDiff")).search(); (new Lexer("TimeDiff")).search();
@ -59,4 +56,5 @@ var test = function() {
(new Lexer(' "111\\\"11\\\"1" "222222" ')).search(); (new Lexer(' "111\\\"11\\\"1" "222222" ')).search();
(new Lexer(" '111\\\'11\\\'1' '222222' ")).search(); (new Lexer(" '111\\\'11\\\'1' '222222' ")).search();
console.log("\nSuccess tests\n");
}; };