diff options
| author | Graydon Hoare <[email protected]> | 2010-08-23 18:19:42 -0700 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2010-08-23 18:19:42 -0700 |
| commit | 6e3a77c3a3b32aa6fabad895492c2b24739fedba (patch) | |
| tree | 5e92169975465400c1f617c39fcbacf9bffab706 /src/boot/util | |
| parent | Warn when the value of "spawn" is unused, as it's useless (diff) | |
| parent | Modified parser to handle alt type andadded a few tests (diff) | |
| download | rust-6e3a77c3a3b32aa6fabad895492c2b24739fedba.tar.xz rust-6e3a77c3a3b32aa6fabad895492c2b24739fedba.zip | |
Merge remote branch 'tohava/master'
Conflicts:
src/boot/fe/ast.ml
Diffstat (limited to 'src/boot/util')
| -rw-r--r-- | src/boot/util/common.ml | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/boot/util/common.ml b/src/boot/util/common.ml index 7b0f7848..d9b91856 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} @@ -344,6 +346,11 @@ let rec list_drop n ls = (* + * Auxiliary pair functions. + *) +let pair_rev (x,y) = (y,x) + +(* * Auxiliary option functions. *) @@ -357,12 +364,36 @@ 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. *) |