Skip to content
This repository was archived by the owner on Jul 15, 2021. It is now read-only.

Commit ea33703

Browse files
committed
Merge pull request #14 from codeschool/performance
Speed up performance by reducing rule count.
2 parents f7bb184 + 8559684 commit ea33703

11 files changed

Lines changed: 2410 additions & 2321 deletions

Gruntfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ module.exports = function(grunt) {
122122
livereload: false
123123
},
124124
files: [
125-
'index.js', 'test/*.js', 'src/*.js', 'src/*.pegjs',
126-
'test/sql/*.sql', 'Gruntfile.js'
125+
'index.js', 'test/**/*.js', 'src/*.js', 'src/*.pegjs',
126+
'test/sql/**/*.sql', 'test/json/**/*.json', 'Gruntfile.js'
127127
],
128128
tasks: ['build', 'shell:debug']
129129
},

demo/css/sqlite-parser-demo.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/js/sqlite-parser-demo.js

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

dist/sqlite-parser-min.js

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

dist/sqlite-parser.js

Lines changed: 1186 additions & 1122 deletions
Large diffs are not rendered by default.

lib/parser-util.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@ function compose(args, glue) {
5656
}
5757
res = args.reduce(function (prev, cur) {
5858
return conc ? (isOkay(cur) ? prev.concat(cur) : prev) :
59-
(prev + (isOkay(cur) ? textNode(cur) + glue : ''));
59+
(prev + (isOkay(cur) ? textCompose(cur) + glue : ''));
6060
}, start);
61-
return conc ? res : res.trim();
61+
return conc ? res : textNode(res);
62+
}
63+
64+
function textCompose(arg) {
65+
return nodeToString(isArray(arg) ? arg.join('') : arg);
6266
}
6367

6468
function stack(arr) {

lib/parser.js

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

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "sqlite-parser",
33
"description": "JavaScript implentation of SQLite 3 query parser",
44
"author": "Code School (http://codeschool.com)",
5-
"version": "0.12.3",
5+
"version": "0.13.0",
66
"contributors": [
77
"Nick Wronski <nick@javascript.com>"
88
],
@@ -30,25 +30,25 @@
3030
"test": "grunt test"
3131
},
3232
"devDependencies": {
33-
"chai": "^3.4.1",
34-
"codemirror": "^5.9.0",
33+
"chai": "^3.5.0",
34+
"codemirror": "^5.12.0",
3535
"grunt": "^0.4.5",
3636
"grunt-banner": "^0.6.0",
3737
"grunt-browserify": "^4.0.1",
38-
"grunt-contrib-clean": "^0.7.0",
39-
"grunt-contrib-connect": "^0.11.2",
40-
"grunt-contrib-copy": "^0.8.2",
41-
"grunt-contrib-cssmin": "^0.14.0",
42-
"grunt-contrib-uglify": "^0.11.0",
38+
"grunt-contrib-clean": "^1.0.0",
39+
"grunt-contrib-connect": "^1.0.0",
40+
"grunt-contrib-copy": "^1.0.0",
41+
"grunt-contrib-cssmin": "^1.0.0",
42+
"grunt-contrib-uglify": "^1.0.0",
4343
"grunt-contrib-watch": "^0.6.1",
4444
"grunt-replace": "^0.11.0",
45-
"grunt-shell": "^1.1.2",
46-
"load-grunt-tasks": "^3.3.0",
47-
"lodash": "^3.10.1",
48-
"mocha": "^2.3.4",
45+
"grunt-shell": "^1.2.1",
46+
"load-grunt-tasks": "^3.4.1",
47+
"lodash": "^4.6.1",
48+
"mocha": "^2.4.5",
4949
"pegjs": "git+https://github.com/dmajda/pegjs.git#master",
5050
"prettyjson": "^1.1.3",
51-
"promise": "^7.0.4"
51+
"promise": "^7.1.1"
5252
},
5353
"dependencies": {}
5454
}

src/grammar.pegjs

Lines changed: 13 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
/* Start Grammar */
99
start
10-
= o s:( stmt_list )?
10+
= o semi_optional s:( stmt_list )? semi_optional
1111
{
1212
return util.extend({}, s);
1313
}
1414

