summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Doligez <damien.doligez-inria.fr>2010-08-16 14:14:10 +0000
committerDamien Doligez <damien.doligez-inria.fr>2010-08-16 14:14:10 +0000
commit96456b82e82a548bf2e73de472c4fa2e402bd6b6 (patch)
tree3438a762122a2ad399e69c78084c5d96a60af424
parente98c4c3f566e7d4a603d1a2a21948cd2ce79a696 (diff)
downloadocaml-96456b82e82a548bf2e73de472c4fa2e402bd6b6.tar.gz
another fix for PR#5090; this one seems to work correctly
git-svn-id: http://caml.inria.fr/svn/ocaml/version/3.12@10645 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--VERSION2
-rw-r--r--camlp4/Camlp4/Struct/Grammar/Structure.ml2
-rw-r--r--camlp4/Camlp4/Struct/Grammar/Tools.ml34
-rw-r--r--camlp4/Camlp4Parsers/Camlp4OCamlParser.ml8
-rw-r--r--camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml6
-rw-r--r--camlp4/Camlp4Top/Top.ml12
6 files changed, 36 insertions, 28 deletions
diff --git a/VERSION b/VERSION
index d0c463f732..5ac4977b58 100644
--- a/VERSION
+++ b/VERSION
@@ -1,4 +1,4 @@
-3.12.1+dev1 (2010-08-13)
+3.12.1+dev2 (2010-08-13)
# The version string is the first line of this file.
# It must be in the format described in stdlib/sys.mli
diff --git a/camlp4/Camlp4/Struct/Grammar/Structure.ml b/camlp4/Camlp4/Struct/Grammar/Structure.ml
index c2afdd6395..67b99feb99 100644
--- a/camlp4/Camlp4/Struct/Grammar/Structure.ml
+++ b/camlp4/Camlp4/Struct/Grammar/Structure.ml
@@ -36,6 +36,7 @@ module type S = sig
type token_info = { prev_loc : Loc.t
; cur_loc : Loc.t
+ ; prev_loc_only : bool
};
type token_stream = Stream.t (Token.t * token_info);
@@ -126,6 +127,7 @@ module Make (Lexer : Sig.Lexer) = struct
type token_info = { prev_loc : Loc.t
; cur_loc : Loc.t
+ ; prev_loc_only : bool
};
type token_stream = Stream.t (Token.t * token_info);
diff --git a/camlp4/Camlp4/Struct/Grammar/Tools.ml b/camlp4/Camlp4/Struct/Grammar/Tools.ml
index 26489d3744..31824eb285 100644
--- a/camlp4/Camlp4/Struct/Grammar/Tools.ml
+++ b/camlp4/Camlp4/Struct/Grammar/Tools.ml
@@ -16,6 +16,10 @@
* - Daniel de Rauglaudre: initial version
* - Nicolas Pouillard: refactoring
*)
+
+(* PR#5090: don't do lookahead on get_prev_loc. *)
+value get_prev_loc_only = ref False;
+
module Make (Structure : Structure.S) = struct
open Structure;
@@ -29,10 +33,17 @@ module Make (Structure : Structure.S) = struct
value keep_prev_loc strm =
match Stream.peek strm with
[ None -> [: :]
- | Some (_,init_loc) ->
- let rec go prev_loc = parser
- [ [: `(tok,cur_loc); strm :] -> [: `(tok,{prev_loc;cur_loc}); go cur_loc strm :]
- | [: :] -> [: :] ]
+ | Some (tok0,init_loc) ->
+ let rec go prev_loc strm1 =
+ if get_prev_loc_only.val then
+ [: `(tok0, {prev_loc; cur_loc = prev_loc; prev_loc_only = True});
+ go prev_loc strm1 :]
+ else
+ match strm1 with parser
+ [ [: `(tok,cur_loc); strm :] ->
+ [: `(tok, {prev_loc; cur_loc; prev_loc_only = False});
+ go cur_loc strm :]
+ | [: :] -> [: :] ]
in go init_loc strm ];
value drop_prev_loc strm = stream_map (fun (tok,r) -> (tok,r.cur_loc)) strm;
@@ -43,9 +54,18 @@ module Make (Structure : Structure.S) = struct
| None -> Loc.ghost ];
value get_prev_loc strm =
- match Stream.peek strm with
- [ Some (_,r) -> r.prev_loc
- | None -> Loc.ghost ];
+ do {
+ get_prev_loc_only.val := True;
+ let result = match Stream.peek strm with
+ [ Some (_, {prev_loc; prev_loc_only = True}) ->
+ do {Stream.junk strm; prev_loc}
+ | Some (_, {prev_loc; prev_loc_only = False}) -> prev_loc
+ | None -> Loc.ghost ]
+ in do {
+ get_prev_loc_only.val := False;
+ result
+ }
+ };
value is_level_labelled n lev =
match lev.lname with
diff --git a/camlp4/Camlp4Parsers/Camlp4OCamlParser.ml b/camlp4/Camlp4Parsers/Camlp4OCamlParser.ml
index 1bfdefc277..c7a510a52a 100644
--- a/camlp4/Camlp4Parsers/Camlp4OCamlParser.ml
+++ b/camlp4/Camlp4Parsers/Camlp4OCamlParser.ml
@@ -616,13 +616,11 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
| `UIDENT s -> s
] ]
;
- (* Fix for PR#5090: dummy tokens introduced by the toplevel's lexer
- to compensate for the lookahead done by the location-handling code *)
top_phrase:
- [ [ OPT "%%dummy"; "#"; n = a_LIDENT; dp = opt_expr; ";;" ->
+ [ [ "#"; n = a_LIDENT; dp = opt_expr; ";;" ->
Some <:str_item< # $n$ $dp$ >>
- | OPT "%%dummy"; l = LIST1 str_item; ";;" -> Some (Ast.stSem_of_list l)
- | OPT "%%dummy"; `EOI -> None
+ | l = LIST1 str_item; ";;" -> Some (Ast.stSem_of_list l)
+ | `EOI -> None
] ]
;
END;
diff --git a/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml b/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml
index f91e6ab37b..11fd025041 100644
--- a/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml
+++ b/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml
@@ -1614,11 +1614,9 @@ Very old (no more supported) syntax:\n\
| l = LIST0 [ st = str_item; semi -> st ] -> Ast.stSem_of_list l
] ]
;
- (* Fix for PR#5090: dummy tokens introduced by the toplevel's lexer
- to compensate for the lookahead done by the location-handling code *)
top_phrase:
- [ [ OPT "%% dummy %%"; ph = phrase -> Some ph
- | OPT "%% dummy %%"; `EOI -> None
+ [ [ ph = phrase -> Some ph
+ | `EOI -> None
] ]
;
use_file:
diff --git a/camlp4/Camlp4Top/Top.ml b/camlp4/Camlp4Top/Top.ml
index 66b3022aba..dcd3aa4607 100644
--- a/camlp4/Camlp4Top/Top.ml
+++ b/camlp4/Camlp4Top/Top.ml
@@ -62,15 +62,6 @@ end;
value lookup x xs = try Some (List.assq x xs) with [ Not_found -> None ];
-(* Fix for PR#5090: dummy tokens introduced by the toplevel's lexer
- to compensate for the lookahead done by the location-handling code *)
-value rec add_dummies x =
- match x with parser
- [ [: `(KEYWORD x, l); strm :] ->
- [: `(KEYWORD x, l); `(KEYWORD "%% dummy %%", l); add_dummies strm :]
- | [: `x; strm :] -> [: `x; add_dummies strm :] ]
-;
-
value wrap parse_fun =
let token_streams = ref [] in
let cleanup lb =
@@ -110,8 +101,7 @@ value wrap parse_fun =
} ];
value toplevel_phrase token_stream =
- match Gram.parse_tokens_after_filter Syntax.top_phrase
- (add_dummies token_stream) with
+ match Gram.parse_tokens_after_filter Syntax.top_phrase token_stream with
[ Some str_item ->
let str_item =
AstFilters.fold_topphrase_filters (fun t filter -> filter t) str_item