diff options
author | Jérémie Dimino <jeremie@dimino.org> | 2011-12-20 17:40:18 +0000 |
---|---|---|
committer | Jérémie Dimino <jeremie@dimino.org> | 2011-12-20 17:40:18 +0000 |
commit | dfcbd7fc56f0749ebe8bfcccac3323dab1bc5d8e (patch) | |
tree | aabe128f8a96f82b5b8b1232433d8bcf9f6c9bde | |
parent | a69f9be8c5fd60296550ffb23de9a2e9d4c372e4 (diff) | |
download | ocaml-dfcbd7fc56f0749ebe8bfcccac3323dab1bc5d8e.tar.gz |
Avoid creating malformed location in Camlp4 when no token is consumed
When no token was consumed, Camlp4 created a location with start-pos > stop-pos.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@11902 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r-- | camlp4/Camlp4/Struct/Grammar/Parser.ml | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/camlp4/Camlp4/Struct/Grammar/Parser.ml b/camlp4/Camlp4/Struct/Grammar/Parser.ml index d97eb28755..2c639b2a1c 100644 --- a/camlp4/Camlp4/Struct/Grammar/Parser.ml +++ b/camlp4/Camlp4/Struct/Grammar/Parser.ml @@ -34,9 +34,17 @@ module Make (Structure : Structure.S) = struct value drop_prev_loc = Tools.drop_prev_loc; value add_loc bp parse_fun strm = + let count1 = Stream.count strm in let x = parse_fun strm in - let ep = loc_ep strm in - let loc = Loc.merge bp ep in + let count2 = Stream.count strm in + let loc = + if count1 < count2 then + let ep = loc_ep strm in + Loc.merge bp ep + else + (* If nothing has been consumed, create a 0-length location. *) + Loc.join bp + in (x, loc); value stream_peek_nth strm n = |