let ident_of_expr =
let error () =
invalid_arg
"ident_of_expr: this expression is not an identifier" in
let rec self =
function
| Ast.ExApp (_loc, e1, e2) ->
Ast.IdApp (_loc, (self e1), (self e2))
| Ast.ExAcc (_loc, e1, e2) ->
Ast.IdAcc (_loc, (self e1), (self e2))
| Ast.ExId (_, (Ast.IdLid (_, _))) -> error ()
| Ast.ExId (_, i) ->
if is_module_longident i then i else error ()
| _ -> error ()
in
function
| Ast.ExId (_, i) -> i
| Ast.ExApp (_, _, _) -> error ()
| t -> self t