1515
stmt_list
16-
= semi_optional f:( stmt ) o b:( stmt_list_tail )* semi_optional
16+
= f:( stmt ) o b:( stmt_list_tail )*
1717
{
1818
return {
1919
'statement': util.listify(f, b)
@@ -2458,12 +2458,8 @@ datatype_real "REAL Datatype Name"
24582458
{ return util.key(t); }
24592459

24602460
datatype_real_double "DOUBLE Datatype Name"
2461-
= d:( "DOUBLE"i ) p:( real_double_precision )?
2462-
{ return util.compose([d, p]); }
2463-
2464-
real_double_precision
2465-
= e p:( "PRECISION"i )
2466-
{ return p; }
2461+
= d:( "DOUBLE"i ) p:( [\t ]+ "PRECISION"i )?
2462+
{ return util.compose([d, p], ''); }
24672463

24682464
datatype_numeric "NUMERIC Datatype Name"
24692465
= t:( "NUMERIC"i
@@ -2510,36 +2506,23 @@ name_unquoted
25102506

25112507
/** @note Non-standard legacy format */
25122508
name_bracketed
2513-
= sym_bopen n:( name_bracketed_schar )+ o sym_bclose
2509+
= sym_bopen n:( !( [ \t]* "]" ) [^\]] )+ o sym_bclose
25142510
{ return util.textNode(n); }
25152511

2516-
name_bracketed_schar
2517-
= !( whitespace_space* "]" ) n:( [^\]] )
2518-
{ return n; }
2519-
25202512
name_dblquoted
2521-
= '"' n:( name_dblquoted_schar )+ '"'
2513+
= '"' n:( '""' / [^\"] )+ '"'
25222514
{ return util.unescape(n, '"'); }
25232515

2524-
name_dblquoted_schar
2525-
= '""' / [^\"]
2526-
25272516
/** @note Non-standard format */
25282517
name_sglquoted
2529-
= "'" n:( name_sglquoted_schar )+ "'"
2518+
= "'" n:( "''" / [^\'] )+ "'"
25302519
{ return util.unescape(n, "'"); }
25312520

2532-
name_sglquoted_schar
2533-
= "''" / [^\']
2534-
25352521
/** @note Non-standard legacy format */
25362522
name_backticked
2537-
= '`' n:( name_backticked_schar )+ '`'
2523+
= '`' n:( '``' / [^\`] )+ '`'
25382524
{ return util.unescape(n, '`'); }
25392525

2540-
name_backticked_schar
2541-
= '``' / [^\`]
2542-
25432526
/* Symbols */
25442527

25452528
sym_bopen "Open Bracket"
@@ -2879,10 +2862,7 @@ comment
28792862
{ return null; }
28802863

28812864
comment_line "Line Comment"
2882-
= comment_line_start ( !whitespace_line match_all )*
2883-
2884-
comment_line_start
2885-
= "--"
2865+
= "--" ( ![\n\v\f\r] . )*
28862866

28872867
comment_block "Block Comment"
28882868
= comment_block_start comment_block_feed comment_block_end
@@ -2894,43 +2874,19 @@ comment_block_end
28942874
= "*/"
28952875

28962876
comment_block_body
2897-
= ( !( comment_block_end / comment_block_start ) match_all )+
2877+
= ( !( comment_block_end / comment_block_start ) . )+
28982878

28992879
block_body_nodes
29002880
= comment_block_body / comment_block
29012881

29022882
comment_block_feed
2903-
= block_body_nodes ( whitespace / block_body_nodes )*
2904-
2905-
match_all
2906-
= .
2907-
/*= [\s\S]*/
2883+
= block_body_nodes ( [\n\v\f\r\t ] / block_body_nodes )*
29082884

29092885
/* Optional Whitespace */
2910-
o
2911-
= n:( whitespace_nodes )*
2912-
{ return n; }
2913-
2914-
/* Enforced Whitespace */
2915-
e
2916-
= n:( whitespace_nodes )+
2886+
o "Whitespace"
2887+
= n:( [\n\v\f\r\t ] / comment )*
29172888
{ return n; }
29182889

2919-
whitespace_nodes
2920-
= whitespace
2921-
/ comment
2922-
2923-
/* Whitespace */
2924-
whitespace
2925-
= whitespace_space
2926-
/ whitespace_line
2927-
2928-
whitespace_space "Whitespace"
2929-
= [ \t]
2930-
2931-
whitespace_line "New Line"
2932-
= [\n\v\f\r]
2933-
29342890
/* TODO: Everything with this symbol */
29352891
_TODO_
29362892
= "__TODO__"

src/parser-util.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@ function compose(args, glue) {
5656
}
5757
res = args.reduce(function (prev, cur) {
5858
return conc ? (isOkay(cur) ? prev.concat(cur) : prev) :
59-
(prev + (isOkay(cur) ? textNode(cur) + glue : ''));
59+
(prev + (isOkay(cur) ? textCompose(cur) + glue : ''));
6060
}, start);
61-
return conc ? res : res.trim();
61+
return conc ? res : textNode(res);
62+
}
63+
64+
function textCompose(arg) {
65+
return nodeToString(isArray(arg) ? arg.join('') : arg);
6266
}
6367

6468
function stack(arr) {

0 commit comments

Comments
 (0)