diff options
| author | Alain Frisch <alain@frisch.fr> | 2013-04-17 09:46:52 +0000 |
|---|---|---|
| committer | Alain Frisch <alain@frisch.fr> | 2013-04-17 09:46:52 +0000 |
| commit | b36ec9f7644410df981d954aae686eaf3f59a590 (patch) | |
| tree | ede621009ff1bd6fb99b93b658e49705a0310229 /parsing | |
| parent | 501dfd2b5e2425b2b40afe5ce9782503e68f8e22 (diff) | |
| download | ocaml-b36ec9f7644410df981d954aae686eaf3f59a590.tar.gz | |
Get rid of the 'explicit arity' flag on Pexp_construct/Ppat_construct. If really requires (for camlp5?), the feature should be reimplemented with attributes.
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/extension_points@13549 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'parsing')
| -rw-r--r-- | parsing/ast_helper.ml | 8 | ||||
| -rw-r--r-- | parsing/ast_helper.mli | 4 | ||||
| -rw-r--r-- | parsing/ast_mapper.ml | 4 | ||||
| -rw-r--r-- | parsing/parser.mly | 20 | ||||
| -rw-r--r-- | parsing/parsetree.mli | 30 | ||||
| -rw-r--r-- | parsing/pprintast.ml | 26 | ||||
| -rw-r--r-- | parsing/printast.ml | 6 |
7 files changed, 41 insertions, 57 deletions
diff --git a/parsing/ast_helper.ml b/parsing/ast_helper.ml index 8e40c215b6..5796177cd8 100644 --- a/parsing/ast_helper.ml +++ b/parsing/ast_helper.ml @@ -61,7 +61,7 @@ module Pat = struct let constant ?loc ?attrs a = mk ?loc ?attrs (Ppat_constant a) let interval ?loc ?attrs a b = mk ?loc ?attrs (Ppat_interval (a, b)) let tuple ?loc ?attrs a = mk ?loc ?attrs (Ppat_tuple a) - let construct ?loc ?attrs a b c = mk ?loc ?attrs (Ppat_construct (a, b, c)) + let construct ?loc ?attrs a b = mk ?loc ?attrs (Ppat_construct (a, b)) let variant ?loc ?attrs a b = mk ?loc ?attrs (Ppat_variant (a, b)) let record ?loc ?attrs a b = mk ?loc ?attrs (Ppat_record (a, b)) let array ?loc ?attrs a = mk ?loc ?attrs (Ppat_array a) @@ -85,7 +85,7 @@ module Exp = struct let match_ ?loc ?attrs a b = mk ?loc ?attrs (Pexp_match (a, b)) let try_ ?loc ?attrs a b = mk ?loc ?attrs (Pexp_try (a, b)) let tuple ?loc ?attrs a = mk ?loc ?attrs (Pexp_tuple a) - let construct ?loc ?attrs a b c = mk ?loc ?attrs (Pexp_construct (a, b, c)) + let construct ?loc ?attrs a b = mk ?loc ?attrs (Pexp_construct (a, b)) let variant ?loc ?attrs a b = mk ?loc ?attrs (Pexp_variant (a, b)) let record ?loc ?attrs a b = mk ?loc ?attrs (Pexp_record (a, b)) let field ?loc ?attrs a b = mk ?loc ?attrs (Pexp_field (a, b)) @@ -372,7 +372,7 @@ module Convenience = struct let lid s = mkloc (Longident.parse s) !default_loc let tuple l = Exp.tuple l - let constr s args = Exp.construct (lid s) (may_tuple Exp.tuple args) false + let constr s args = Exp.construct (lid s) (may_tuple Exp.tuple args) let nil () = constr "[]" [] let unit () = constr "()" [] let cons hd tl = constr "::" [hd; tl] @@ -391,7 +391,7 @@ module Convenience = struct Exp.let_ (if recursive then Recursive else Nonrecursive) b body let pvar s = Pat.var (mkloc s !default_loc) - let pconstr s args = Pat.construct (lid s) (may_tuple Pat.tuple args) true + let pconstr s args = Pat.construct (lid s) (may_tuple Pat.tuple args) let punit () = pconstr "()" [] diff --git a/parsing/ast_helper.mli b/parsing/ast_helper.mli index 5bade91346..5952c1b522 100644 --- a/parsing/ast_helper.mli +++ b/parsing/ast_helper.mli @@ -64,7 +64,7 @@ module Pat: val constant: ?loc:loc -> ?attrs:attrs -> constant -> pattern val interval: ?loc:loc -> ?attrs:attrs -> constant -> constant -> pattern val tuple: ?loc:loc -> ?attrs:attrs -> pattern list -> pattern - val construct: ?loc:loc -> ?attrs:attrs -> lid -> pattern option -> bool -> pattern + val construct: ?loc:loc -> ?attrs:attrs -> lid -> pattern option -> pattern val variant: ?loc:loc -> ?attrs:attrs -> label -> pattern option -> pattern val record: ?loc:loc -> ?attrs:attrs -> (lid * pattern) list -> closed_flag -> pattern val array: ?loc:loc -> ?attrs:attrs -> pattern list -> pattern @@ -90,7 +90,7 @@ module Exp: val match_: ?loc:loc -> ?attrs:attrs -> expression -> case list -> expression val try_: ?loc:loc -> ?attrs:attrs -> expression -> case list -> expression val tuple: ?loc:loc -> ?attrs:attrs -> expression list -> expression - val construct: ?loc:loc -> ?attrs:attrs -> lid -> expression option -> bool -> expression + val construct: ?loc:loc -> ?attrs:attrs -> lid -> expression option -> expression val variant: ?loc:loc -> ?attrs:attrs -> label -> expression option -> expression val record: ?loc:loc -> ?attrs:attrs -> (lid * expression) list -> expression option -> expression val field: ?loc:loc -> ?attrs:attrs -> expression -> lid -> expression diff --git a/parsing/ast_mapper.ml b/parsing/ast_mapper.ml index 4f150d5d90..901042e0ac 100644 --- a/parsing/ast_mapper.ml +++ b/parsing/ast_mapper.ml @@ -211,7 +211,7 @@ module E = struct | Pexp_match (e, l) -> match_ ~loc ~attrs (sub # expr e) (List.map (map_case sub) l) | Pexp_try (e, l) -> try_ ~loc ~attrs (sub # expr e) (List.map (map_case sub) l) | Pexp_tuple el -> tuple ~loc ~attrs (List.map (sub # expr) el) - | Pexp_construct (lid, arg, b) -> construct ~loc ~attrs (map_loc sub lid) (map_opt (sub # expr) arg) b + | Pexp_construct (lid, arg) -> construct ~loc ~attrs (map_loc sub lid) (map_opt (sub # expr) arg) | Pexp_variant (lab, eo) -> variant ~loc ~attrs lab (map_opt (sub # expr) eo) | Pexp_record (l, eo) -> record ~loc ~attrs (List.map (map_tuple (map_loc sub) (sub # expr)) l) (map_opt (sub # expr) eo) | Pexp_field (e, lid) -> field ~loc ~attrs (sub # expr e) (map_loc sub lid) @@ -251,7 +251,7 @@ module P = struct | Ppat_constant c -> constant ~loc ~attrs c | Ppat_interval (c1, c2) -> interval ~loc ~attrs c1 c2 | Ppat_tuple pl -> tuple ~loc ~attrs (List.map (sub # pat) pl) - | Ppat_construct (l, p, b) -> construct ~loc ~attrs (map_loc sub l) (map_opt (sub # pat) p) b + | Ppat_construct (l, p) -> construct ~loc ~attrs (map_loc sub l) (map_opt (sub # pat) p) | Ppat_variant (l, p) -> variant ~loc ~attrs l (map_opt (sub # pat) p) | Ppat_record (lpl, cf) -> record ~loc ~attrs (List.map (map_tuple (map_loc sub) (sub # pat)) lpl) cf diff --git a/parsing/parser.mly b/parsing/parser.mly index fcbdeb65db..22c4e0568c 100644 --- a/parsing/parser.mly +++ b/parsing/parser.mly @@ -69,7 +69,7 @@ let ghtyp d = Typ.mk ~loc:(symbol_gloc ()) d let ghloc d = { txt = d; loc = symbol_gloc () } let ghunit () = - ghexp (Pexp_construct (mknoloc (Lident "()"), None, false)) + ghexp (Pexp_construct (mknoloc (Lident "()"), None)) let mkinfix arg1 name arg2 = mkexp(Pexp_apply(mkoperator name 2, ["", arg1; "", arg2])) @@ -106,16 +106,16 @@ let mkuplus name arg = mkexp(Pexp_apply(mkoperator ("~" ^ name) 1, ["", arg])) let mkexp_cons consloc args loc = - Exp.mk ~loc (Pexp_construct(mkloc (Lident "::") consloc, Some args, false)) + Exp.mk ~loc (Pexp_construct(mkloc (Lident "::") consloc, Some args)) let mkpat_cons consloc args loc = - Pat.mk ~loc (Ppat_construct(mkloc (Lident "::") consloc, Some args, false)) + Pat.mk ~loc (Ppat_construct(mkloc (Lident "::") consloc, Some args)) let rec mktailexp nilloc = function [] -> let loc = { nilloc with loc_ghost = true } in let nil = { txt = Lident "[]"; loc = loc } in - Exp.mk ~loc (Pexp_construct (nil, None, false)) + Exp.mk ~loc (Pexp_construct (nil, None)) | e1 :: el -> let exp_el = mktailexp nilloc el in let loc = {loc_start = e1.pexp_loc.loc_start; @@ -129,7 +129,7 @@ let rec mktailpat nilloc = function [] -> let loc = { nilloc with loc_ghost = true } in let nil = { txt = Lident "[]"; loc = loc } in - Pat.mk ~loc (Ppat_construct (nil, None, false)) + Pat.mk ~loc (Ppat_construct (nil, None)) | p1 :: pl -> let pat_pl = mktailpat nilloc pl in let loc = {loc_start = p1.ppat_loc.loc_start; @@ -1028,7 +1028,7 @@ expr: | expr_comma_list %prec below_COMMA { mkexp(Pexp_tuple(List.rev $1)) } | constr_longident simple_expr %prec below_SHARP - { mkexp(Pexp_construct(mkrhs $1 1, Some $2, false)) } + { mkexp(Pexp_construct(mkrhs $1 1, Some $2)) } | name_tag simple_expr %prec below_SHARP { mkexp(Pexp_variant($1, Some $2)) } | IF ext_attributes seq_expr THEN expr ELSE expr @@ -1114,7 +1114,7 @@ simple_expr: | constant { mkexp(Pexp_constant $1) } | constr_longident %prec prec_constant_constructor - { mkexp(Pexp_construct(mkrhs $1 1, None, false)) } + { mkexp(Pexp_construct(mkrhs $1 1, None)) } | name_tag %prec prec_constant_constructor { mkexp(Pexp_variant($1, None)) } | LPAREN seq_expr RPAREN @@ -1125,7 +1125,7 @@ simple_expr: { wrap_exp_attrs (reloc_exp $3) $2 (* check location *) } | BEGIN ext_attributes END { mkexp_attrs (Pexp_construct (mkloc (Lident "()") (symbol_rloc ()), - None, false)) $2 } + None)) $2 } | BEGIN ext_attributes seq_expr error { unclosed "begin" 1 "end" 3 } | LPAREN seq_expr type_constraint RPAREN @@ -1318,7 +1318,7 @@ pattern: | pattern_comma_list %prec below_COMMA { mkpat(Ppat_tuple(List.rev $1)) } | constr_longident pattern %prec prec_constr_appl - { mkpat(Ppat_construct(mkrhs $1 1, Some $2, false)) } + { mkpat(Ppat_construct(mkrhs $1 1, Some $2)) } | name_tag pattern %prec prec_constr_appl { mkpat(Ppat_variant($1, Some $2)) } | pattern COLONCOLON pattern @@ -1348,7 +1348,7 @@ simple_pattern: | signed_constant DOTDOT signed_constant { mkpat(Ppat_interval ($1, $3)) } | constr_longident - { mkpat(Ppat_construct(mkrhs $1 1, None, false)) } + { mkpat(Ppat_construct(mkrhs $1 1, None)) } | name_tag { mkpat(Ppat_variant($1, None)) } | SHARP type_longident diff --git a/parsing/parsetree.mli b/parsing/parsetree.mli index d515919442..6fde14dfbc 100644 --- a/parsing/parsetree.mli +++ b/parsing/parsetree.mli @@ -145,23 +145,11 @@ and pattern_desc = but rejected by the type-checker. *) | Ppat_tuple of pattern list (* (P1, ..., Pn) (n >= 2) *) - | Ppat_construct of Longident.t loc * pattern option * bool - (* C (None, false) - C P (Some P, false) - - Constructors with multiple arguments are represented - by storing a Ppat_tuple in P. - - bool = true is never created by the standard parser. - It can be used when P is a Ppat_tuple to inform the - type-checker that the length of that tuple corresponds - to the number of parameters for that constructor (otherwise - this is inferred from the definition of the constructor). - This can be useful with a different concrete syntax - which distinguishes n-ary constructors from constructors - with a tuple argument in patterns. + | Ppat_construct of Longident.t loc * pattern option + (* C None + C P Some P + C (P1, ..., Pn) Some (Ppat_tuple [P1; ...; Pn]) *) - | Ppat_variant of label * pattern option (* `A (None) `A P (Some P) @@ -231,12 +219,10 @@ and expression_desc = (* try E0 with P1 -> E1 | ... | Pn -> En *) | Pexp_tuple of expression list (* (E1, ..., En) (n >= 2) *) - | Pexp_construct of Longident.t loc * expression option * bool - (* C (None, false) - C E (Some E, false) - - Constructors with multiple arguments are represented - by storing a Pexp_tuple in E. + | Pexp_construct of Longident.t loc * expression option + (* C None + C E Some E + C (E1, ..., En) Some (Pexp_tuple[E1;...;En]) *) | Pexp_variant of label * expression option (* `A (None) diff --git a/parsing/pprintast.ml b/parsing/pprintast.ml index b65f79b1c2..653347ef78 100644 --- a/parsing/pprintast.ml +++ b/parsing/pprintast.ml @@ -55,7 +55,7 @@ let is_predef_option = function | _ -> false let is_unit = function - | {pexp_desc=Pexp_construct ( {txt= Lident "()"; _},_,_); + | {pexp_desc=Pexp_construct ( {txt= Lident "()"; _},_); pexp_attributes = [] } -> true | _ -> false @@ -82,20 +82,20 @@ type construct = let view_expr x = match x.pexp_desc with - | Pexp_construct ( {txt= Lident "()"; _},_,_) -> `tuple - | Pexp_construct ( {txt= Lident "[]";_},_,_) -> `nil - | Pexp_construct ( {txt= Lident"::";_},Some _,_) -> + | Pexp_construct ( {txt= Lident "()"; _},_) -> `tuple + | Pexp_construct ( {txt= Lident "[]";_},_) -> `nil + | Pexp_construct ( {txt= Lident"::";_},Some _) -> let rec loop exp acc = match exp with - | {pexp_desc=Pexp_construct ({txt=Lident "[]";_},_,_);_} -> (List.rev acc,true) + | {pexp_desc=Pexp_construct ({txt=Lident "[]";_},_);_} -> (List.rev acc,true) | {pexp_desc= - Pexp_construct ({txt=Lident "::";_},Some ({pexp_desc= Pexp_tuple([e1;e2]);_}),_);_} -> + Pexp_construct ({txt=Lident "::";_},Some ({pexp_desc= Pexp_tuple([e1;e2]);_}));_} -> loop e2 (e1::acc) | e -> (List.rev (e::acc),false) in let (ls,b) = loop x [] in if b then `list ls else `cons ls - | Pexp_construct (x,None,_) -> `simple (x.txt) + | Pexp_construct (x,None) -> `simple (x.txt) | _ -> `normal let is_simple_construct :construct -> bool = function @@ -335,14 +335,14 @@ class printer ()= object(self:'self) | {ppat_desc = Ppat_construct ({ txt = Lident("::") ;_}, - Some ({ppat_desc = Ppat_tuple([pat1; pat2]);_}), - _);_} -> + Some ({ppat_desc = Ppat_tuple([pat1; pat2]);_})); _} + -> pp f "%a::%a" self#simple_pattern pat1 pattern_list_helper pat2 (*RA*) | p -> self#pattern1 f p in match x.ppat_desc with | Ppat_variant (l, Some p) -> pp f "@[<2>`%s@;%a@]" l self#pattern1 p (*RA*) - | Ppat_construct (({txt=Lident("()"|"[]");_}), _, _) -> self#simple_pattern f x - | Ppat_construct (({txt;_} as li), po, _) -> (* FIXME The third field always false *) + | Ppat_construct (({txt=Lident("()"|"[]");_}), _) -> self#simple_pattern f x + | Ppat_construct (({txt;_} as li), po) -> (* FIXME The third field always false *) if txt = Lident "::" then pp f "%a" pattern_list_helper x else @@ -353,7 +353,7 @@ class printer ()= object(self:'self) | _ -> self#simple_pattern f x method simple_pattern (f:Format.formatter) (x:pattern) :unit = match x.ppat_desc with - | Ppat_construct (({txt=Lident ("()"|"[]" as x);_}), _, _) -> pp f "%s" x + | Ppat_construct (({txt=Lident ("()"|"[]" as x);_}), _) -> pp f "%s" x | Ppat_any -> pp f "_"; | Ppat_var ({txt = txt;_}) -> if (is_infix (fixity_of_string txt)) || List.mem txt.[0] prefix_symbols then @@ -571,7 +571,7 @@ class printer ()= object(self:'self) (*reset here only because [function,match,try,sequence] are lower priority*) end (e,l)) - | Pexp_construct (li, Some eo, _) + | Pexp_construct (li, Some eo) when not (is_simple_construct (view_expr x))-> (* Not efficient FIXME*) (match view_expr x with | `cons ls -> self#list self#simple_expr f ls ~sep:"@;::@;" diff --git a/parsing/printast.ml b/parsing/printast.ml index fc00e3043e..7da500c1b8 100644 --- a/parsing/printast.ml +++ b/parsing/printast.ml @@ -198,10 +198,9 @@ and pattern i ppf x = | Ppat_tuple (l) -> line i ppf "Ppat_tuple\n"; list i pattern ppf l; - | Ppat_construct (li, po, b) -> + | Ppat_construct (li, po) -> line i ppf "Ppat_construct %a\n" fmt_longident_loc li; option i pattern ppf po; - bool i ppf b; | Ppat_variant (l, po) -> line i ppf "Ppat_variant \"%s\"\n" l; option i pattern ppf po; @@ -261,10 +260,9 @@ and expression i ppf x = | Pexp_tuple (l) -> line i ppf "Pexp_tuple\n"; list i expression ppf l; - | Pexp_construct (li, eo, b) -> + | Pexp_construct (li, eo) -> line i ppf "Pexp_construct %a\n" fmt_longident_loc li; option i expression ppf eo; - bool i ppf b; | Pexp_variant (l, eo) -> line i ppf "Pexp_variant \"%s\"\n" l; option i expression ppf eo; |
