Fixed pattern matching of lists.
New syntax: nil -> ... | list [...] -> ... | list .... end -> ...
This commit is contained in:
parent
baffeeb6eb
commit
01128b6518
@ -666,7 +666,8 @@ and pattern =
|
|||||||
| PTuple of (pattern, comma) nsepseq par reg
|
| PTuple of (pattern, comma) nsepseq par reg
|
||||||
|
|
||||||
and list_pattern =
|
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
|
| Raw of (pattern * cons * pattern) par reg
|
||||||
|
|
||||||
(* Projecting regions *)
|
(* Projecting regions *)
|
||||||
@ -792,6 +793,7 @@ let pattern_to_region = function
|
|||||||
| PNone region
|
| PNone region
|
||||||
| PSome {region; _}
|
| PSome {region; _}
|
||||||
| PList Sugar {region; _}
|
| PList Sugar {region; _}
|
||||||
|
| PList PNil region
|
||||||
| PList Raw {region; _}
|
| PList Raw {region; _}
|
||||||
| PTuple {region; _} -> region
|
| PTuple {region; _} -> region
|
||||||
|
|
||||||
@ -1482,15 +1484,10 @@ and print_patterns {value; _} =
|
|||||||
print_token rpar ")"
|
print_token rpar ")"
|
||||||
|
|
||||||
and print_list_pattern = function
|
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
|
| 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; _} =
|
and print_raw {value; _} =
|
||||||
let {lpar; inside; rpar} = value in
|
let {lpar; inside; rpar} = value in
|
||||||
let head, cons, tail = inside in
|
let head, cons, tail = inside in
|
||||||
|
@ -650,7 +650,8 @@ and pattern =
|
|||||||
| PTuple of (pattern, comma) nsepseq par reg
|
| PTuple of (pattern, comma) nsepseq par reg
|
||||||
|
|
||||||
and list_pattern =
|
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
|
| Raw of (pattern * cons * pattern) par reg
|
||||||
|
|
||||||
(* Projecting regions *)
|
(* Projecting regions *)
|
||||||
|
@ -518,7 +518,7 @@ map_remove:
|
|||||||
in {region; value}}
|
in {region; value}}
|
||||||
|
|
||||||
set_patch:
|
set_patch:
|
||||||
Patch path With injection(Set) {
|
Patch path With injection(Set,expr) {
|
||||||
let region = cover $1 $4.region in
|
let region = cover $1 $4.region in
|
||||||
let value = {
|
let value = {
|
||||||
kwd_patch = $1;
|
kwd_patch = $1;
|
||||||
@ -537,8 +537,8 @@ map_patch:
|
|||||||
map_inj = $4}
|
map_inj = $4}
|
||||||
in {region; value}}
|
in {region; value}}
|
||||||
|
|
||||||
injection(Kind):
|
injection(Kind,element):
|
||||||
Kind series(expr,End) {
|
Kind series(element,End) {
|
||||||
let first, (others, terminator, closing) = $2 in
|
let first, (others, terminator, closing) = $2 in
|
||||||
let region = cover $1 closing
|
let region = cover $1 closing
|
||||||
and value = {
|
and value = {
|
||||||
@ -557,7 +557,7 @@ injection(Kind):
|
|||||||
closing = End $2}
|
closing = End $2}
|
||||||
in {region; value}
|
in {region; value}
|
||||||
}
|
}
|
||||||
| Kind LBRACKET series(expr,RBRACKET) {
|
| Kind LBRACKET series(element,RBRACKET) {
|
||||||
let first, (others, terminator, closing) = $3 in
|
let first, (others, terminator, closing) = $3 in
|
||||||
let region = cover $1 closing
|
let region = cover $1 closing
|
||||||
and value = {
|
and value = {
|
||||||
@ -942,7 +942,7 @@ core_expr:
|
|||||||
EConstr (SomeApp {region; value = $1,$2})}
|
EConstr (SomeApp {region; value = $1,$2})}
|
||||||
|
|
||||||
set_expr:
|
set_expr:
|
||||||
injection(Set) { SetInj $1 }
|
injection(Set,expr) { SetInj $1 }
|
||||||
|
|
||||||
map_expr:
|
map_expr:
|
||||||
map_lookup { MapLookUp $1 }
|
map_lookup { MapLookUp $1 }
|
||||||
@ -1010,7 +1010,7 @@ arguments:
|
|||||||
tuple_inj { $1 }
|
tuple_inj { $1 }
|
||||||
|
|
||||||
list_expr:
|
list_expr:
|
||||||
injection(List) { List $1 }
|
injection(List,expr) { List $1 }
|
||||||
| nil { Nil $1 }
|
| nil { Nil $1 }
|
||||||
|
|
||||||
nil:
|
nil:
|
||||||
@ -1054,7 +1054,8 @@ core_pattern:
|
|||||||
in PSome {region; value = $1,$2}}
|
in PSome {region; value = $1,$2}}
|
||||||
|
|
||||||
list_patt:
|
list_patt:
|
||||||
brackets(sepseq(core_pattern,SEMI)) { Sugar $1 }
|
injection(List,core_pattern) { Sugar $1 }
|
||||||
|
| Nil { PNil $1 }
|
||||||
| par(cons_pattern) { Raw $1 }
|
| par(cons_pattern) { Raw $1 }
|
||||||
|
|
||||||
cons_pattern:
|
cons_pattern:
|
||||||
|
Loading…
Reference in New Issue
Block a user