From 0830b5bf24a7117130e0089754cd96e51411284d Mon Sep 17 00:00:00 2001 From: Or Brostovski Date: Sat, 21 Aug 2010 02:41:43 +0300 Subject: Modified parser to handle alt type andadded a few tests ast.ml - modified arm types for easier polymorphism - fixed a bug in fmt_type_arm dead.ml - modified arm types for easier polymorphism common.ml - added 'either' - added some useful auxiliary functions item.ml - modified arm code to be more polymorphic and handle both alt-tag and alt-type, also fixed the problematic case in bad-alt.rs Makefile - added XFAIL for new alt-type test bad-alt.rs - added test for invalid alt syntax alt-type-simple.rs - added simple test for alt type --- src/boot/util/common.ml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/boot/util') diff --git a/src/boot/util/common.ml b/src/boot/util/common.ml index 58caf78d..3a467f1c 100644 --- a/src/boot/util/common.ml +++ b/src/boot/util/common.ml @@ -3,6 +3,8 @@ * types shared across all phases of the compiler. *) +type ('a, 'b) either = Left of 'a | Right of 'b + type filename = string type pos = (filename * int * int) type span = {lo: pos; hi: pos} @@ -343,6 +345,11 @@ let rec list_drop n ls = ;; +(* + * Auxiliary pair functions. + *) +let pair_rev (x,y) = (y,x) + (* * Auxiliary option functions. *) @@ -357,11 +364,35 @@ let may f x = Some x' -> f x' | None -> () +let option_map f x = + match x with + Some x' -> Some (f x') + | None -> None + let option_get x = match x with Some x -> x | None -> raise Not_found +(* + * Auxiliary either functions. + *) +let either_has_left x = + match x with + Left _ -> true + | Right _ -> false + +let either_has_right x = not (either_has_left x) + +let either_get_left x = + match x with + Left x -> x + | Right _ -> raise Not_found + +let either_get_right x = + match x with + Right x -> x + | Left _ -> raise Not_found (* * Auxiliary stack functions. *) -- cgit v1.2.3