Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/code_matcher.ml
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,23 @@ struct
mismatch_handler loc [ x ]);
match_loop ~end_pos ~mismatch_handler ~expected ~source

(* [source] is supposed to be the list of items that follow the [@@deriving_inline]
item in the source file. That is not the case when the [@@deriving_inline] item is

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds a little bit odd, I think adding the ppx_template example here would make a bit more sense as otherwise, ppx generated deriving_inline nodes sounds a bit crazy and something we don't necessarily want to support.

itself part of code generated by another ppx: the generator is free to insert items
of its own after it.

Such items have no corresponding source text; their location is inherited from the
node they were generated from, and hence starts at or before the start of the
[@@deriving_inline] item. Were we to keep them, we would end up replacing the
source text of the [@@deriving_inline] item itself with the generated code. *)
let drop_items_without_source_text ~pos items =
List.filter items ~f:(fun item ->
Location.compare_pos (M.get_loc item).loc_start pos >= 0)

let do_match ~pos ~expected ~mismatch_handler source =
let open Result in
extract_prefix ~pos source >>| fun (source, end_pos) ->
let source = drop_items_without_source_text ~pos source in
match_loop ~end_pos ~mismatch_handler ~expected ~source
end

Expand Down
Loading