Skip to content

Commit 59da3a8

Browse files
committed
issue #14
1 parent c284a9c commit 59da3a8

File tree

8 files changed

+41
-50
lines changed

8 files changed

+41
-50
lines changed

Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ module.exports = function(grunt) {
4646
'src/sugar/insertInto.js',
4747
'src/sugar/dropTable.js',
4848
'src/sugar/deleteFrom.js',
49+
'src/sugar/tokenize.js',
4950
'src/helpers/jSQLReset.js',
5051
'src/helpers/jSQLMinifier.js',
5152
'src/helpers/removeQuotes.js',

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![jSQL Logo](http://i.imgur.com/VQlJKOc.png)](http://pamblam.github.io/jSQL/)
22

3-
jSQL (Official) - Version 3.0.1 - *Now available without a prescription!*
3+
jSQL (Official) - Version 3.0.2 - *Now available without a prescription!*
44

55
[![npm version](https://badge.fury.io/js/jsql-official.svg)](https://badge.fury.io/js/jsql-official) [![Build Status](https://travis-ci.org/Pamblam/jSQL.svg?branch=master)](https://travis-ci.org/Pamblam/jSQL) [![Inline docs](http://inch-ci.org/github/Pamblam/jSQL.svg?branch=master)](https://github.com/Pamblam/jSQL/wiki) [![Code Climate](https://codeclimate.com/github/Pamblam/jSQL/badges/gpa.svg)](https://codeclimate.com/github/Pamblam/jSQL) [![Coverage Status](https://coveralls.io/repos/github/Pamblam/jSQL/badge.svg?branch=master)](https://coveralls.io/github/Pamblam/jSQL?branch=master)
66

jSQL.js

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* jsql-official - v3.0.1
2+
* jsql-official - v3.0.2
33
* A persistent SQL database.
44
* @author Rob Parham
55
* @website http://pamblam.github.io/jSQL/
@@ -1076,36 +1076,26 @@ function jSQLLexer(input) {
10761076
this.token_matches = [];
10771077
}
10781078

1079-
jSQLLexer.prototype.getTokenMatches = function(){
1080-
if(this.token_matches.length) return this.token_matches;
1081-
this.token_matches = []
1079+
jSQLLexer.prototype.getNextToken = function(){
10821080
var r;
10831081
for(var i=0; i<jSQLLexer.token_types.length; i++){
1084-
this.token_matches[i] = [];
10851082
while ((r = jSQLLexer.token_types[i].pattern.exec(this.input)) != null) {
1086-
this.token_matches[i].push(r);
1083+
if(r.index !== this.pos) continue;
1084+
var token = new jSQLToken(this.pos, r[0], i);
1085+
this.pos += token.length;
1086+
return token;
10871087
}
10881088
}
1089-
return this.token_matches;
1089+
return false;
10901090
};
10911091

10921092
jSQLLexer.prototype.getTokens = function(){
10931093
if(this.tokens.length) return this.tokens;
1094-
this.pos = 0;
1095-
var matches = this.getTokenMatches(),
1096-
throwaway = ["COMMENT", "WHITESPACE"];
1097-
for(var type_id=0; type_id<matches.length; type_id++){
1098-
if(this.pos >= this.input.length) break;
1099-
for(var match_index=0; match_index<matches[type_id].length; match_index++){
1100-
var r = matches[type_id][match_index];
1101-
if(r.index !== this.pos) continue;
1102-
var token = new jSQLToken(this.pos, r[0], type_id);
1103-
this.pos += token.length;
1104-
if(throwaway.indexOf(token.type) === -1) this.tokens.push(token);
1105-
type_id=-1;
1106-
break;
1107-
}
1108-
}
1094+
this.pos = 0; this.tokens = [];
1095+
var throwaway = ["COMMENT", "WHITESPACE"], token;
1096+
while ((token = this.getNextToken()) != false)
1097+
if(throwaway.indexOf(token.type) === -1)
1098+
this.tokens.push(token);
11091099
if(this.pos !== this.input.length){
11101100
var pos;
11111101
if(this.tokens.length){
@@ -2686,6 +2676,10 @@ function deleteFrom(tablename){
26862676
}
26872677

26882678

2679+
function tokenize(sql){
2680+
return new jSQLLexer(sql).getTokens();
2681+
}
2682+
26892683
function jSQLReset(){
26902684
jSQL.tables = {};
26912685
jSQL.commit();
@@ -2707,7 +2701,7 @@ function removeQuotes(str){
27072701
}
27082702

27092703
return {
2710-
version: "3.0.1",
2704+
version: "3.0.2",
27112705
tables: {},
27122706
query: jSQLParseQuery,
27132707
createTable: createTable,
@@ -2724,7 +2718,8 @@ return {
27242718
commit: persistenceManager.commit,
27252719
rollback: persistenceManager.rollback,
27262720
setApiPriority: persistenceManager.setApiPriority,
2727-
getApi: persistenceManager.getApi
2721+
getApi: persistenceManager.getApi,
2722+
tokenize: tokenize
27282723
};
27292724

27302725
})();

jSQL.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsql-official",
3-
"version": "3.0.1",
3+
"version": "3.0.2",
44
"description": "A persistent SQL database.",
55
"main": "jSQL.min.js",
66
"directories": {

src/lexer/jSQLLexer.js

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,26 @@ function jSQLLexer(input) {
88
this.token_matches = [];
99
}
1010

11-
jSQLLexer.prototype.getTokenMatches = function(){
12-
if(this.token_matches.length) return this.token_matches;
13-
this.token_matches = []
11+
jSQLLexer.prototype.getNextToken = function(){
1412
var r;
1513
for(var i=0; i<jSQLLexer.token_types.length; i++){
16-
this.token_matches[i] = [];
1714
while ((r = jSQLLexer.token_types[i].pattern.exec(this.input)) != null) {
18-
this.token_matches[i].push(r);
15+
if(r.index !== this.pos) continue;
16+
var token = new jSQLToken(this.pos, r[0], i);
17+
this.pos += token.length;
18+
return token;
1919
}
2020
}
21-
return this.token_matches;
21+
return false;
2222
};
2323

2424
jSQLLexer.prototype.getTokens = function(){
2525
if(this.tokens.length) return this.tokens;
26-
this.pos = 0;
27-
var matches = this.getTokenMatches(),
28-
throwaway = ["COMMENT", "WHITESPACE"];
29-
for(var type_id=0; type_id<matches.length; type_id++){
30-
if(this.pos >= this.input.length) break;
31-
for(var match_index=0; match_index<matches[type_id].length; match_index++){
32-
var r = matches[type_id][match_index];
33-
if(r.index !== this.pos) continue;
34-
var token = new jSQLToken(this.pos, r[0], type_id);
35-
this.pos += token.length;
36-
if(throwaway.indexOf(token.type) === -1) this.tokens.push(token);
37-
type_id=-1;
38-
break;
39-
}
40-
}
26+
this.pos = 0; this.tokens = [];
27+
var throwaway = ["COMMENT", "WHITESPACE"], token;
28+
while ((token = this.getNextToken()) != false)
29+
if(throwaway.indexOf(token.type) === -1)
30+
this.tokens.push(token);
4131
if(this.pos !== this.input.length){
4232
var pos;
4333
if(this.tokens.length){

src/sugar/tokenize.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
function tokenize(sql){
3+
return new jSQLLexer(sql).getTokens();
4+
}

src/wrapper/foot.js.part

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ return {
1717
commit: persistenceManager.commit,
1818
rollback: persistenceManager.rollback,
1919
setApiPriority: persistenceManager.setApiPriority,
20-
getApi: persistenceManager.getApi
20+
getApi: persistenceManager.getApi,
21+
tokenize: tokenize
2122
};
2223

2324
})();

0 commit comments

Comments
 (0)