diff options
| author | Graydon Hoare <[email protected]> | 2010-07-02 12:02:56 -0700 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2010-07-02 12:02:56 -0700 |
| commit | 285a4735b9565cc75cabd02f7b9c89aa8a70657e (patch) | |
| tree | cd9fbc798e6cc08ec7f758edc1a564a69f672532 /src/boot/fe | |
| parent | Remove nameless node causing errors on doc make. (diff) | |
| download | rust-285a4735b9565cc75cabd02f7b9c89aa8a70657e.tar.xz rust-285a4735b9565cc75cabd02f7b9c89aa8a70657e.zip | |
Parse effect-qualified type definitions.
Diffstat (limited to 'src/boot/fe')
| -rw-r--r-- | src/boot/fe/ast.ml | 15 | ||||
| -rw-r--r-- | src/boot/fe/item.ml | 33 | ||||
| -rw-r--r-- | src/boot/fe/pexp.ml | 3 |
3 files changed, 29 insertions, 22 deletions
diff --git a/src/boot/fe/ast.ml b/src/boot/fe/ast.ml index 6962a9e0..32eed2c1 100644 --- a/src/boot/fe/ast.ml +++ b/src/boot/fe/ast.ml @@ -410,7 +410,7 @@ and obj = and ty_param = ident * (ty_param_idx * effect) and mod_item' = - MOD_ITEM_type of ty + MOD_ITEM_type of (effect * ty) | MOD_ITEM_tag of (header_tup * ty_tag * node_id) | MOD_ITEM_mod of (mod_view * mod_items) | MOD_ITEM_fn of fn @@ -1212,6 +1212,10 @@ and fmt_ident_and_params fmt_ident ff id; fmt_decl_params ff params +and fmt_effect_qual (ff:Format.formatter) (e:effect) : unit = + fmt_effect ff e; + if e <> PURE then fmt ff " "; + and fmt_fn (ff:Format.formatter) (id:ident) @@ -1219,8 +1223,7 @@ and fmt_fn (f:fn) : unit = fmt_obox ff; - fmt_effect ff f.fn_aux.fn_effect; - if f.fn_aux.fn_effect <> PURE then fmt ff " "; + fmt_effect_qual ff f.fn_aux.fn_effect; fmt ff "%s "(if f.fn_aux.fn_is_iter then "iter" else "fn"); fmt_ident_and_params ff id params; fmt_header_slots ff f.fn_input_slots; @@ -1240,8 +1243,7 @@ and fmt_obj (obj:obj) : unit = fmt_obox ff; - fmt_effect ff obj.obj_effect; - if obj.obj_effect <> PURE then fmt ff " "; + fmt_effect_qual ff obj.obj_effect; fmt ff "obj "; fmt_ident_and_params ff id params; fmt_header_slots ff obj.obj_state; @@ -1277,7 +1279,8 @@ and fmt_mod_item (ff:Format.formatter) (id:ident) (item:mod_item) : unit = let params = Array.map (fun i -> i.node) params in begin match item.node.decl_item with - MOD_ITEM_type ty -> + MOD_ITEM_type (e, ty) -> + fmt_effect_qual ff e; fmt ff "type "; fmt_ident_and_params ff id params; fmt ff " = "; diff --git a/src/boot/fe/item.ml b/src/boot/fe/item.ml index 658fb8c4..130909e2 100644 --- a/src/boot/fe/item.ml +++ b/src/boot/fe/item.ml @@ -760,6 +760,20 @@ and parse_obj_item span ps apos bpos (decl params (Ast.MOD_ITEM_obj obj))) +and parse_type_item + (ps:pstate) + (apos:pos) + (effect:Ast.effect) + : (Ast.ident * Ast.mod_item) = + expect ps TYPE; + let (ident, params) = parse_ident_and_params ps "type" in + let _ = expect ps EQ in + let ty = ctxt "mod type item: ty" Pexp.parse_ty ps in + let _ = expect ps SEMI in + let bpos = lexpos ps in + let item = Ast.MOD_ITEM_type (effect, ty) in + (ident, span ps apos bpos (decl params item)) + and parse_mod_item (ps:pstate) : (Ast.ident * Ast.mod_item) = let apos = lexpos ps in @@ -775,13 +789,15 @@ and parse_mod_item (ps:pstate) : (Ast.ident * Ast.mod_item) = | _ -> ps.pstate_infer_lib_name ident in + match peek ps with - IO | STATE | UNSAFE | OBJ | FN | ITER -> + IO | STATE | UNSAFE | TYPE | OBJ | FN | ITER -> let effect = Pexp.parse_effect ps in begin match peek ps with OBJ -> parse_obj_item ps apos effect + | TYPE -> parse_type_item ps apos effect | _ -> let is_iter = (peek ps) = ITER in bump ps; @@ -795,16 +811,6 @@ and parse_mod_item (ps:pstate) : (Ast.ident * Ast.mod_item) = (decl params (Ast.MOD_ITEM_fn fn))) end - | TYPE -> - bump ps; - let (ident, params) = parse_ident_and_params ps "type" in - let _ = expect ps EQ in - let ty = ctxt "mod type item: ty" Pexp.parse_ty ps in - let _ = expect ps SEMI in - let bpos = lexpos ps in - let item = Ast.MOD_ITEM_type ty in - (ident, span ps apos bpos (decl params item)) - | MOD -> bump ps; let (ident, params) = parse_ident_and_params ps "mod" in @@ -964,7 +970,8 @@ and parse_mod_item_from_signature (ps:pstate) in expect ps SEMI; let bpos = lexpos ps in - (ident, span ps apos bpos (decl params (Ast.MOD_ITEM_type t))) + (ident, span ps apos bpos + (decl params (Ast.MOD_ITEM_type (Ast.UNSAFE, t)))) | _ -> raise (unexpected ps) @@ -1008,7 +1015,7 @@ and expand_tags | _ -> [| |] in match item.node.Ast.decl_item with - Ast.MOD_ITEM_type tyd -> handle_ty_decl item.id tyd + Ast.MOD_ITEM_type (_, tyd) -> handle_ty_decl item.id tyd | _ -> [| |] diff --git a/src/boot/fe/pexp.ml b/src/boot/fe/pexp.ml index 1869a7d3..14065466 100644 --- a/src/boot/fe/pexp.ml +++ b/src/boot/fe/pexp.ml @@ -360,9 +360,6 @@ and flag (ps:pstate) (tok:token) : bool = then (bump ps; true) else false -and parse_mutability (ps:pstate) : bool = - flag ps MUTABLE - and parse_slot (aliases_ok:bool) (ps:pstate) : Ast.slot = let mode = match (peek ps, aliases_ok) with |