@@ -265,6 +265,7 @@ module.exports = grammar({
265265 keyword_main : _ => make_keyword ( "main" ) ,
266266 keyword_storage : _ => make_keyword ( "storage" ) ,
267267 keyword_compression : _ => make_keyword ( "compression" ) ,
268+ keyword_while : _ => make_keyword ( "while" ) ,
268269
269270 keyword_trigger : _ => make_keyword ( 'trigger' ) ,
270271 keyword_function : _ => make_keyword ( "function" ) ,
@@ -696,9 +697,39 @@ module.exports = grammar({
696697 $ . _ddl_statement ,
697698 $ . _dml_write ,
698699 optional_parenthesis ( $ . _dml_read ) ,
700+ $ . while_statement ,
699701 ) ,
700702 ) ,
701703
704+ while_statement : $ => prec . left ( seq (
705+ $ . keyword_while ,
706+ optional_parenthesis ( $ . _expression ) ,
707+ choice (
708+ seq (
709+ $ . statement ,
710+ optional ( ';' ) ,
711+ ) ,
712+ seq (
713+ $ . keyword_begin ,
714+ repeat ( $ . statement ) ,
715+ $ . keyword_end ,
716+ ) ,
717+ ) ,
718+ ) ) ,
719+
720+ var_declarations : $ => seq ( $ . keyword_declare , repeat1 ( $ . var_declaration ) ) ,
721+ var_declaration : $ => seq (
722+ $ . identifier ,
723+ $ . _type ,
724+ optional (
725+ seq (
726+ choice ( $ . keyword_default , '=' ) ,
727+ $ . literal ,
728+ ) ,
729+ ) ,
730+ optional ( ',' ) ,
731+ ) ,
732+
702733 _ddl_statement : $ => choice (
703734 $ . _create_statement ,
704735 $ . _alter_statement ,
@@ -1244,6 +1275,22 @@ module.exports = grammar({
12441275 $ . _function_return ,
12451276 ) ,
12461277
1278+ _tsql_function_body_statement : $ => seq (
1279+ optional ( $ . keyword_as ) ,
1280+ $ . keyword_begin ,
1281+ optional ( $ . var_declarations ) ,
1282+ choice (
1283+ repeat ( $ . statement ) ,
1284+ repeat1 ( seq (
1285+ $ . keyword_begin ,
1286+ repeat ( $ . statement ) ,
1287+ $ . keyword_end ,
1288+ ) ) ,
1289+ ) ,
1290+ $ . _function_return ,
1291+ $ . keyword_end ,
1292+ ) ,
1293+
12471294 function_body : $ => choice (
12481295 seq (
12491296 $ . _function_return ,
@@ -1299,6 +1346,7 @@ module.exports = grammar({
12991346 optional ( ';' ) ,
13001347 alias ( $ . _dollar_quoted_string_end_tag , $ . dollar_quote ) ,
13011348 ) ,
1349+ $ . _tsql_function_body_statement ,
13021350 ) ,
13031351
13041352 function_language : $ => seq (
@@ -1453,7 +1501,7 @@ module.exports = grammar({
14531501 field ( 'value' , choice ( $ . identifier , alias ( $ . _single_quote_string , $ . literal ) ) ) ,
14541502 ) ,
14551503
1456- create_database : $ => seq (
1504+ create_database : $ => prec . left ( seq (
14571505 $ . keyword_create ,
14581506 $ . keyword_database ,
14591507 optional ( $ . _if_not_exists ) ,
@@ -1462,9 +1510,9 @@ module.exports = grammar({
14621510 repeat (
14631511 $ . _with_settings
14641512 ) ,
1465- ) ,
1513+ ) ) ,
14661514
1467- create_role : $ => seq (
1515+ create_role : $ => prec . left ( seq (
14681516 $ . keyword_create ,
14691517 choice (
14701518 $ . keyword_user ,
@@ -1479,7 +1527,7 @@ module.exports = grammar({
14791527 $ . _role_options ,
14801528 ) ,
14811529 ) ,
1482- ) ,
1530+ ) ) ,
14831531
14841532 _role_options : $ => choice (
14851533 field ( "option" , $ . identifier ) ,
@@ -1540,7 +1588,7 @@ module.exports = grammar({
15401588 ) ,
15411589 ) ,
15421590
1543- create_extension : $ => seq (
1591+ create_extension : $ => prec . left ( seq (
15441592 $ . keyword_create ,
15451593 $ . keyword_extension ,
15461594 optional ( $ . _if_not_exists ) ,
@@ -1549,7 +1597,7 @@ module.exports = grammar({
15491597 optional ( seq ( $ . keyword_schema , $ . identifier ) ) ,
15501598 optional ( seq ( $ . keyword_version , choice ( $ . identifier , alias ( $ . _literal_string , $ . literal ) ) ) ) ,
15511599 optional ( $ . keyword_cascade ) ,
1552- ) ,
1600+ ) ) ,
15531601
15541602 create_trigger : $ => seq (
15551603 $ . keyword_create ,
@@ -1613,7 +1661,7 @@ module.exports = grammar({
16131661 $ . keyword_truncate ,
16141662 ) ,
16151663
1616- create_type : $ => seq (
1664+ create_type : $ => prec . left ( seq (
16171665 $ . keyword_create ,
16181666 $ . keyword_type ,
16191667 $ . object_reference ,
@@ -1644,7 +1692,7 @@ module.exports = grammar({
16441692 ) ,
16451693 ) ,
16461694 ) ,
1647- ) ,
1695+ ) ) ,
16481696
16491697 enum_elements : $ => seq (
16501698 paren_list ( field ( "enum_element" , alias ( $ . _literal_string , $ . literal ) ) ) ,
@@ -1918,7 +1966,7 @@ module.exports = grammar({
19181966 ) ,
19191967 ) ,
19201968
1921- alter_role : $ => seq (
1969+ alter_role : $ => prec . left ( seq (
19221970 $ . keyword_alter ,
19231971 choice (
19241972 $ . keyword_role ,
@@ -1945,7 +1993,7 @@ module.exports = grammar({
19451993 ) ,
19461994 )
19471995 ) ,
1948- ) ,
1996+ ) ) ,
19491997
19501998 set_configuration : $ => seq (
19511999 field ( "option" , $ . identifier ) ,
@@ -2125,14 +2173,14 @@ module.exports = grammar({
21252173 optional ( $ . _drop_behavior )
21262174 ) ,
21272175
2128- drop_database : $ => seq (
2176+ drop_database : $ => prec . left ( seq (
21292177 $ . keyword_drop ,
21302178 $ . keyword_database ,
21312179 optional ( $ . _if_exists ) ,
21322180 $ . identifier ,
21332181 optional ( $ . keyword_with ) ,
21342182 optional ( $ . keyword_force ) ,
2135- ) ,
2183+ ) ) ,
21362184
21372185 drop_role : $ => seq (
21382186 $ . keyword_drop ,
@@ -2420,7 +2468,7 @@ module.exports = grammar({
24202468 repeat1 ( $ . when_clause )
24212469 ) ,
24222470
2423- when_clause : $ => seq (
2471+ when_clause : $ => prec . left ( seq (
24242472 $ . keyword_when ,
24252473 optional ( $ . keyword_not ) ,
24262474 $ . keyword_matched ,
@@ -2443,7 +2491,7 @@ module.exports = grammar({
24432491 ) ,
24442492 optional ( $ . where )
24452493 )
2446- ) ,
2494+ ) ) ,
24472495
24482496 _optimize_statement : $ => choice (
24492497 $ . _compute_stats ,
@@ -2452,7 +2500,7 @@ module.exports = grammar({
24522500 ) ,
24532501
24542502 // Compute stats for Impala and Hive
2455- _compute_stats : $ => choice (
2503+ _compute_stats : $ => prec . left ( choice (
24562504 // Hive
24572505 seq (
24582506 $ . keyword_analyze ,
@@ -2490,7 +2538,7 @@ module.exports = grammar({
24902538 )
24912539 )
24922540 ) ,
2493- ) ,
2541+ ) ) ,
24942542
24952543 _optimize_table : $ => choice (
24962544 // Athena/Iceberg
@@ -2520,14 +2568,14 @@ module.exports = grammar({
25202568 ) ,
25212569 ) ,
25222570
2523- _vacuum_table : $ => seq (
2571+ _vacuum_table : $ => prec . left ( seq (
25242572 $ . keyword_vacuum ,
25252573 optional ( $ . _vacuum_option ) ,
25262574 $ . object_reference ,
25272575 optional (
25282576 paren_list ( $ . field )
25292577 ) ,
2530- ) ,
2578+ ) ) ,
25312579
25322580 _vacuum_option : $ => choice (
25332581 seq ( $ . keyword_full , optional ( choice ( $ . keyword_true , $ . keyword_false ) ) ) ,
@@ -2711,11 +2759,11 @@ module.exports = grammar({
27112759 ')' ,
27122760 ) ,
27132761
2714- column_definition : $ => seq (
2762+ column_definition : $ => prec . left ( seq (
27152763 field ( 'name' , $ . _column ) ,
27162764 field ( 'type' , $ . _type ) ,
27172765 repeat ( $ . _column_constraint ) ,
2718- ) ,
2766+ ) ) ,
27192767
27202768 _column_comment : $ => seq (
27212769 $ . keyword_comment ,
0 commit comments