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

Commit

Permalink
Speed up performance by reducing rule count.
Browse files Browse the repository at this point in the history
Going to do a sweep of the rules and consolidate them
where possible. If a rule is only used by exactly one other
rule then I am going to rewrite the grammar without
creating that separate rule.
  • Loading branch information
nwronski committed Mar 8, 2016
1 parent f7bb184 commit 8559684
Show file tree
Hide file tree
Showing 11 changed files with 2,410 additions and 2,321 deletions.
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ module.exports = function(grunt) {
livereload: false
},
files: [
'index.js', 'test/*.js', 'src/*.js', 'src/*.pegjs',
'test/sql/*.sql', 'Gruntfile.js'
'index.js', 'test/**/*.js', 'src/*.js', 'src/*.pegjs',
'test/sql/**/*.sql', 'test/json/**/*.json', 'Gruntfile.js'
],
tasks: ['build', 'shell:debug']
},
Expand Down
2 changes: 1 addition & 1 deletion demo/css/sqlite-parser-demo.css

Large diffs are not rendered by default.

25 changes: 13 additions & 12 deletions demo/js/sqlite-parser-demo.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions dist/sqlite-parser-min.js

Large diffs are not rendered by default.

2,308 changes: 1,186 additions & 1,122 deletions dist/sqlite-parser.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions lib/parser-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ function compose(args, glue) {
}
res = args.reduce(function (prev, cur) {
return conc ? (isOkay(cur) ? prev.concat(cur) : prev) :
(prev + (isOkay(cur) ? textNode(cur) + glue : ''));
(prev + (isOkay(cur) ? textCompose(cur) + glue : ''));
}, start);
return conc ? res : res.trim();
return conc ? res : textNode(res);
}

function textCompose(arg) {
return nodeToString(isArray(arg) ? arg.join('') : arg);
}

function stack(arr) {
Expand Down
2,266 changes: 1,163 additions & 1,103 deletions lib/parser.js

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sqlite-parser",
"description": "JavaScript implentation of SQLite 3 query parser",
"author": "Code School (http://codeschool.com)",
"version": "0.12.3",
"version": "0.13.0",
"contributors": [
"Nick Wronski <nick@javascript.com>"
],
Expand Down Expand Up @@ -30,25 +30,25 @@
"test": "grunt test"
},
"devDependencies": {
"chai": "^3.4.1",
"codemirror": "^5.9.0",
"chai": "^3.5.0",
"codemirror": "^5.12.0",
"grunt": "^0.4.5",
"grunt-banner": "^0.6.0",
"grunt-browserify": "^4.0.1",
"grunt-contrib-clean": "^0.7.0",
"grunt-contrib-connect": "^0.11.2",
"grunt-contrib-copy": "^0.8.2",
"grunt-contrib-cssmin": "^0.14.0",
"grunt-contrib-uglify": "^0.11.0",
"grunt-contrib-clean": "^1.0.0",
"grunt-contrib-connect": "^1.0.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-cssmin": "^1.0.0",
"grunt-contrib-uglify": "^1.0.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-replace": "^0.11.0",
"grunt-shell": "^1.1.2",
"load-grunt-tasks": "^3.3.0",
"lodash": "^3.10.1",
"mocha": "^2.3.4",
"grunt-shell": "^1.2.1",
"load-grunt-tasks": "^3.4.1",
"lodash": "^4.6.1",
"mocha": "^2.4.5",
"pegjs": "git+https://github.com/dmajda/pegjs.git#master",
"prettyjson": "^1.1.3",
"promise": "^7.0.4"
"promise": "^7.1.1"
},
"dependencies": {}
}
70 changes: 13 additions & 57 deletions src/grammar.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

/* Start Grammar */
start
= o s:( stmt_list )?
= o semi_optional s:( stmt_list )? semi_optional
{
return util.extend({}, s);
}

