Compare commits
2 commits
main
...
improve-pr
Author | SHA1 | Date | |
---|---|---|---|
b121cd1fc1 | |||
dc314830d2 |
4 changed files with 57153 additions and 67358 deletions
143
grammar.js
143
grammar.js
|
@ -27,6 +27,14 @@ module.exports = grammar({
|
||||||
// NOTE(chrde): https://github.com/tree-sitter/tree-sitter-javascript/blob/1ddbf1588c353edab37791cdcc9f17e56fb4ea73/grammar.js#L9
|
// NOTE(chrde): https://github.com/tree-sitter/tree-sitter-javascript/blob/1ddbf1588c353edab37791cdcc9f17e56fb4ea73/grammar.js#L9
|
||||||
extras: ($) => [$.comment, /[\s\uFEFF\u2060\u200B\u00A0]/],
|
extras: ($) => [$.comment, /[\s\uFEFF\u2060\u200B\u00A0]/],
|
||||||
|
|
||||||
|
conflicts: ($) => [
|
||||||
|
[$.op_expression],
|
||||||
|
[$.select_statement],
|
||||||
|
[$.from_item],
|
||||||
|
[$.select_group_by, $._value_expression],
|
||||||
|
[$.time_expression, $.op_expression],
|
||||||
|
],
|
||||||
|
|
||||||
rules: {
|
rules: {
|
||||||
source_file: ($) =>
|
source_file: ($) =>
|
||||||
repeat(choice($.psql_statement, seq($._statement, ";"))),
|
repeat(choice($.psql_statement, seq($._statement, ";"))),
|
||||||
|
@ -160,7 +168,7 @@ module.exports = grammar({
|
||||||
|
|
||||||
conflict_target: ($) =>
|
conflict_target: ($) =>
|
||||||
choice(
|
choice(
|
||||||
seq(kw("on"), kw("constraint"), $.identifier),
|
seq(kw("on"), $._constraint, $.identifier),
|
||||||
seq("(", commaSep($._value_expression), ")")
|
seq("(", commaSep($._value_expression), ")")
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -298,7 +306,7 @@ module.exports = grammar({
|
||||||
),
|
),
|
||||||
seq(
|
seq(
|
||||||
kw("drop"),
|
kw("drop"),
|
||||||
kw("constraint"),
|
$._constraint,
|
||||||
optional($.if_exists),
|
optional($.if_exists),
|
||||||
$.identifier,
|
$.identifier,
|
||||||
optional($.alter_table_fk_ref_action)
|
optional($.alter_table_fk_ref_action)
|
||||||
|
@ -330,7 +338,7 @@ module.exports = grammar({
|
||||||
|
|
||||||
table_constraint: ($) =>
|
table_constraint: ($) =>
|
||||||
seq(
|
seq(
|
||||||
optional(seq(kw("constraint"), $.identifier)),
|
optional(seq($._constraint, $.identifier)),
|
||||||
$.table_constraint_ty,
|
$.table_constraint_ty,
|
||||||
optional($.constraint_when)
|
optional($.constraint_when)
|
||||||
),
|
),
|
||||||
|
@ -379,19 +387,17 @@ module.exports = grammar({
|
||||||
|
|
||||||
alter_column_type: ($) =>
|
alter_column_type: ($) =>
|
||||||
seq($._type, optional(seq(kw("using"), $._value_expression))),
|
seq($._type, optional(seq(kw("using"), $._value_expression))),
|
||||||
|
|
||||||
alter_table_fk_ref_action: ($) => choice(kw("restrict"), kw("cascade")),
|
alter_table_fk_ref_action: ($) => choice(kw("restrict"), kw("cascade")),
|
||||||
|
|
||||||
table_column_item: ($) =>
|
table_column_item: ($) =>
|
||||||
seq($.identifier, $._type, repeat($.column_constraint)),
|
seq($.identifier, $._type, repeat($.column_constraint)),
|
||||||
|
|
||||||
column_constraint: ($) =>
|
column_constraint: ($) =>
|
||||||
choice(
|
seq(
|
||||||
seq(
|
optional(seq($._constraint, $.identifier)),
|
||||||
kw("constraint"),
|
$.column_constraint_ty,
|
||||||
$.identifier,
|
optional($.constraint_when)
|
||||||
$.column_constraint_ty,
|
|
||||||
optional($.constraint_when)
|
|
||||||
),
|
|
||||||
seq($.column_constraint_ty, optional($.constraint_when))
|
|
||||||
),
|
),
|
||||||
|
|
||||||
column_constraint_ty: ($) =>
|
column_constraint_ty: ($) =>
|
||||||
|
@ -413,9 +419,12 @@ module.exports = grammar({
|
||||||
kw("to"),
|
kw("to"),
|
||||||
$.identifier
|
$.identifier
|
||||||
),
|
),
|
||||||
|
|
||||||
alter_table_rename_constraint: ($) =>
|
alter_table_rename_constraint: ($) =>
|
||||||
seq(kw("rename"), kw("constraint"), $.identifier, kw("to"), $.identifier),
|
seq(kw("rename"), $._constraint, $.identifier, kw("to"), $.identifier),
|
||||||
|
|
||||||
alter_table_rename_table: ($) => seq(kw("rename"), kw("to"), $.identifier),
|
alter_table_rename_table: ($) => seq(kw("rename"), kw("to"), $.identifier),
|
||||||
|
|
||||||
alter_table_change_schema: ($) =>
|
alter_table_change_schema: ($) =>
|
||||||
seq(kw("set"), kw("schema"), $.identifier),
|
seq(kw("set"), kw("schema"), $.identifier),
|
||||||
|
|
||||||
|
@ -517,7 +526,7 @@ module.exports = grammar({
|
||||||
create_trigger_statement: ($) =>
|
create_trigger_statement: ($) =>
|
||||||
seq(
|
seq(
|
||||||
kw("create"),
|
kw("create"),
|
||||||
optional(kw("constraint")),
|
optional($._constraint),
|
||||||
kw("trigger"),
|
kw("trigger"),
|
||||||
$.identifier,
|
$.identifier,
|
||||||
$.trigger_when,
|
$.trigger_when,
|
||||||
|
@ -663,20 +672,18 @@ module.exports = grammar({
|
||||||
do_block: ($) => seq(kw("do"), $.block),
|
do_block: ($) => seq(kw("do"), $.block),
|
||||||
|
|
||||||
select_statement: ($) =>
|
select_statement: ($) =>
|
||||||
prec.left(
|
seq(
|
||||||
seq(
|
optional($.with_query),
|
||||||
optional($.with_query),
|
kw("select"),
|
||||||
kw("select"),
|
commaSep($.select_item),
|
||||||
commaSep($.select_item),
|
optional($.into),
|
||||||
optional($.into),
|
optional($.select_from),
|
||||||
optional($.select_from),
|
optional($.select_where),
|
||||||
optional($.select_where),
|
optional($.select_group_by),
|
||||||
optional($.select_group_by),
|
optional($.select_having),
|
||||||
optional($.select_having),
|
optional($.select_order_by),
|
||||||
optional($.select_order_by),
|
optional($._select_limit_offset),
|
||||||
optional($._select_limit_offset),
|
optional($.into)
|
||||||
optional($.into)
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
|
|
||||||
with_query: ($) => seq(kw("with"), commaSep1($.with_query_item)),
|
with_query: ($) => seq(kw("with"), commaSep1($.with_query_item)),
|
||||||
|
@ -717,15 +724,12 @@ module.exports = grammar({
|
||||||
|
|
||||||
// TODO(chrde): rollup, cube, grouping sets
|
// TODO(chrde): rollup, cube, grouping sets
|
||||||
select_group_by: ($) =>
|
select_group_by: ($) =>
|
||||||
prec(
|
seq(
|
||||||
1,
|
kw("group"),
|
||||||
seq(
|
kw("by"),
|
||||||
kw("group"),
|
choice(
|
||||||
kw("by"),
|
seq("(", commaSep1($._value_expression), ")"),
|
||||||
choice(
|
commaSep1($._value_expression)
|
||||||
seq("(", commaSep1($._value_expression), ")"),
|
|
||||||
commaSep1($._value_expression)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -745,12 +749,10 @@ module.exports = grammar({
|
||||||
select_from: ($) => seq(kw("from"), commaSep1($.from_item)),
|
select_from: ($) => seq(kw("from"), commaSep1($.from_item)),
|
||||||
|
|
||||||
from_item: ($) =>
|
from_item: ($) =>
|
||||||
prec.left(
|
seq(
|
||||||
seq(
|
// TODO(chrde): https://www.postgresql.org/docs/current/sql-select.html
|
||||||
// TODO(chrde): https://www.postgresql.org/docs/current/sql-select.html
|
choice($.from_select, $.from_table, $.from_function),
|
||||||
choice($.from_select, $.from_table, $.from_function),
|
repeat($.join_item)
|
||||||
repeat($.join_item)
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
|
|
||||||
from_select: ($) =>
|
from_select: ($) =>
|
||||||
|
@ -772,12 +774,10 @@ module.exports = grammar({
|
||||||
),
|
),
|
||||||
|
|
||||||
join_item: ($) =>
|
join_item: ($) =>
|
||||||
prec.left(
|
choice(
|
||||||
choice(
|
seq(kw("natural"), $.join_type, $.from_item),
|
||||||
seq(kw("natural"), $.join_type, $.from_item),
|
seq($.join_type, $.from_item, $.join_condition),
|
||||||
seq($.join_type, $.from_item, $.join_condition),
|
seq(kw("cross"), kw("join"), $.from_item)
|
||||||
seq(kw("cross"), kw("join"), $.from_item)
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
|
|
||||||
join_condition: ($) =>
|
join_condition: ($) =>
|
||||||
|
@ -912,8 +912,7 @@ module.exports = grammar({
|
||||||
|
|
||||||
type_length: ($) => seq("(", $.number, ")"),
|
type_length: ($) => seq("(", $.number, ")"),
|
||||||
|
|
||||||
string: ($) =>
|
string: ($) => seq("'", repeat(choice(/''/, /[^']/)), "'"),
|
||||||
seq("'", repeat(choice(prec(1, /''/), prec(2, /[^']/))), "'"),
|
|
||||||
|
|
||||||
// NOTE(chrde): taken from https://github.com/tree-sitter/tree-sitter-javascript/blob/1ddbf1588c353edab37791cdcc9f17e56fb4ea73/grammar.js#L899
|
// NOTE(chrde): taken from https://github.com/tree-sitter/tree-sitter-javascript/blob/1ddbf1588c353edab37791cdcc9f17e56fb4ea73/grammar.js#L899
|
||||||
comment: ($) =>
|
comment: ($) =>
|
||||||
|
@ -1002,37 +1001,20 @@ module.exports = grammar({
|
||||||
|
|
||||||
op_expression: ($) =>
|
op_expression: ($) =>
|
||||||
choice(
|
choice(
|
||||||
prec.left(12, seq($._value_expression, $.cast, $._type)),
|
seq($._value_expression, $.cast, $._type),
|
||||||
// array access
|
// array access
|
||||||
prec.right(10, seq(choice($.minus, $.plus), $._value_expression)),
|
seq(choice($.minus, $.plus), $._value_expression),
|
||||||
// ^
|
// ^
|
||||||
prec.left(
|
seq($._value_expression, choice("*", "/", "%"), $._value_expression),
|
||||||
8,
|
seq($._value_expression, choice("-", "+"), $._value_expression),
|
||||||
seq($._value_expression, choice("*", "/", "%"), $._value_expression)
|
seq($._value_expression, $.other_op, $._value_expression),
|
||||||
),
|
seq($._value_expression, $.contains_op, $._value_expression),
|
||||||
prec.left(
|
seq($._value_expression, $.comparison_op, $._value_expression),
|
||||||
7,
|
seq($._value_expression, $.comparison_kw, $._value_expression),
|
||||||
seq($._value_expression, choice("-", "+"), $._value_expression)
|
seq($._value_expression, $.comparison_null),
|
||||||
),
|
seq($.not, $._value_expression),
|
||||||
prec.left(6, seq($._value_expression, $.other_op, $._value_expression)),
|
|
||||||
prec.left(
|
seq($._value_expression, choice($.and, $.or), $._value_expression)
|
||||||
5,
|
|
||||||
seq($._value_expression, $.contains_op, $._value_expression)
|
|
||||||
),
|
|
||||||
prec.left(
|
|
||||||
4,
|
|
||||||
seq($._value_expression, $.comparison_op, $._value_expression)
|
|
||||||
),
|
|
||||||
prec.left(
|
|
||||||
3,
|
|
||||||
seq($._value_expression, $.comparison_kw, $._value_expression)
|
|
||||||
),
|
|
||||||
prec.left(3, seq($._value_expression, $.comparison_null)),
|
|
||||||
prec.right(2, seq($.not, $._value_expression)),
|
|
||||||
prec.left(
|
|
||||||
1,
|
|
||||||
seq($._value_expression, choice($.and, $.or), $._value_expression)
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
|
|
||||||
_list_of_identifiers: ($) => seq("(", commaSep($.identifier), ")"),
|
_list_of_identifiers: ($) => seq("(", commaSep($.identifier), ")"),
|
||||||
|
@ -1083,5 +1065,8 @@ module.exports = grammar({
|
||||||
_identifier: ($) => /[a-zA-Z0-9_]+(\.?[a-zA-Z0-9_]+)*/,
|
_identifier: ($) => /[a-zA-Z0-9_]+(\.?[a-zA-Z0-9_]+)*/,
|
||||||
// ^
|
// ^
|
||||||
// |- we dont want to match consecutive dots, e.g: 1..2 consists of 3 tokens
|
// |- we dont want to match consecutive dots, e.g: 1..2 consists of 3 tokens
|
||||||
|
|
||||||
|
//--------------------------
|
||||||
|
_constraint: ($) => kw("constraint"),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
1143
src/grammar.json
1143
src/grammar.json
File diff suppressed because it is too large
Load diff
123217
src/parser.c
123217
src/parser.c
File diff suppressed because it is too large
Load diff
|
@ -223,7 +223,13 @@ alter table foo add constraint u_bar unique(bar);
|
||||||
(table_constraint
|
(table_constraint
|
||||||
(identifier)
|
(identifier)
|
||||||
(table_constraint_ty
|
(table_constraint_ty
|
||||||
(identifier)))))))
|
(identifier)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
column drop constraint
|
column drop constraint
|
||||||
|
|
Loading…
Reference in a new issue