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

Commit 5edb732

Browse files
committed
Fix parse error with INTERSECT compound operator.
Thanks to @mstStudent for finding this bug. Closes #6
1 parent 3643973 commit 5edb732

6 files changed

Lines changed: 238 additions & 50 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
All notable changes to this project will be documented in this file.
33

44
## [Unreleased][unreleased]
5+
### Fixed
6+
- the parser picked up on `INT` instead of the full keyword `INTERSECT` in queries such as the following, causing a parse error:
7+
8+
``` sql
9+
SELECT a, b FROM table1
10+
INTERSECT
11+
SELECT * FROM table2
12+
```
513

614
## [v0.12.0] - 2015-09-29
715
### Changed

demo/js/sqlite-parser-demo.js

Lines changed: 9 additions & 9 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: 4 additions & 4 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: 106 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13612,48 +13612,138 @@ module.exports = (function() {
1361213612
}
1361313613

1361413614
function peg$parsedatatype_types() {
13615-
var s0, s1;
13615+
var s0, s1, s2, s3;
1361613616

1361713617
peg$silentFails++;
1361813618
s0 = peg$currPos;
1361913619
s1 = peg$parsedatatype_text();
1362013620
if (s1 !== peg$FAILED) {
13621-
peg$savedPos = s0;
13622-
s1 = peg$c444(s1);
13621+
s2 = peg$currPos;
13622+
peg$silentFails++;
13623+
s3 = peg$parsename_char();
13624+
peg$silentFails--;
13625+
if (s3 === peg$FAILED) {
13626+
s2 = void 0;
13627+
} else {
13628+
peg$currPos = s2;
13629+
s2 = peg$FAILED;
13630+
}
13631+
if (s2 !== peg$FAILED) {
13632+
peg$savedPos = s0;
13633+
s1 = peg$c444(s1);
13634+
s0 = s1;
13635+
} else {
13636+
peg$currPos = s0;
13637+
s0 = peg$FAILED;
13638+
}
13639+
} else {
13640+
peg$currPos = s0;
13641+
s0 = peg$FAILED;
1362313642
}
13624-
s0 = s1;
1362513643
if (s0 === peg$FAILED) {
1362613644
s0 = peg$currPos;
1362713645
s1 = peg$parsedatatype_real();
1362813646
if (s1 !== peg$FAILED) {
13629-
peg$savedPos = s0;
13630-
s1 = peg$c445(s1);
13647+
s2 = peg$currPos;
13648+
peg$silentFails++;
13649+
s3 = peg$parsename_char();
13650+
peg$silentFails--;
13651+
if (s3 === peg$FAILED) {
13652+
s2 = void 0;
13653+
} else {
13654+
peg$currPos = s2;
13655+
s2 = peg$FAILED;
13656+
}
13657+
if (s2 !== peg$FAILED) {
13658+
peg$savedPos = s0;
13659+
s1 = peg$c445(s1);
13660+
s0 = s1;
13661+
} else {
13662+
peg$currPos = s0;
13663+
s0 = peg$FAILED;
13664+
}
13665+
} else {
13666+
peg$currPos = s0;
13667+
s0 = peg$FAILED;
1363113668
}
13632-
s0 = s1;
1363313669
if (s0 === peg$FAILED) {
1363413670
s0 = peg$currPos;
1363513671
s1 = peg$parsedatatype_numeric();
1363613672
if (s1 !== peg$FAILED) {
13637-
peg$savedPos = s0;
13638-
s1 = peg$c446(s1);
13673+
s2 = peg$currPos;
13674+
peg$silentFails++;
13675+
s3 = peg$parsename_char();
13676+
peg$silentFails--;
13677+
if (s3 === peg$FAILED) {
13678+
s2 = void 0;
13679+
} else {
13680+
peg$currPos = s2;
13681+
s2 = peg$FAILED;
13682+
}
13683+
if (s2 !== peg$FAILED) {
13684+
peg$savedPos = s0;
13685+
s1 = peg$c446(s1);
13686+
s0 = s1;
13687+
} else {
13688+
peg$currPos = s0;
13689+
s0 = peg$FAILED;
13690+
}
13691+
} else {
13692+
peg$currPos = s0;
13693+
s0 = peg$FAILED;
1363913694
}
13640-
s0 = s1;
1364113695
if (s0 === peg$FAILED) {
1364213696
s0 = peg$currPos;
1364313697
s1 = peg$parsedatatype_integer();
1364413698
if (s1 !== peg$FAILED) {
13645-
peg$savedPos = s0;
13646-
s1 = peg$c447(s1);
13699+
s2 = peg$currPos;
13700+
peg$silentFails++;
13701+
s3 = peg$parsename_char();
13702+
peg$silentFails--;
13703+
if (s3 === peg$FAILED) {
13704+
s2 = void 0;
13705+
} else {
13706+
peg$currPos = s2;
13707+
s2 = peg$FAILED;
13708+
}
13709+
if (s2 !== peg$FAILED) {
13710+
peg$savedPos = s0;
13711+
s1 = peg$c447(s1);
13712+
s0 = s1;
13713+
} else {
13714+
peg$currPos = s0;
13715+
s0 = peg$FAILED;
13716+
}
13717+
} else {
13718+
peg$currPos = s0;
13719+
s0 = peg$FAILED;
1364713720
}
13648-
s0 = s1;
1364913721
if (s0 === peg$FAILED) {
1365013722
s0 = peg$currPos;
1365113723
s1 = peg$parsedatatype_none();
1365213724
if (s1 !== peg$FAILED) {
13653-
peg$savedPos = s0;
13654-
s1 = peg$c448(s1);
13725+
s2 = peg$currPos;
13726+
peg$silentFails++;
13727+
s3 = peg$parsename_char();
13728+
peg$silentFails--;
13729+
if (s3 === peg$FAILED) {
13730+
s2 = void 0;
13731+
} else {
13732+
peg$currPos = s2;
13733+
s2 = peg$FAILED;
13734+
}
13735+
if (s2 !== peg$FAILED) {
13736+
peg$savedPos = s0;
13737+
s1 = peg$c448(s1);
13738+
s0 = s1;
13739+
} else {
13740+
peg$currPos = s0;
13741+
s0 = peg$FAILED;
13742+
}
13743+
} else {
13744+
peg$currPos = s0;
13745+
s0 = peg$FAILED;
1365513746
}
13656-
s0 = s1;
1365713747
}
1365813748
}
1365913749
}

lib/parser.js

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

src/grammar.pegjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,11 +2449,11 @@ id_constraint_column "Column Constraint Identifier"
24492449
/* Column datatypes */
24502450

24512451
datatype_types "Datatype Name"
2452-
= t:( datatype_text ) { return [t, 'text']; }
2453-
/ t:( datatype_real ) { return [t, 'real']; }
2454-
/ t:( datatype_numeric ) { return [t, 'numeric']; }
2455-
/ t:( datatype_integer ) { return [t, 'integer']; }
2456-
/ t:( datatype_none ) { return [t, 'none']; }
2452+
= t:( datatype_text ) !name_char { return [t, 'text']; }
2453+
/ t:( datatype_real ) !name_char { return [t, 'real']; }
2454+
/ t:( datatype_numeric ) !name_char { return [t, 'numeric']; }
2455+
/ t:( datatype_integer ) !name_char { return [t, 'integer']; }
2456+
/ t:( datatype_none ) !name_char { return [t, 'none']; }
24572457

24582458
datatype_text "TEXT Datatype Name"
24592459
= t:( ( ( "N"i )? ( "VAR"i )? "CHAR"i )

0 commit comments

Comments
 (0)