diff options
-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 = |