update pattern

This commit is contained in:
Mylloon 2023-10-21 11:15:17 +02:00
parent 2f05f7ba09
commit 4d08e97bd8
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -133,10 +133,6 @@ branch:
simple_pattern:
/* Parenthésage */
| LPAREN p=pattern RPAREN {
p
}
/* Motif universel liant */
| i=located(identifier) {
PVariable i
@ -145,6 +141,10 @@ simple_pattern:
| WILDCARD {
PWildcard
}
/* N-uplets ou parenthésage */
| LPAREN p=optionlist(separated_nonempty_list(COMMA, located(pattern))) RPAREN {
PTuple(p)
}
/* Annotation de type */
| p=located(simple_pattern) COLON ty=located(ty) {
PTypeAnnotation(p, ty)
@ -154,65 +154,35 @@ simple_pattern:
PLiteral l
}
/* Valeurs étiquetées */
| const=located(constructor) {
PTaggedValue(const, None, [])
}
| const=located(constructor)
INFERIOR liste_ty=option(separated_nonempty_list(COMMA, located(ty))) SUPERIOR {
PTaggedValue(const, liste_ty, [])
}
| const=located(constructor)
LPAREN liste_pattern=separated_nonempty_list(COMMA, located(pattern)) RPAREN {
PTaggedValue(const, None, liste_pattern)
}
| const=located(constructor)
INFERIOR liste_ty=option(separated_nonempty_list(COMMA, located(ty))) SUPERIOR
LPAREN liste_pattern=separated_nonempty_list(COMMA, located(pattern)) RPAREN {
PTaggedValue(const, liste_ty, liste_pattern)
| const=located(constructor) tl=option(type_list) pl=optionlist(pattern_list) {
PTaggedValue(const, tl, pl)
}
/* Enregistrement */
/* à refaire */
| LBRACE l=separated_nonempty_list(
COMMA,
separated_pair(located(label), EQUAL, located(pattern))
) RBRACE {
PRecord(l, None)
) RBRACE tl=option(type_list) {
PRecord(l, tl)
}
| LBRACE l=separated_nonempty_list(
COMMA,
separated_pair(located(label), EQUAL, located(pattern))
) RBRACE INFERIOR SUPERIOR {
PRecord(l, None)
}
| LBRACE l=separated_nonempty_list(
COMMA,
separated_pair(located(label), EQUAL, located(pattern))
) RBRACE INFERIOR liste_ty=option(separated_nonempty_list(COMMA, located(ty))) SUPERIOR {
PRecord(l, liste_ty)
}
/* Disjonction */
pattern:
| p1=pattern_and {
| p1=simple_pattern {
p1
}
| p1=located(pattern_and) PIPE p_list=separated_nonempty_list(PIPE, located(pattern_and)) {
/* Disjonction */
| p1=located(simple_pattern)
PIPE p_list=separated_nonempty_list(PIPE, located(simple_pattern)) {
POr(p1 :: p_list)
}
/* Conjonction */
pattern_and:
| p1=simple_pattern{
p1
}
| p1=located(simple_pattern)
AND p_list=separated_nonempty_list(AND, located(simple_pattern)) {
PAnd(p1 :: p_list)
}
pattern_list:
/* N-uplets */
| LPAREN p=separated_nonempty_list(COMMA, pattern) RPAREN {
p
| LPAREN el=separated_nonempty_list(COMMA, located(pattern)) RPAREN {
el
}