ocaml-ppx / ppxlib

Base library and tools for ppx rewriters
MIT License
244 stars 94 forks source link

Context_free.special_function: fix the parsing of indexing operators #494

Closed Octachron closed 1 month ago

Octachron commented 1 month ago

Currently, indexing operators are misparsed by ppxlib in Context_free.special_function because the Longident parsing code stops on the first closing parenthesis in (.!(;..)) and fails with an invalid argument because this first closing parenthesis is not at the end of the identifier.

This PR fixes this issue by finding the first pair of matched parentheses and add a test for the indexing operator cases. Along the way, I added some more context on the Invalid_argument error.

Note that I am also tempted to propose a version of special_function that doesn't parse its argument and takes a longident directly to avoid this recurring issue.

Octachron commented 1 month ago

I have added a change entry added, with a off-by-one fix and some new tests for unbalanced parentheses (e.g "(").