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