fmt
This commit is contained in:
parent
aa5009e94c
commit
7683cada98
1 changed files with 113 additions and 111 deletions
|
@ -30,7 +30,7 @@ program:
|
||||||
/* Attrapes les erreurs de syntaxe */
|
/* Attrapes les erreurs de syntaxe */
|
||||||
| e=located(error) {
|
| e=located(error) {
|
||||||
Error.error "parsing" (Position.position e) "Syntax error."
|
Error.error "parsing" (Position.position e) "Syntax error."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
definition:
|
definition:
|
||||||
|
@ -60,7 +60,9 @@ tdefinition:
|
||||||
}
|
}
|
||||||
|
|
||||||
label_with_type:
|
label_with_type:
|
||||||
| l=located(label) COLON t=located(ty) { l, t }
|
| l=located(label) COLON t=located(ty) {
|
||||||
|
l, t
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
vdefinition:
|
vdefinition:
|
||||||
|
@ -97,17 +99,17 @@ fundef:
|
||||||
* TODO : y'a environ 50 warnings ici, surtout au niveau du POr et PAnd */
|
* TODO : y'a environ 50 warnings ici, surtout au niveau du POr et PAnd */
|
||||||
|
|
||||||
branches:
|
branches:
|
||||||
| b=separated_nonempty_list(PIPE,located(branch)){
|
| b=separated_nonempty_list(PIPE, located(branch)) {
|
||||||
b
|
b
|
||||||
}
|
}
|
||||||
| PIPE b = separated_nonempty_list(PIPE,located(branch)){
|
| PIPE b=separated_nonempty_list(PIPE, located(branch)) {
|
||||||
b
|
b
|
||||||
}
|
}
|
||||||
|
|
||||||
branch:
|
branch:
|
||||||
| p = located(pattern) ARROW e=located(expression){
|
| p=located(pattern) ARROW e=located(expression) {
|
||||||
Branch(p,e)
|
Branch(p, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
simple_pattern:
|
simple_pattern:
|
||||||
|
@ -125,7 +127,7 @@ simple_pattern:
|
||||||
}
|
}
|
||||||
/* 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)
|
||||||
}
|
}
|
||||||
/* Entier / Caractère / String */
|
/* Entier / Caractère / String */
|
||||||
| l=located(literal) {
|
| l=located(literal) {
|
||||||
|
@ -149,7 +151,7 @@ simple_pattern:
|
||||||
| LBRACE l=separated_nonempty_list(COMMA, separated_pair(located(label), EQUAL, located(pattern))) RBRACE {
|
| LBRACE l=separated_nonempty_list(COMMA, separated_pair(located(label), EQUAL, located(pattern))) RBRACE {
|
||||||
PRecord(l, None)
|
PRecord(l, None)
|
||||||
}
|
}
|
||||||
| LBRACE l=separated_nonempty_list(COMMA,separated_pair(located(label), EQUAL, located(pattern))) RBRACE INFERIOR SUPERIOR {
|
| LBRACE l=separated_nonempty_list(COMMA, separated_pair(located(label), EQUAL, located(pattern))) RBRACE INFERIOR SUPERIOR {
|
||||||
PRecord(l, None)
|
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 {
|
| 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 {
|
||||||
|
@ -158,9 +160,9 @@ simple_pattern:
|
||||||
/* Disjonction */
|
/* Disjonction */
|
||||||
|
|
||||||
pattern:
|
pattern:
|
||||||
| p1=pattern_and{
|
| p1=pattern_and {
|
||||||
p1
|
p1
|
||||||
}
|
}
|
||||||
| p1=located(pattern_and) PIPE p_list=separated_nonempty_list(PIPE, located(pattern_and)) {
|
| p1=located(pattern_and) PIPE p_list=separated_nonempty_list(PIPE, located(pattern_and)) {
|
||||||
POr(p1 :: p_list)
|
POr(p1 :: p_list)
|
||||||
}
|
}
|
||||||
|
@ -168,7 +170,7 @@ pattern:
|
||||||
pattern_and:
|
pattern_and:
|
||||||
| p1=simple_pattern{
|
| p1=simple_pattern{
|
||||||
p1
|
p1
|
||||||
}
|
}
|
||||||
| p1=located(simple_pattern) AND p_list=separated_nonempty_list(AND, located(simple_pattern)) {
|
| p1=located(simple_pattern) AND p_list=separated_nonempty_list(AND, located(simple_pattern)) {
|
||||||
PAnd(p1 :: p_list)
|
PAnd(p1 :: p_list)
|
||||||
}
|
}
|
||||||
|
@ -243,111 +245,110 @@ simple_expression:
|
||||||
Literal l
|
Literal l
|
||||||
}
|
}
|
||||||
/* Variable */
|
/* Variable */
|
||||||
| i = located(identifier){
|
| i=located(identifier) {
|
||||||
Variable(i,None)
|
Variable(i, None)
|
||||||
}
|
}
|
||||||
| i = located(identifier) INFERIOR SUPERIOR {
|
| i=located(identifier) INFERIOR SUPERIOR {
|
||||||
Variable(i,None)
|
Variable(i, None)
|
||||||
}
|
}
|
||||||
| i = located(identifier) INFERIOR t_list = option(separated_nonempty_list(COMMA,located(ty))) SUPERIOR{
|
| i=located(identifier) INFERIOR t_list=option(separated_nonempty_list(COMMA, located(ty))) SUPERIOR {
|
||||||
Variable(i,t_list)
|
Variable(i, t_list)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Tuple n = 0 and n > 1 */
|
/* Tuple n = 0 and n > 1 */
|
||||||
| LPAREN RPAREN {
|
| LPAREN RPAREN {
|
||||||
Tuple([])
|
Tuple([])
|
||||||
}
|
}
|
||||||
| LPAREN e=located(expression) COMMA e_list = separated_nonempty_list(COMMA,located(expression)) RPAREN {
|
| LPAREN e=located(expression) COMMA e_list=separated_nonempty_list(COMMA, located(expression)) RPAREN {
|
||||||
Tuple(e::e_list)
|
Tuple(e::e_list)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Tagged Value*/
|
/* Tagged Value*/
|
||||||
/* K */
|
/* K */
|
||||||
| const = located(constructor){
|
| const=located(constructor) {
|
||||||
Tagged(const,None,[])
|
Tagged(const, None, [])
|
||||||
}
|
}
|
||||||
/* K < > */
|
/* K < > */
|
||||||
| const = located(constructor) INFERIOR SUPERIOR{
|
| const=located(constructor) INFERIOR SUPERIOR {
|
||||||
Tagged(const,None,[])
|
Tagged(const, None, [])
|
||||||
}
|
}
|
||||||
/* K < > (e1, ..., en) */
|
/* K < > (e1, ..., en) */
|
||||||
| const = located(constructor) INFERIOR SUPERIOR LPAREN e_list=separated_nonempty_list(COMMA,located(expression)) RPAREN {
|
| const=located(constructor) INFERIOR SUPERIOR LPAREN e_list=separated_nonempty_list(COMMA, located(expression)) RPAREN {
|
||||||
Tagged(const,None,e_list)
|
Tagged(const, None, e_list)
|
||||||
}
|
}
|
||||||
/* K <ty_1, ... ty_m> */
|
/* K <ty_1, ... ty_m> */
|
||||||
| const = located(constructor) INFERIOR t_list = option(separated_nonempty_list(COMMA,located(ty))) SUPERIOR {
|
| const=located(constructor) INFERIOR t_list=option(separated_nonempty_list(COMMA, located(ty))) SUPERIOR {
|
||||||
Tagged(const,t_list,[])
|
Tagged(const, t_list, [])
|
||||||
}
|
}
|
||||||
/* K <ty_1, ..., ty_m> (e1,...,en) */
|
/* K <ty_1, ..., ty_m> (e1,...,en) */
|
||||||
| const = located(constructor) INFERIOR t_list = option(separated_nonempty_list(COMMA,located(ty))) SUPERIOR LPAREN e_list=separated_nonempty_list(COMMA,located(expression)) RPAREN{
|
| const=located(constructor) INFERIOR t_list=option(separated_nonempty_list(COMMA, located(ty))) SUPERIOR LPAREN e_list=separated_nonempty_list(COMMA, located(expression)) RPAREN {
|
||||||
Tagged(const,t_list,e_list)
|
Tagged(const, t_list, e_list)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Record */
|
/* Record */
|
||||||
| LBRACE l=separated_nonempty_list(COMMA, separated_pair(located(label), EQUAL, located(expression))) RBRACE {
|
| LBRACE l=separated_nonempty_list(COMMA, separated_pair(located(label), EQUAL, located(expression))) RBRACE {
|
||||||
Record(l, None)
|
Record(l, None)
|
||||||
}
|
}
|
||||||
| LBRACE l=separated_nonempty_list(COMMA, separated_pair(located(label), EQUAL, located(expression))) RBRACE INFERIOR SUPERIOR {
|
| LBRACE l=separated_nonempty_list(COMMA, separated_pair(located(label), EQUAL, located(expression))) RBRACE INFERIOR SUPERIOR {
|
||||||
Record(l, None)
|
Record(l, None)
|
||||||
}
|
}
|
||||||
| LBRACE l=separated_nonempty_list(COMMA, separated_pair(located(label), EQUAL, located(expression))) RBRACE INFERIOR t_list = option(separated_nonempty_list(COMMA,located(ty))) SUPERIOR{
|
| LBRACE l=separated_nonempty_list(COMMA, separated_pair(located(label), EQUAL, located(expression))) RBRACE INFERIOR t_list=option(separated_nonempty_list(COMMA, located(ty))) SUPERIOR {
|
||||||
Record(l, t_list)
|
Record(l, t_list)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Lecture de variable */
|
/* Lecture de variable */
|
||||||
/* ! expr */
|
/* ! expr */
|
||||||
| EXCLA e=located(simple_expression) {
|
| EXCLA e=located(simple_expression) {
|
||||||
Read(e)
|
Read(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
expression:
|
expression:
|
||||||
| e=simple_expression{
|
| e=simple_expression {
|
||||||
e
|
e
|
||||||
}
|
}
|
||||||
/* Field */
|
/* Field */
|
||||||
|
|
||||||
/* e.l */
|
/* e.l */
|
||||||
| e=located(expression) DOT l = located(label){
|
| e=located(expression) DOT l=located(label) {
|
||||||
Field(e,l,None)
|
Field(e, l, None)
|
||||||
}
|
}
|
||||||
/* e.l < > */
|
/* e.l < > */
|
||||||
| e=located(expression) DOT l = located(label) INFERIOR SUPERIOR {
|
| e=located(expression) DOT l=located(label) INFERIOR SUPERIOR {
|
||||||
Field(e,l,None)
|
Field(e, l, None)
|
||||||
}
|
}
|
||||||
/* e.l <ty_1...ty_n>*/
|
/* e.l <ty_1...ty_n>*/
|
||||||
| e = located(expression) DOT l=located(label) INFERIOR t_list = option(separated_nonempty_list(COMMA,located(ty))) SUPERIOR {
|
| e=located(expression) DOT l=located(label) INFERIOR t_list=option(separated_nonempty_list(COMMA, located(ty))) SUPERIOR {
|
||||||
Field(e,l,t_list)
|
Field(e, l, t_list)
|
||||||
}
|
}
|
||||||
/* Sequence */
|
/* Sequence */
|
||||||
/* Pas sûr, voir s'il ne fuat pas une troisième couche d'expression */
|
/* Pas sûr, voir s'il ne fuat pas une troisième couche d'expression */
|
||||||
| e = located(simple_expression) SEMICOLON e_list = separated_nonempty_list(SEMICOLON,located(simple_expression)){
|
| e=located(simple_expression) SEMICOLON e_list=separated_nonempty_list(SEMICOLON, located(simple_expression)) {
|
||||||
Sequence(e::e_list)
|
Sequence(e::e_list)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Definition locale */
|
/* Definition locale */
|
||||||
| vd= vdefinition SEMICOLON e=located(expression){
|
| vd=vdefinition SEMICOLON e=located(expression) {
|
||||||
Define(vd,e)
|
Define(vd, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fonction anonyme */
|
/* Fonction anonyme */
|
||||||
| BACKSLASH p=located(pattern) ARROW e=located(expression){
|
| BACKSLASH p=located(pattern) ARROW e=located(expression) {
|
||||||
Fun(FunctionDefinition(p,e))
|
Fun(FunctionDefinition(p, e))
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Application */
|
/* Application */
|
||||||
| e1=located(expression) e2=located(expression){
|
| e1=located(expression) e2=located(expression) {
|
||||||
Apply(e1,e2)
|
Apply(e1, e2)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO operation binaire mais j'ai pas très bien compris encore */
|
/* TODO operation binaire mais j'ai pas très bien compris encore */
|
||||||
|
|
||||||
|
|
||||||
/* Match (exp) {| ...| ... | ...} */
|
/* Match (exp) {| ...| ... | ...} */
|
||||||
| MATCH LPAREN e=located(expression) RPAREN
|
| MATCH LPAREN e=located(expression) RPAREN LBRACE b=branches RBRACE {
|
||||||
LBRACE b=branches RBRACE {
|
Case(e, b)
|
||||||
Case(e,b)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO if ( exp ) then { expr } j'ai RIEN COMPRIS */
|
/* TODO if ( exp ) then { expr } j'ai RIEN COMPRIS */
|
||||||
|
@ -357,52 +358,53 @@ simple_expression:
|
||||||
IfThenElse(e,e2,None)
|
IfThenElse(e,e2,None)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
/* if ( expr ) then { expr } else { expr } */
|
/* if ( expr ) then { expr } else { expr } */
|
||||||
| IF LPAREN e=located(expression) RPAREN
|
| IF LPAREN e=located(expression) RPAREN
|
||||||
THEN LBRACE e2=located(expression) RBRACE
|
THEN LBRACE e2=located(expression) RBRACE
|
||||||
ELSE LBRACE e3=located(expression) RBRACE {
|
ELSE LBRACE e3=located(expression) RBRACE {
|
||||||
IfThenElse(e,e2,e3)
|
IfThenElse(e, e2, e3)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reference ref expr */
|
/* Reference ref expr */
|
||||||
|
|
||||||
| REF e=located(expression){
|
| REF e=located(expression) {
|
||||||
Ref(e)
|
Ref(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Affectation */
|
/* Affectation */
|
||||||
/* expr := expr */
|
/* expr := expr */
|
||||||
|
|
||||||
| e1=located(expression) ASSIGN e2=located(expression){
|
| e1=located(expression) ASSIGN e2=located(expression) {
|
||||||
Assign(e1,e2)
|
Assign(e1, e2)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* While */
|
/* While */
|
||||||
/* while ( expr ) { expr } */
|
/* while ( expr ) { expr } */
|
||||||
| WHILE LPAREN e=located(expression) RPAREN
|
| WHILE LPAREN e=located(expression) RPAREN
|
||||||
LBRACE e2=located(expression) RBRACE {
|
LBRACE e2=located(expression) RBRACE {
|
||||||
While(e,e2)
|
While(e, e2)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Do while TODO */
|
/* Do while TODO */
|
||||||
/* do { expr } until ( expr ) */
|
/* do { expr } until ( expr ) */
|
||||||
|
|
||||||
/* boucle for */
|
/* boucle for */
|
||||||
/* for x in (e1 to e2) { expr } */
|
/* for x in (e1 to e2) { expr } */
|
||||||
| FOR x=located(identifier)
|
| FOR x=located(identifier)
|
||||||
FROM LPAREN e1=located(expression) RPAREN TO LPAREN e2=located(expression) RPAREN
|
FROM LPAREN e1=located(expression) RPAREN TO LPAREN e2=located(expression) RPAREN
|
||||||
LBRACE e3=located(expression) RBRACE
|
LBRACE e3=located(expression) RBRACE {
|
||||||
{ For(x,e1,e2,e3)}
|
For(x, e1, e2, e3)
|
||||||
|
}
|
||||||
|
|
||||||
/* Parenthésage pas sûr mais je vois pas sinon*/
|
/* Parenthésage pas sûr mais je vois pas sinon*/
|
||||||
| LPAREN e=expression RPAREN {
|
| LPAREN e=expression RPAREN {
|
||||||
e
|
e
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Annotation de type */
|
/* Annotation de type */
|
||||||
/* (e : ty) */
|
/* (e : ty) */
|
||||||
| LPAREN e=located(expression) COLON t=located(ty) RPAREN {
|
| LPAREN e=located(expression) COLON t=located(ty) RPAREN {
|
||||||
TypeAnnotation(e,t)
|
TypeAnnotation(e, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue