@@ -101,13 +101,14 @@ module.exports = grammar({
101101 [ $ . _inline_type , $ . function_type_parameters ] ,
102102 [ $ . primary_expression , $ . parameter , $ . _pattern ] ,
103103 [ $ . parameter , $ . _pattern ] ,
104- [ $ . parameter , $ . _parenthesized_pattern ] ,
105- [ $ . _switch_value_pattern , $ . _parenthesized_pattern ] ,
104+ [ $ . parameter , $ . parenthesized_pattern ] ,
106105 [ $ . variant_declaration ] ,
107106 [ $ . unit , $ . _function_type_parameter_list ] ,
108107 [ $ . functor_parameter , $ . module_primary_expression , $ . module_identifier_path ] ,
109108 [ $ . _reserved_identifier , $ . function ] ,
110- [ $ . polyvar_type ]
109+ [ $ . polyvar_type ] ,
110+ [ $ . _let_binding , $ . or_pattern ] ,
111+ [ $ . exception_pattern , $ . or_pattern ]
111112 ] ,
112113
113114 rules : {
@@ -693,45 +694,17 @@ module.exports = grammar({
693694
694695 switch_match : $ => prec . dynamic ( - 1 , seq (
695696 '|' ,
696- $ . _switch_pattern ,
697+ field ( 'pattern' , $ . _pattern ) ,
698+ optional ( $ . guard ) ,
697699 '=>' ,
698- $ . _one_or_more_statements ,
700+ field ( 'body' , alias ( $ . _one_or_more_statements , $ . sequence_expression ) ) ,
699701 ) ) ,
700702
701- _switch_pattern : $ => barSep1 ( choice (
702- alias ( $ . _switch_exception_pattern , $ . exception ) ,
703- $ . _parenthesized_switch_pattern ,
704- $ . _switch_value_pattern ,
705- $ . _switch_range_pattern ,
706- ) ) ,
707-
708- _switch_exception_pattern : $ => seq (
709- 'exception' ,
710- $ . _switch_value_pattern ,
711- ) ,
712-
713- _parenthesized_switch_pattern : $ => seq (
714- '(' ,
715- $ . _switch_pattern ,
716- ')' ,
717- ) ,
718-
719- _switch_value_pattern : $ => seq (
720- $ . _pattern ,
721- optional ( $ . switch_pattern_condition ) ,
722- ) ,
723-
724- switch_pattern_condition : $ => seq (
703+ guard : $ => seq (
725704 choice ( 'if' , 'when' ) ,
726705 $ . expression ,
727706 ) ,
728707
729- _switch_range_pattern : $ => seq (
730- $ . _literal_pattern ,
731- '..' ,
732- $ . _literal_pattern ,
733- ) ,
734-
735708 polyvar_type_pattern : $ => seq (
736709 '#' ,
737710 '...' ,
@@ -870,21 +843,34 @@ module.exports = grammar({
870843 // unfinished constructs are generally treated as literal expressions,
871844 // not patterns.
872845 _pattern : $ => prec . dynamic ( - 1 , seq (
873- barSep1 ( choice (
846+ choice (
874847 $ . value_identifier ,
875848 $ . _literal_pattern ,
876849 $ . _destructuring_pattern ,
877850 $ . polyvar_type_pattern ,
878851 $ . unit ,
879852 $ . module_pack ,
880853 $ . lazy_pattern ,
881- $ . _parenthesized_pattern ,
882- ) ) ,
854+ $ . parenthesized_pattern ,
855+ $ . or_pattern ,
856+ $ . range_pattern ,
857+ $ . exception_pattern
858+ ) ,
883859 optional ( $ . type_annotation ) ,
884860 optional ( $ . as_aliasing ) ,
885861 ) ) ,
886862
887- _parenthesized_pattern : $ => seq ( '(' , $ . _pattern , ')' ) ,
863+ parenthesized_pattern : $ => seq ( '(' , $ . _pattern , ')' ) ,
864+
865+ range_pattern : $ => seq (
866+ $ . _literal_pattern ,
867+ '..' ,
868+ $ . _literal_pattern ,
869+ ) ,
870+
871+ or_pattern : $ => prec . left ( seq ( $ . _pattern , '|' , $ . _pattern ) ) ,
872+
873+ exception_pattern : $ => seq ( 'exception' , $ . _pattern ) ,
888874
889875 _destructuring_pattern : $ => choice (
890876 $ . variant_pattern ,
@@ -919,7 +905,7 @@ module.exports = grammar({
919905 ) ,
920906
921907 _variant_pattern_parameter : $ => seq (
922- barSep1 ( $ . _pattern ) ,
908+ $ . _pattern ,
923909 optional ( $ . type_annotation ) ,
924910 ) ,
925911
@@ -937,7 +923,7 @@ module.exports = grammar({
937923 ) ,
938924 optional ( seq (
939925 ':' ,
940- barSep1 ( $ . _pattern ) ,
926+ $ . _pattern ,
941927 ) ) ,
942928 ) ) ,
943929 '}'
@@ -987,7 +973,7 @@ module.exports = grammar({
987973 $ . _literal_pattern ,
988974 $ . _destructuring_pattern ,
989975 $ . polyvar_type_pattern ,
990- $ . _parenthesized_pattern ,
976+ $ . parenthesized_pattern ,
991977 )
992978 ) ,
993979
@@ -1460,11 +1446,13 @@ module.exports = grammar({
14601446
14611447 template_string : $ => seq (
14621448 token ( seq (
1463- optional ( choice (
1464- 'j' ,
1465- 'js' ,
1466- 'json' ,
1467- ) ) ,
1449+ optional (
1450+ choice (
1451+ / [ a - z _ ] [ a - z A - Z 0 - 9 _ ' ] * / ,
1452+ // escape_sequence
1453+ seq ( '\\"' , / [ ^ " ] + / , '"' ) ,
1454+ )
1455+ ) ,
14681456 '`' ,
14691457 ) ) ,
14701458 $ . template_string_content ,
0 commit comments