sedlex
sedlex copied to clipboard
Nested matches using the same lexbuf produce misleading error
When nesting a match%sedlex inside another one the error message is pretty confusing:
let nested str =
let buf = Sedlexing.Latin1.from_string str in
match%sedlex buf with
| "0" ->
print_endline "it's a 0!"
| "foo" ->
begin
match %sedlex buf with
| "bar" -> print_endline "it's a generic example"
| _ -> print_endline "bad foo"
end
| _ ->
print_endline "invalid input"
This produces a generic error message
File "src_test/sedlex_test.ml", line 8, characters 16-22:
Uninterpreted extension 'sedlex'.
The problem seems to be reusing buf. If a different variable is used it compiles and works:
let nested str =
let buf = Sedlexing.Latin1.from_string str in
match%sedlex buf with
| "0" ->
print_endline "it's a 0!"
| "foo" ->
begin
let buf2 = buf in
match %sedlex buf2 with
| "bar" -> print_endline "it's a generic example"
| _ -> print_endline "bad foo"
end
| _ ->
print_endline "invalid input"
The problem is actually that ppx_sedlex.ml applies super#expr instead of this#expr to immediate sub-expressions (actions).
@toots, can you close this one. automatic closing didn't work