diff options
| author | Or Brostovski <[email protected]> | 2010-08-21 02:41:43 +0300 |
|---|---|---|
| committer | Or Brostovski <[email protected]> | 2010-08-21 02:41:43 +0300 |
| commit | 0830b5bf24a7117130e0089754cd96e51411284d (patch) | |
| tree | 007dbef82fb2e6e63ac0c8153393c0902c22c5be /src/boot/util | |
| parent | Merge branch 'master' of git://github.com/graydon/rust (diff) | |
| download | rust-0830b5bf24a7117130e0089754cd96e51411284d.tar.xz rust-0830b5bf24a7117130e0089754cd96e51411284d.zip | |
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
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 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} @@ -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. *) |