Skip to content

Commit fe77f68

Browse files
authored
Merge pull request #339 from iamchanii/main
feat: add support for backtick-quoted identifiers
2 parents ead7111 + 7b3f66e commit fe77f68

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

grammar.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3660,6 +3660,7 @@ module.exports = grammar({
36603660
),
36613661
),
36623662
_double_quote_string: _ => /"[^"]*"/,
3663+
_backtick_quoted_string: _ => /`[^`]*`/,
36633664
// The norm specify that between two consecutive string must be a return,
36643665
// but this is good enough.
36653666
_single_quote_string: _ => seq(/([uU]&|[nN])?'([^']|'')*'/, repeat(/'([^']|'')*'/)),
@@ -3694,6 +3695,7 @@ module.exports = grammar({
36943695
identifier: $ => choice(
36953696
$._identifier,
36963697
$._double_quote_string,
3698+
$._backtick_quoted_string,
36973699
$._tsql_parameter,
36983700
seq("`", $._identifier, "`"),
36993701
),

test/corpus/select.txt

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3129,3 +3129,87 @@ SELECT col1, col2, col3 into alpha, beta, gamma FROM my_table;
31293129
(relation
31303130
(object_reference
31313131
name: (identifier))))))
3132+
3133+
================================================================================
3134+
Select from table with bare identifier
3135+
================================================================================
3136+
3137+
SELECT * FROM table_name;
3138+
3139+
--------------------------------------------------------------------------------
3140+
3141+
(program
3142+
(statement
3143+
(select
3144+
(keyword_select)
3145+
(select_expression
3146+
(term
3147+
value: (all_fields))))
3148+
(from
3149+
(keyword_from)
3150+
(relation
3151+
(object_reference
3152+
name: (identifier))))))
3153+
3154+
================================================================================
3155+
Select from table with backtick-quoted identifier
3156+
================================================================================
3157+
3158+
SELECT * FROM `table_name`;
3159+
3160+
--------------------------------------------------------------------------------
3161+
3162+
(program
3163+
(statement
3164+
(select
3165+
(keyword_select)
3166+
(select_expression
3167+
(term
3168+
value: (all_fields))))
3169+
(from
3170+
(keyword_from)
3171+
(relation
3172+
(object_reference
3173+
name: (identifier))))))
3174+
3175+
================================================================================
3176+
Select from table with double-quoted identifier
3177+
================================================================================
3178+
3179+
SELECT * FROM "table_name";
3180+
3181+
--------------------------------------------------------------------------------
3182+
3183+
(program
3184+
(statement
3185+
(select
3186+
(keyword_select)
3187+
(select_expression
3188+
(term
3189+
value: (all_fields))))
3190+
(from
3191+
(keyword_from)
3192+
(relation
3193+
(object_reference
3194+
name: (identifier))))))
3195+
3196+
================================================================================
3197+
Select from table with identifiers containing hyphens, dots, or other special characters within backticks
3198+
================================================================================
3199+
3200+
SELECT * FROM `complex-database.schema_name.table_name`;
3201+
3202+
--------------------------------------------------------------------------------
3203+
3204+
(program
3205+
(statement
3206+
(select
3207+
(keyword_select)
3208+
(select_expression
3209+
(term
3210+
value: (all_fields))))
3211+
(from
3212+
(keyword_from)
3213+
(relation
3214+
(object_reference
3215+
name: (identifier))))))

0 commit comments

Comments
 (0)