Skip to content

Commit

Permalink
Add support for ADT and general patterns
Browse files Browse the repository at this point in the history
Since (future) Nickel 1.5, Nickel supports ADTs (enum variants), which
extended the language of destructuring patterns. Moreover, match
expressions have been also extended to handle full patterns instead of
just enum tags.

This commit updates the tree-sitter grammar to reflect those changes,
and in particular adds support for:

- enum variants
- enum patterns
- pattern matching
  • Loading branch information
yannham committed Mar 6, 2024
1 parent 33a64ec commit bfef9fe
Show file tree
Hide file tree
Showing 16 changed files with 19,657 additions and 16,739 deletions.
2 changes: 1 addition & 1 deletion corpus/basic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ fun a => b
(term
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down
16 changes: 8 additions & 8 deletions corpus/examples/array.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ my_array_lib.fold (fun x acc => x * acc) l 1
(term
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down Expand Up @@ -240,11 +240,11 @@ my_array_lib.fold (fun x acc => x * acc) l 1
(term
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(pattern
(pattern_fun
(ident))
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down Expand Up @@ -364,7 +364,7 @@ my_array_lib.fold (fun x acc => x * acc) l 1
(atom
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down Expand Up @@ -441,9 +441,9 @@ my_array_lib.fold (fun x acc => x * acc) l 1
(atom
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down
2 changes: 1 addition & 1 deletion corpus/examples/fibonacci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fibonacci 10
(term
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down
20 changes: 10 additions & 10 deletions corpus/examples/gcc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ let Contract = {
(term
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down Expand Up @@ -220,7 +220,7 @@ let Contract = {
(atom
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down Expand Up @@ -373,7 +373,7 @@ let Contract = {
(atom
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down Expand Up @@ -519,9 +519,9 @@ let Contract = {
(term
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down Expand Up @@ -619,9 +619,9 @@ let Contract = {
(term
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down Expand Up @@ -724,9 +724,9 @@ let Contract = {
(term
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down
10 changes: 5 additions & 5 deletions corpus/examples/polymorphism.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ let id : forall a. a -> a = fun x => x in
(term
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down Expand Up @@ -101,9 +101,9 @@ let id : forall a. a -> a = fun x => x in
(term
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down Expand Up @@ -142,7 +142,7 @@ let id : forall a. a -> a = fun x => x in
(term
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down
2 changes: 1 addition & 1 deletion corpus/examples/record-contract.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ let metadata_ = {
(atom
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down
16 changes: 8 additions & 8 deletions corpus/examples/simple-contracts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ not true
(term
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(pattern
(pattern_fun
(ident))
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down Expand Up @@ -140,7 +140,7 @@ not true
(term
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down Expand Up @@ -197,9 +197,9 @@ let DivBy3 = fun label value =>
(term
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down Expand Up @@ -269,9 +269,9 @@ let DivBy3 = fun label value =>
(term
(uni_term
(fun_expr
(pattern
(pattern_fun
(ident))
(pattern
(pattern_fun
(ident))
(term
(uni_term
Expand Down
35 changes: 21 additions & 14 deletions corpus/match.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ x |> match {
(applicative
(match_expr
(match_case
(enum_tag
(raw_enum_tag))
(pattern
(enum_tag
(raw_enum_tag)))
(term
(uni_term
(infix_expr
Expand All @@ -47,8 +48,9 @@ x |> match {
(atom
(num_literal))))))))
(match_case
(enum_tag
(raw_enum_tag))
(pattern
(enum_tag
(raw_enum_tag)))
(term
(uni_term
(infix_expr
Expand Down Expand Up @@ -76,8 +78,9 @@ match {
(applicative
(match_expr
(match_case
(enum_tag
(raw_enum_tag))
(pattern
(enum_tag
(raw_enum_tag)))
(term
(uni_term
(infix_expr
Expand All @@ -86,8 +89,9 @@ match {
(atom
(bool))))))))
(match_case
(enum_tag
(raw_enum_tag))
(pattern
(enum_tag
(raw_enum_tag)))
(term
(uni_term
(infix_expr
Expand All @@ -96,8 +100,9 @@ match {
(atom
(bool))))))))
(match_case
(enum_tag
(raw_enum_tag))
(pattern
(enum_tag
(raw_enum_tag)))
(term
(uni_term
(infix_expr
Expand Down Expand Up @@ -135,8 +140,9 @@ f 'a
(applicative
(match_expr
(match_case
(enum_tag
(raw_enum_tag))
(pattern
(enum_tag
(raw_enum_tag)))
(term
(uni_term
(infix_expr
Expand All @@ -145,8 +151,9 @@ f 'a
(atom
(num_literal))))))))
(match_case
(enum_tag
(raw_enum_tag))
(pattern
(enum_tag
(raw_enum_tag)))
(term
(uni_term
(infix_expr
Expand Down
Loading

0 comments on commit bfef9fe

Please sign in to comment.