summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Pouillard <np@nicolaspouillard.fr>2010-05-11 15:18:42 +0000
committerNicolas Pouillard <np@nicolaspouillard.fr>2010-05-11 15:18:42 +0000
commitadd4cd96929b7e4ddbc818f74371284c90709440 (patch)
treeb94033d2079548f9c4396685035153f7c26f2564
parentc786bb358f85274871ad72fb88d9ba7b320ac842 (diff)
downloadocaml-add4cd96929b7e4ddbc818f74371284c90709440.tar.gz
camlp4: record punning in expressions as well
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10391 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--camlp4/Camlp4Parsers/Camlp4OCamlParser.ml10
-rw-r--r--camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml17
2 files changed, 16 insertions, 11 deletions
diff --git a/camlp4/Camlp4Parsers/Camlp4OCamlParser.ml b/camlp4/Camlp4Parsers/Camlp4OCamlParser.ml
index fa550bacf4..d9db7b2964 100644
--- a/camlp4/Camlp4Parsers/Camlp4OCamlParser.ml
+++ b/camlp4/Camlp4Parsers/Camlp4OCamlParser.ml
@@ -115,13 +115,15 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
| _ -> 1 ])
;
- value test_label_eq =
- Gram.Entry.of_parser "test_label_eq"
+ value test_label_expr_list =
+ Gram.Entry.of_parser "test_label_expr_list"
(test 1 where rec test lev strm =
match stream_peek_nth lev strm with
[ Some (UIDENT _ | LIDENT _ | KEYWORD ".") ->
test (lev + 1) strm
- | Some (KEYWORD "=") -> ()
+ | Some (KEYWORD ("="|";"|"}")) ->
+ (* ";" and "}" occur due to record punning *)
+ ()
| _ -> raise Stream.Failure ])
;
@@ -335,7 +337,7 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
expr: LEVEL "simple" (* LEFTA *)
[ [ "false" -> <:expr< False >>
| "true" -> <:expr< True >>
- | "{"; test_label_eq; lel = label_expr_list; "}" ->
+ | "{"; test_label_expr_list; lel = label_expr_list; "}" ->
<:expr< { $lel$ } >>
| "{"; e = expr LEVEL "."; "with"; lel = label_expr_list; "}" ->
<:expr< { ($e$) with $lel$ } >>
diff --git a/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml b/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml
index fb7241a602..fbd16aae3c 100644
--- a/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml
+++ b/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml
@@ -255,6 +255,12 @@ Very old (no more supported) syntax:\n\
| e -> e ]
;
+ value rec lid_of_ident =
+ fun
+ [ <:ident< $_$ . $i$ >> -> lid_of_ident i
+ | <:ident< $lid:lid$ >> -> lid
+ | _ -> assert False ];
+
value module_type_app mt1 mt2 =
match (mt1, mt2) with
[ (<:module_type@_loc< $id:i1$ >>, <:module_type< $id:i2$ >>) ->
@@ -819,7 +825,9 @@ Very old (no more supported) syntax:\n\
<:rec_binding< $anti:mk_anti ~c:"ident" n s$ = $e$ >>
| `ANTIQUOT ("list" as n) s ->
<:rec_binding< $anti:mk_anti ~c:"rec_binding" n s$ >>
- | i = label_longident; e = fun_binding -> <:rec_binding< $i$ = $e$ >> ] ]
+ | i = label_longident; e = fun_binding -> <:rec_binding< $i$ = $e$ >>
+ | i = label_longident ->
+ <:rec_binding< $i$ = $lid:lid_of_ident i$ >> ] ]
;
fun_def:
[ [ p = labeled_ipatt; (w, e) = fun_def_cont ->
@@ -921,12 +929,7 @@ Very old (no more supported) syntax:\n\
| `ANTIQUOT ("list" as n) s ->
<:patt< $anti:mk_anti ~c:"patt;" n s$ >>
| i = label_longident; "="; p = patt -> <:patt< $i$ = $p$ >>
- | i = label_longident ->
- let rec desugar_punning = fun
- [ <:ident< $_$ . $i$ >> -> desugar_punning i
- | <:ident< $lid:lid$ >> -> <:patt< $i$ = $lid:lid$ >>
- | _ -> assert False ]
- in desugar_punning i
+ | i = label_longident -> <:patt< $i$ = $lid:lid_of_ident i$ >>
] ]
;
ipatt: