Refactoring for tuple expressions.
This commit is contained in:
parent
c0800a64ef
commit
847a3a42b6
27
AST.ml
27
AST.ml
@ -510,7 +510,7 @@ and expr =
|
|||||||
| ECall of fun_call
|
| ECall of fun_call
|
||||||
| EBytes of (Lexer.lexeme * Hex.t) reg
|
| EBytes of (Lexer.lexeme * Hex.t) reg
|
||||||
| EUnit of c_Unit
|
| EUnit of c_Unit
|
||||||
| ETuple of tuple
|
| ETuple of tuple_expr
|
||||||
| EPar of expr par reg
|
| EPar of expr par reg
|
||||||
|
|
||||||
and set_expr =
|
and set_expr =
|
||||||
@ -634,7 +634,10 @@ and record_projection = {
|
|||||||
field_path : (field_name, dot) nsepseq
|
field_path : (field_name, dot) nsepseq
|
||||||
}
|
}
|
||||||
|
|
||||||
and tuple = (expr, comma) nsepseq par reg
|
and tuple_expr =
|
||||||
|
TupleInj of tuple_injection
|
||||||
|
|
||||||
|
and tuple_injection = (expr, comma) nsepseq par reg
|
||||||
|
|
||||||
and none_expr = typed_none_expr par
|
and none_expr = typed_none_expr par
|
||||||
|
|
||||||
@ -646,7 +649,7 @@ and typed_none_expr = {
|
|||||||
|
|
||||||
and fun_call = (fun_name * arguments) reg
|
and fun_call = (fun_name * arguments) reg
|
||||||
|
|
||||||
and arguments = tuple
|
and arguments = tuple_injection
|
||||||
|
|
||||||
(* Patterns *)
|
(* Patterns *)
|
||||||
|
|
||||||
@ -690,13 +693,16 @@ let rec expr_to_region = function
|
|||||||
| EConstr e -> constr_expr_to_region e
|
| EConstr e -> constr_expr_to_region e
|
||||||
| ERecord e -> record_expr_to_region e
|
| ERecord e -> record_expr_to_region e
|
||||||
| EMap e -> map_expr_to_region e
|
| EMap e -> map_expr_to_region e
|
||||||
|
| ETuple e -> tuple_expr_to_region e
|
||||||
| EVar {region; _}
|
| EVar {region; _}
|
||||||
| ECall {region; _}
|
| ECall {region; _}
|
||||||
| EBytes {region; _}
|
| EBytes {region; _}
|
||||||
| EUnit region
|
| EUnit region
|
||||||
| ETuple {region; _}
|
|
||||||
| EPar {region; _} -> region
|
| EPar {region; _} -> region
|
||||||
|
|
||||||
|
and tuple_expr_to_region = function
|
||||||
|
TupleInj {region; _} -> region
|
||||||
|
|
||||||
and map_expr_to_region = function
|
and map_expr_to_region = function
|
||||||
MapLookUp {region; _}
|
MapLookUp {region; _}
|
||||||
| MapInj {region; _} -> region
|
| MapInj {region; _} -> region
|
||||||
@ -1214,7 +1220,7 @@ and print_expr = function
|
|||||||
| ECall e -> print_fun_call e
|
| ECall e -> print_fun_call e
|
||||||
| EBytes b -> print_bytes b
|
| EBytes b -> print_bytes b
|
||||||
| EUnit r -> print_token r "Unit"
|
| EUnit r -> print_token r "Unit"
|
||||||
| ETuple e -> print_tuple e
|
| ETuple e -> print_tuple_expr e
|
||||||
| EPar e -> print_par_expr e
|
| EPar e -> print_par_expr e
|
||||||
|
|
||||||
and print_map_expr = function
|
and print_map_expr = function
|
||||||
@ -1394,7 +1400,10 @@ and print_binding {value; _} =
|
|||||||
print_token arrow "->";
|
print_token arrow "->";
|
||||||
print_expr image
|
print_expr image
|
||||||
|
|
||||||
and print_tuple {value; _} =
|
and print_tuple_expr = function
|
||||||
|
TupleInj inj -> print_tuple_inj inj
|
||||||
|
|
||||||
|
and print_tuple_inj {value; _} =
|
||||||
let {lpar; inside; rpar} = value in
|
let {lpar; inside; rpar} = value in
|
||||||
print_token lpar "(";
|
print_token lpar "(";
|
||||||
print_nsepseq "," print_expr inside;
|
print_nsepseq "," print_expr inside;
|
||||||
@ -1428,17 +1437,17 @@ and print_none_expr {value; _} =
|
|||||||
and print_fun_call {value; _} =
|
and print_fun_call {value; _} =
|
||||||
let fun_name, arguments = value in
|
let fun_name, arguments = value in
|
||||||
print_var fun_name;
|
print_var fun_name;
|
||||||
print_tuple arguments
|
print_tuple_inj arguments
|
||||||
|
|
||||||
and print_constr_app {value; _} =
|
and print_constr_app {value; _} =
|
||||||
let constr, arguments = value in
|
let constr, arguments = value in
|
||||||
print_constr constr;
|
print_constr constr;
|
||||||
print_tuple arguments
|
print_tuple_inj arguments
|
||||||
|
|
||||||
and print_some_app {value; _} =
|
and print_some_app {value; _} =
|
||||||
let c_Some, arguments = value in
|
let c_Some, arguments = value in
|
||||||
print_token c_Some "Some";
|
print_token c_Some "Some";
|
||||||
print_tuple arguments
|
print_tuple_inj arguments
|
||||||
|
|
||||||
and print_par_expr {value; _} =
|
and print_par_expr {value; _} =
|
||||||
let {lpar; inside; rpar} = value in
|
let {lpar; inside; rpar} = value in
|
||||||
|
9
AST.mli
9
AST.mli
@ -494,7 +494,7 @@ and expr =
|
|||||||
| ECall of fun_call
|
| ECall of fun_call
|
||||||
| EBytes of (Lexer.lexeme * Hex.t) reg
|
| EBytes of (Lexer.lexeme * Hex.t) reg
|
||||||
| EUnit of c_Unit
|
| EUnit of c_Unit
|
||||||
| ETuple of tuple
|
| ETuple of tuple_expr
|
||||||
| EPar of expr par reg
|
| EPar of expr par reg
|
||||||
|
|
||||||
and set_expr =
|
and set_expr =
|
||||||
@ -618,7 +618,10 @@ and record_projection = {
|
|||||||
field_path : (field_name, dot) nsepseq
|
field_path : (field_name, dot) nsepseq
|
||||||
}
|
}
|
||||||
|
|
||||||
and tuple = (expr, comma) nsepseq par reg
|
and tuple_expr =
|
||||||
|
TupleInj of tuple_injection
|
||||||
|
|
||||||
|
and tuple_injection = (expr, comma) nsepseq par reg
|
||||||
|
|
||||||
and none_expr = typed_none_expr par
|
and none_expr = typed_none_expr par
|
||||||
|
|
||||||
@ -630,7 +633,7 @@ and typed_none_expr = {
|
|||||||
|
|
||||||
and fun_call = (fun_name * arguments) reg
|
and fun_call = (fun_name * arguments) reg
|
||||||
|
|
||||||
and arguments = tuple
|
and arguments = tuple_injection
|
||||||
|
|
||||||
(* Patterns *)
|
(* Patterns *)
|
||||||
|
|
||||||
|
17
Parser.mly
17
Parser.mly
@ -923,13 +923,13 @@ unary_expr:
|
|||||||
|
|
||||||
core_expr:
|
core_expr:
|
||||||
Int { EArith (Int $1) }
|
Int { EArith (Int $1) }
|
||||||
| var { EVar $1 } (* TODO: Path *)
|
| var { EVar $1 }
|
||||||
| String { EString (String $1) }
|
| String { EString (String $1) }
|
||||||
| Bytes { EBytes $1 }
|
| Bytes { EBytes $1 }
|
||||||
| C_False { ELogic (BoolExpr (False $1)) }
|
| C_False { ELogic (BoolExpr (False $1)) }
|
||||||
| C_True { ELogic (BoolExpr (True $1)) }
|
| C_True { ELogic (BoolExpr (True $1)) }
|
||||||
| C_Unit { EUnit $1 }
|
| C_Unit { EUnit $1 }
|
||||||
| tuple { ETuple $1 }
|
| tuple_expr { ETuple $1 }
|
||||||
| list_expr { EList (List $1) }
|
| list_expr { EList (List $1) }
|
||||||
| nil { EList (Nil $1) }
|
| nil { EList (Nil $1) }
|
||||||
| none_expr { EConstr (NoneExpr $1) }
|
| none_expr { EConstr (NoneExpr $1) }
|
||||||
@ -955,9 +955,7 @@ path:
|
|||||||
map_lookup:
|
map_lookup:
|
||||||
path brackets(expr) {
|
path brackets(expr) {
|
||||||
let region = cover (path_to_region $1) $2.region in
|
let region = cover (path_to_region $1) $2.region in
|
||||||
let value = {
|
let value = {path=$1; index=$2}
|
||||||
path = $1;
|
|
||||||
index = $2}
|
|
||||||
in {region; value}
|
in {region; value}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1004,11 +1002,16 @@ fun_call:
|
|||||||
in {region; value = $1,$2}
|
in {region; value = $1,$2}
|
||||||
}
|
}
|
||||||
|
|
||||||
tuple:
|
tuple_expr:
|
||||||
|
tuple_inj {
|
||||||
|
TupleInj $1
|
||||||
|
}
|
||||||
|
|
||||||
|
tuple_inj:
|
||||||
par(nsepseq(expr,COMMA)) { $1 }
|
par(nsepseq(expr,COMMA)) { $1 }
|
||||||
|
|
||||||
arguments:
|
arguments:
|
||||||
tuple { $1 }
|
tuple_inj { $1 }
|
||||||
|
|
||||||
list_expr:
|
list_expr:
|
||||||
List series(expr,End) {
|
List series(expr,End) {
|
||||||
|
Loading…
Reference in New Issue
Block a user