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

Commit 6ea3be4

Browse files
committed
updated rules to allow for nested parenthesis and multiple binary expressions and concatenation operators within parenthesis. refs #2
1 parent 203f809 commit 6ea3be4

File tree

3 files changed

+50
-40
lines changed

3 files changed

+50
-40
lines changed

TODO.md

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,51 @@
55
- [ ] Missing specs
66

77
- [ ] Expression grouping issues
8-
``` sql
9-
`anger` != null AND NOT `happiness`
10-
```
8+
- [x] Grouping with unary and binary expressions
119

12-
``` sql
13-
`happiness` NOT NULL AND `anger` > 0
14-
```
10+
``` sql
11+
`anger` != null AND NOT `happiness`
12+
```
1513

16-
``` sql
17-
`happiness` IS NOT NULL AND `anger` > 0
18-
```
14+
``` sql
15+
`happiness` NOT NULL AND `anger` > 0
16+
```
1917

20-
``` sql
21-
`happiness` ISNULL AND `anger` >
22-
```
18+
``` sql
19+
`happiness` IS NOT NULL AND `anger` > 0
20+
```
2321

24-
``` sql
25-
`anger` > 0 AND `happiness` IS NOT NULL
26-
```
22+
``` sql
23+
`happiness` ISNULL AND `anger` >
24+
```
2725

28-
``` sql
29-
NOT `happiness` AND `anger` > 0
30-
```
26+
``` sql
27+
`anger` > 0 AND `happiness` IS NOT NULL
28+
```
29+
30+
``` sql
31+
NOT `happiness` AND `anger` > 0
32+
```
33+
34+
``` sql
35+
NOT `happiness` OR ~`ANGER` AND `anger` IS NOT 0
36+
```
37+
38+
- [ ] Grouping with parenthesis
39+
40+
``` sql
41+
SELECT *
42+
FROM hats
43+
WHERE
44+
(1 != 2 OR 3 != 4) AND ( 3 == 3 )
45+
```
46+
47+
``` sql
48+
SELECT *
49+
FROM hats
50+
WHERE
51+
hat OR (shirt AND (shoes OR wig) AND pants)
52+
```
3153

3254
- [ ] Remove `modifier` key from all parts of AST and standardize as `conditions`
3355

lib/sql-parser.js

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

src/sql-grammar.pegjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ expression_concat
5656
}
5757

5858
expression_wrapped
59-
= sym_popen o n:( expression_unary / expression_node / expression_value ) o sym_pclose
59+
= sym_popen n:( expression ) o sym_pclose
6060
{ return n; }
6161

6262
expression_value
@@ -77,7 +77,7 @@ expression_unary
7777
'format': 'unary',
7878
'variant': 'operation',
7979
'expression': e,
80-
'operator': o
80+
'operator': _.key(o)
8181
};
8282
}
8383

0 commit comments

Comments
 (0)