Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test:
# Generate the postgres grammar from PostgreSQL source
generate-postgres pg_dir=env("PG_SOURCE_DIR"):
node script/generate-grammar.js {{pg_dir}}
{{ts}} generate postgres/grammar.js
cd postgres && ../node_modules/.bin/tree-sitter generate

# Generate postgres language injection queries
generate-injections:
Expand Down
30 changes: 18 additions & 12 deletions postgres/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ module.exports = grammar({
seq($.kw_connection, $.kw_limit, $.SignedIconst),
seq($.kw_valid, $.kw_until, $.Sconst),
seq($.kw_user, $.role_list),
prec.left(11, prec.dynamic(11, $.identifier))
prec.left(11, prec.dynamic(11, $._ident))
),
CreateOptRoleElem: $ => choice(
$.AlterOptRoleElem,
Expand Down Expand Up @@ -311,7 +311,7 @@ module.exports = grammar({
),
zone_value: $ => choice(
$.Sconst,
prec.left(11, prec.dynamic(11, $.identifier)),
prec.left(11, prec.dynamic(11, $._ident)),
seq($.ConstInterval, $.Sconst, optional($.opt_interval)),
prec.left(20, prec.dynamic(20, seq($.ConstInterval, '(', $.Iconst, ')', $.Sconst))),
$.NumericOnly,
Expand Down Expand Up @@ -991,7 +991,7 @@ module.exports = grammar({
RowSecurityOptionalWithCheck: $ => prec.left(11, prec.dynamic(11, seq($.kw_with, $.kw_check, '(', $.a_expr, ')'))),
RowSecurityDefaultToRole: $ => seq($.kw_to, $.role_list),
RowSecurityOptionalToRole: $ => seq($.kw_to, $.role_list),
RowSecurityDefaultPermissive: $ => prec.left(11, prec.dynamic(11, seq($.kw_as, $.identifier))),
RowSecurityDefaultPermissive: $ => prec.left(11, prec.dynamic(11, seq($.kw_as, $._ident))),
RowSecurityDefaultForCmd: $ => seq($.kw_for, $.row_security_cmd),
row_security_cmd: $ => choice(
$.kw_all,
Expand Down Expand Up @@ -1134,7 +1134,7 @@ module.exports = grammar({
$.old_aggr_elem,
seq($.old_aggr_list, ',', $.old_aggr_elem)
),
old_aggr_elem: $ => prec.left(11, prec.dynamic(11, seq($.identifier, '=', $.def_arg))),
old_aggr_elem: $ => prec.left(11, prec.dynamic(11, seq($._ident, '=', $.def_arg))),
opt_enum_val_list: $ => $.enum_val_list,
enum_val_list: $ => choice(
$.Sconst,
Expand Down Expand Up @@ -1966,7 +1966,7 @@ module.exports = grammar({
seq($.createdb_opt_name, optional($.opt_equal), $.kw_default)
),
createdb_opt_name: $ => choice(
prec.left(11, prec.dynamic(11, $.identifier)),
prec.left(11, prec.dynamic(11, $._ident)),
seq($.kw_connection, $.kw_limit),
$.kw_encoding,
$.kw_location,
Expand Down Expand Up @@ -2505,7 +2505,7 @@ module.exports = grammar({
seq($.xmltable_column_option_list, $.xmltable_column_option_el)
),
xmltable_column_option_el: $ => choice(
prec.left(11, prec.dynamic(11, seq($.identifier, $.b_expr))),
prec.left(11, prec.dynamic(11, seq($._ident, $.b_expr))),
seq($.kw_default, $.b_expr),
prec.right(5, prec.dynamic(5, seq($.kw_not, $.kw_null))),
$.kw_null,
Expand Down Expand Up @@ -2997,7 +2997,7 @@ module.exports = grammar({
),
extract_list: $ => seq($.extract_arg, $.kw_from, $.a_expr),
extract_arg: $ => choice(
prec.left(11, prec.dynamic(11, $.identifier)),
prec.left(11, prec.dynamic(11, $._ident)),
$.kw_year,
$.kw_month,
$.kw_day,
Expand Down Expand Up @@ -3226,30 +3226,30 @@ module.exports = grammar({
prec.left(7, prec.dynamic(7, '='))
),
ColId: $ => choice(
prec.left(11, prec.dynamic(11, $.identifier)),
prec.left(11, prec.dynamic(11, $._ident)),
$.unreserved_keyword,
$.col_name_keyword
),
type_function_name: $ => choice(
prec.left(11, prec.dynamic(11, $.identifier)),
prec.left(11, prec.dynamic(11, $._ident)),
$.unreserved_keyword,
$.type_func_name_keyword
),
NonReservedWord: $ => choice(
prec.left(11, prec.dynamic(11, $.identifier)),
prec.left(11, prec.dynamic(11, $._ident)),
$.unreserved_keyword,
$.col_name_keyword,
$.type_func_name_keyword
),
ColLabel: $ => choice(
prec.left(11, prec.dynamic(11, $.identifier)),
prec.left(11, prec.dynamic(11, $._ident)),
$.unreserved_keyword,
$.col_name_keyword,
$.type_func_name_keyword,
$.reserved_keyword
),
BareColLabel: $ => choice(
prec.left(11, prec.dynamic(11, $.identifier)),
prec.left(11, prec.dynamic(11, $._ident)),
$.bare_label_keyword
),
bare_label_keyword: $ => choice(
Expand Down Expand Up @@ -4729,6 +4729,12 @@ module.exports = grammar({
// scanner would be needed to handle these correctly.
quoted_identifier: _ => token(/"([^"]|"")*"/),

// gram.y's IDENT terminal matches either identifier form (scan.l lexes
// quoted identifiers into IDENT). Hidden so the CST surfaces the
// (identifier) / (quoted_identifier) leaf directly. 'word' below must
// stay on the bare identifier token, so this cannot replace it there.
_ident: $ => choice($.identifier, $.quoted_identifier),

// Positional parameter: $1, $2, ...
param: _ => /\$[0-9]+/,

Expand Down
37 changes: 25 additions & 12 deletions postgres/src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions postgres/src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions postgres/src/parser.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading