Make type_expr_simple less complicated.

This commit is contained in:
Sander Spies 2019-12-16 14:54:12 +01:00
parent f5aebffd0b
commit 09875cf1da

View File

@ -388,30 +388,14 @@ type_expr_simple_args:
par(nsepseq(type_expr_simple, ",")) { $1 } par(nsepseq(type_expr_simple, ",")) { $1 }
type_expr_simple: type_expr_simple:
core_expr_2 type_expr_simple_args? { type_name type_expr_simple_args? {
let args = $2 in let args = $2 in
let constr = match args with
match $1 with Some {value; _} ->
EVar i -> i let region = cover $1.region value.rpar in
| EProj {value={struct_name; field_path; _}; region} -> let value = $1, {region; value}
let app a = function in TApp {region; value}
FieldName v -> a ^ "." ^ v.value | None -> TVar $1
| Component {value = c, _; _} -> a ^ "." ^ c in
let value =
Utils.nsepseq_foldl app struct_name.value field_path
in {region; value}
| EArith Mutez r | EArith Int r | EArith Nat r ->
{r with value = fst r.value}
| EString String s -> s
| ELogic BoolExpr (True t) -> {region=t; value="true"}
| ELogic BoolExpr (False f) -> {region=f; value="false"}
| _ -> failwith "Not supported" (* TODO: raise a proper exception *)
in match args with
Some {value; _} ->
let region = cover (expr_to_region $1) value.rpar in
let value = constr, {region; value}
in TApp {region; value}
| None -> TVar constr
} }
| "(" nsepseq(type_expr_simple, ",") ")" { | "(" nsepseq(type_expr_simple, ",") ")" {
TProd {region = cover $1 $3; value=$2} TProd {region = cover $1 $3; value=$2}