Alpha: do not catch runtime exceptions

This commit is contained in:
Benjamin Canou 2018-06-14 01:41:04 +02:00
parent ec648f5397
commit a8b2ab325e

View File

@ -141,21 +141,19 @@ let parse_annots loc ?(allow_special_var = false) ?(allow_special_field = false)
else error (Unexpected_annotation loc) else error (Unexpected_annotation loc)
| _ -> error (Unexpected_annotation loc) in | _ -> error (Unexpected_annotation loc) in
List.fold_left (fun acc s -> List.fold_left (fun acc s ->
match acc with acc >>? fun acc ->
| Ok acc -> if Compare.Int.(String.length s = 0) then
begin match s.[0] with error (Unexpected_annotation loc)
| ':' -> sub_or_wildcard ~specials:[] (fun a -> `Type_annot a) s acc else match s.[0] with
| '@' -> | ':' -> sub_or_wildcard ~specials:[] (fun a -> `Type_annot a) s acc
sub_or_wildcard | '@' ->
~specials:(if allow_special_var then ['%'] else []) sub_or_wildcard
(fun a -> `Var_annot a) s acc ~specials:(if allow_special_var then ['%'] else [])
| '%' -> sub_or_wildcard (fun a -> `Var_annot a) s acc
~specials:(if allow_special_field then ['@'] else []) | '%' -> sub_or_wildcard
(fun a -> `Field_annot a) s acc ~specials:(if allow_special_field then ['@'] else [])
| _ -> error (Unexpected_annotation loc) (fun a -> `Field_annot a) s acc
| exception Invalid_argument _ -> error (Unexpected_annotation loc) | _ -> error (Unexpected_annotation loc)
end
| Error _ -> acc
) (ok []) l ) (ok []) l
>|? List.rev >|? List.rev
@ -273,10 +271,8 @@ let extract_field_annot
= function = function
| Prim (loc, prim, args, annot) -> | Prim (loc, prim, args, annot) ->
let field_annots, annot = List.partition (fun s -> let field_annots, annot = List.partition (fun s ->
match s.[0] with Compare.Int.(String.length s > 0) &&
| '%' -> true Compare.Char.(s.[0] = '%')
| _ -> false
| exception Invalid_argument _ -> false
) annot in ) annot in
parse_field_annot loc field_annots >|? fun field_annot -> parse_field_annot loc field_annots >|? fun field_annot ->
Prim (loc, prim, args, annot), field_annot Prim (loc, prim, args, annot), field_annot