Fixed pattern matching of lists.

New syntax: nil -> ... | list [...] -> ... | list .... end -> ...
This commit is contained in:
Christian Rinderknecht 2019-03-27 18:17:23 +01:00
parent baffeeb6eb
commit 01128b6518
No known key found for this signature in database
GPG Key ID: 9446816CFD267040
3 changed files with 18 additions and 19 deletions

View File

@ -666,7 +666,8 @@ and pattern =
| PTuple of (pattern, comma) nsepseq par reg
and list_pattern =
Sugar of (pattern, semi) sepseq brackets reg
Sugar of pattern injection reg
| PNil of kwd_nil
| Raw of (pattern * cons * pattern) par reg
(* Projecting regions *)
@ -792,6 +793,7 @@ let pattern_to_region = function
| PNone region
| PSome {region; _}
| PList Sugar {region; _}
| PList PNil region
| PList Raw {region; _}
| PTuple {region; _} -> region
@ -1482,15 +1484,10 @@ and print_patterns {value; _} =
print_token rpar ")"
and print_list_pattern = function
Sugar sugar -> print_sugar sugar
Sugar sugar -> print_injection "list" print_pattern sugar
| PNil kwd_nil -> print_token kwd_nil "nil"
| Raw raw -> print_raw raw
and print_sugar {value; _} =
let {lbracket; inside; rbracket} = value in
print_token lbracket "[";
print_sepseq "," print_pattern inside;
print_token rbracket "]"
and print_raw {value; _} =
let {lpar; inside; rpar} = value in
let head, cons, tail = inside in

View File

@ -650,7 +650,8 @@ and pattern =
| PTuple of (pattern, comma) nsepseq par reg
and list_pattern =
Sugar of (pattern, semi) sepseq brackets reg
Sugar of pattern injection reg
| PNil of kwd_nil
| Raw of (pattern * cons * pattern) par reg
(* Projecting regions *)

View File

@ -518,7 +518,7 @@ map_remove:
in {region; value}}
set_patch:
Patch path With injection(Set) {
Patch path With injection(Set,expr) {
let region = cover $1 $4.region in
let value = {
kwd_patch = $1;
@ -537,8 +537,8 @@ map_patch:
map_inj = $4}
in {region; value}}
injection(Kind):
Kind series(expr,End) {
injection(Kind,element):
Kind series(element,End) {
let first, (others, terminator, closing) = $2 in
let region = cover $1 closing
and value = {
@ -557,7 +557,7 @@ injection(Kind):
closing = End $2}
in {region; value}
}
| Kind LBRACKET series(expr,RBRACKET) {
| Kind LBRACKET series(element,RBRACKET) {
let first, (others, terminator, closing) = $3 in
let region = cover $1 closing
and value = {
@ -942,7 +942,7 @@ core_expr:
EConstr (SomeApp {region; value = $1,$2})}
set_expr:
injection(Set) { SetInj $1 }
injection(Set,expr) { SetInj $1 }
map_expr:
map_lookup { MapLookUp $1 }
@ -1010,7 +1010,7 @@ arguments:
tuple_inj { $1 }
list_expr:
injection(List) { List $1 }
injection(List,expr) { List $1 }
| nil { Nil $1 }
nil:
@ -1054,7 +1054,8 @@ core_pattern:
in PSome {region; value = $1,$2}}
list_patt:
brackets(sepseq(core_pattern,SEMI)) { Sugar $1 }
injection(List,core_pattern) { Sugar $1 }
| Nil { PNil $1 }
| par(cons_pattern) { Raw $1 }
cons_pattern: