Skip to content

Commit

Permalink
Support more comparison predicates
Browse files Browse the repository at this point in the history
1. BETWEEN...AND expression;
2. ISNULL and NOTNULL;
3. IS UNKNOWN and IS NOT UNKNOWN;
  • Loading branch information
pplam committed Jun 30, 2022
1 parent a3e100f commit 42f750d
Show file tree
Hide file tree
Showing 5 changed files with 1,330,835 additions and 1,180,117 deletions.
24 changes: 23 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1500,17 +1500,34 @@ module.exports = grammar({
_parenthesized_expression: $ =>
prec.left(PREC.unary, seq("(", $._expression, ")")),
with_ordinality: $ => kw("WITH ORDINALITY"),

is_expression: $ =>
prec.left(
PREC.comparative,
seq(
$._expression,
kw("IS"),
optional(kw("NOT")),
choice($.NULL, $.TRUE, $.FALSE, $.distinct_from),
choice($.NULL, $.TRUE, $.FALSE, $.UNKNOWN, $.distinct_from),
),
),
distinct_from: $ => prec.left(seq(kw("DISTINCT FROM"), $._expression)),
isnull_expression: $ => seq($._expression, kw("ISNULL")),
notnull_expression: $ => seq($._expression, kw("NOTNULL")),
between_and_expression: $ =>
prec.left(
PREC.comparative,
seq(
$._expression,
optional(kw("NOT")),
kw("BETWEEN"),
optional(kw("SYMMETRIC")),
$._expression,
kw("AND"),
$._expression,
),
),

boolean_expression: $ =>
choice(
prec.left(PREC.unary, seq(kw("NOT"), $._expression)),
Expand All @@ -1526,6 +1543,7 @@ module.exports = grammar({
NULL: $ => kw("NULL"),
TRUE: $ => kw("TRUE"),
FALSE: $ => kw("FALSE"),
UNKNOWN: $ => kw("UNKNOWN"),

number: $ => {
const digits = repeat1(/[0-9]+_?/);
Expand Down Expand Up @@ -1669,11 +1687,15 @@ module.exports = grammar({
$.TRUE,
$.FALSE,
$.NULL,
$.UNKNOWN,
$.asterisk_expression,
$._identifier,
$.number,
$.in_expression,
$.is_expression,
$.isnull_expression,
$.notnull_expression,
$.between_and_expression,
$.boolean_expression,
$._parenthesized_expression,
$.type_cast,
Expand Down
138 changes: 138 additions & 0 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -14393,6 +14393,10 @@
"type": "SYMBOL",
"name": "FALSE"
},
{
"type": "SYMBOL",
"name": "UNKNOWN"
},
{
"type": "SYMBOL",
"name": "distinct_from"
Expand Down Expand Up @@ -14433,6 +14437,115 @@
]
}
},
"isnull_expression": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[iI][sS][nN][uU][lL][lL]"
},
"named": false,
"value": "ISNULL"
}
]
},
"notnull_expression": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[nN][oO][tT][nN][uU][lL][lL]"
},
"named": false,
"value": "NOTNULL"
}
]
},
"between_and_expression": {
"type": "PREC_LEFT",
"value": 3,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[nN][oO][tT]"
},
"named": false,
"value": "NOT"
},
{
"type": "BLANK"
}
]
},
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[bB][eE][tT][wW][eE][eE][nN]"
},
"named": false,
"value": "BETWEEN"
},
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[sS][yY][mM][mM][eE][tT][rR][iI][cC]"
},
"named": false,
"value": "SYMMETRIC"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[aA][nN][dD]"
},
"named": false,
"value": "AND"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
},
"boolean_expression": {
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -14609,6 +14722,15 @@
"named": false,
"value": "FALSE"
},
"UNKNOWN": {
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[uU][nN][kK][nN][oO][wW][nN]"
},
"named": false,
"value": "UNKNOWN"
},
"number": {
"type": "TOKEN",
"content": {
Expand Down Expand Up @@ -15823,6 +15945,10 @@
"type": "SYMBOL",
"name": "NULL"
},
{
"type": "SYMBOL",
"name": "UNKNOWN"
},
{
"type": "SYMBOL",
"name": "asterisk_expression"
Expand All @@ -15843,6 +15969,18 @@
"type": "SYMBOL",
"name": "is_expression"
},
{
"type": "SYMBOL",
"name": "isnull_expression"
},
{
"type": "SYMBOL",
"name": "notnull_expression"
},
{
"type": "SYMBOL",
"name": "between_and_expression"
},
{
"type": "SYMBOL",
"name": "boolean_expression"
Expand Down
Loading

0 comments on commit 42f750d

Please sign in to comment.