stmt_list
= semi_optional f:( stmt ) o b:( stmt_list_tail )* semi_optional
= f:( stmt ) o b:( stmt_list_tail )*
{
return {
'statement': util.listify(f, b)
Expand Down Expand Up @@ -2458,12 +2458,8 @@ datatype_real "REAL Datatype Name"
{ return util.key(t); }
datatype_real_double "DOUBLE Datatype Name"
= d:( "DOUBLE"i ) p:( real_double_precision )?
{ return util.compose([d, p]); }
real_double_precision
= e p:( "PRECISION"i )
{ return p; }
= d:( "DOUBLE"i ) p:( [\t ]+ "PRECISION"i )?
{ return util.compose([d, p], ''); }
datatype_numeric "NUMERIC Datatype Name"
= t:( "NUMERIC"i
Expand Down Expand Up @@ -2510,36 +2506,23 @@ name_unquoted
/** @note Non-standard legacy format */
name_bracketed
= sym_bopen n:( name_bracketed_schar )+ o sym_bclose
= sym_bopen n:( !( [ \t]* "]" ) [^\]] )+ o sym_bclose
{ return util.textNode(n); }
name_bracketed_schar
= !( whitespace_space* "]" ) n:( [^\]] )
{ return n; }
name_dblquoted
= '"' n:( name_dblquoted_schar )+ '"'
= '"' n:( '""' / [^\"] )+ '"'
{ return util.unescape(n, '"'); }
name_dblquoted_schar
= '""' / [^\"]
/** @note Non-standard format */
name_sglquoted
= "'" n:( name_sglquoted_schar )+ "'"
= "'" n:( "''" / [^\'] )+ "'"
{ return util.unescape(n, "'"); }
name_sglquoted_schar
= "''" / [^\']
/** @note Non-standard legacy format */
name_backticked
= '`' n:( name_backticked_schar )+ '`'
= '`' n:( '``' / [^\`] )+ '`'
{ return util.unescape(n, '`'); }
name_backticked_schar
= '``' / [^\`]
/* Symbols */
sym_bopen "Open Bracket"
Expand Down Expand Up @@ -2879,10 +2862,7 @@ comment
{ return null; }
comment_line "Line Comment"
= comment_line_start ( !whitespace_line match_all )*
comment_line_start
= "--"
= "--" ( ![\n\v\f\r] . )*
comment_block "Block Comment"
= comment_block_start comment_block_feed comment_block_end
Expand All @@ -2894,43 +2874,19 @@ comment_block_end
= "*/"
comment_block_body
= ( !( comment_block_end / comment_block_start ) match_all )+
= ( !( comment_block_end / comment_block_start ) . )+
block_body_nodes
= comment_block_body / comment_block
comment_block_feed
= block_body_nodes ( whitespace / block_body_nodes )*
match_all
= .
/*= [\s\S]*/
= block_body_nodes ( [\n\v\f\r\t ] / block_body_nodes )*
/* Optional Whitespace */
o
= n:( whitespace_nodes )*
{ return n; }
/* Enforced Whitespace */
e
= n:( whitespace_nodes )+
o "Whitespace"
= n:( [\n\v\f\r\t ] / comment )*
{ return n; }
whitespace_nodes
= whitespace
/ comment
/* Whitespace */
whitespace
= whitespace_space
/ whitespace_line
whitespace_space "Whitespace"
= [ \t]
whitespace_line "New Line"
= [\n\v\f\r]
/* TODO: Everything with this symbol */
_TODO_
= "__TODO__"
8 changes: 6 additions & 2 deletions src/parser-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ function compose(args, glue) {
}
res = args.reduce(function (prev, cur) {
return conc ? (isOkay(cur) ? prev.concat(cur) : prev) :
(prev + (isOkay(cur) ? textNode(cur) + glue : ''));
(prev + (isOkay(cur) ? textCompose(cur) + glue : ''));
}, start);
return conc ? res : res.trim();
return conc ? res : textNode(res);
}

function textCompose(arg) {
return nodeToString(isArray(arg) ? arg.join('') : arg);
}

function stack(arr) {
Expand Down
2 changes: 1 addition & 1 deletion test/core/parse-errors-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ describe('parse errors', function() {

it('parse error 1', function(done) {
tree.error({
'message': 'Expected Block Comment, Line Comment, New Line, Semicolon, Whitespace or end of input.'
'message': 'Expected Semicolon or end of input.'
}, this, done);
});

Expand Down

0 comments on commit 8559684

Please sign in to comment.