Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for parsing longident's with . #111

Merged
merged 4 commits into from
Jan 31, 2024

Conversation

rgrinberg
Copy link
Collaborator

There are some identifiers that have the . character. We test cases with +.
and *.

It seems like the +. isn't handled correctly when there's no module prefixing.

@rgrinberg rgrinberg requested a review from a user December 22, 2019 11:15
@rgrinberg rgrinberg requested a review from xclerc as a code owner December 22, 2019 11:15
@rgrinberg rgrinberg requested a review from NathanReb December 22, 2019 11:15
@rgrinberg
Copy link
Collaborator Author

@gasche, i'm a bit curious, why is the implementation of Longident.parse in compiler-libs not complete? I'm being bit by a bug in it in the context of merlin as well.

@gasche
Copy link

gasche commented Dec 22, 2019

parse is a misnomer for this function that is used in very restricted ways inside the compiler codebase, only to parse paths of the form Foo.Bar.baz. It was never designed for external usage.

The robust code to parse longidents is in the parser, but it separates in many smaller categories (mod_longident similarly does not allow module applications, mod_ext_longident does, and both of those only parse module identifiers (the last component is uppercased) and get turned into various non-module-identifiers (for values, types, etc.)) that are finer grained than the type Longident.t represents. We could propose to expose this parser logic, but:

  • I don't know what would be a good API for it. (We could expose the various kind of longidents, one for each namespace: modules, types and module types, values, classes and class types.)
  • We cannot expose this from Longident.parse, because it would create a cyclic dependency between the parser and Longident. So users would have to access Parse.*_longident instead, and build a lexing buffer themselves.

Finally, we could also try to use a hand-written parser for Longident -- for example the one I proposed in #98 (comment) -- but it seems weird to duplicate logic that we already have someplace else, with inferior technology, for something we don't need inside the compiler codebase.

Copy link
Collaborator

@NathanReb NathanReb left a comment

Choose a reason for hiding this comment

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

There is something weird about the way the exceptions are reported in the tests.

It seems that 4.08 reports them differently from 4.07 in the CI but when I try to reproduce that locally, I get the same formatting (no parens, ends with a .) with both 4.07 and 4.08.

Besides that it looks good!

@gasche I'm happy to import your suggested implementation in ppxlib when I get some time to work on that. In the meantime, if you wish to open a PR and fix the tiny bugs it contains so that it passes the existing tests that would be wonderful.

There are some identifiers that have the `.` character. We test cases
with +. and *.

Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
Copy link
Collaborator

@panglesd panglesd left a comment

Choose a reason for hiding this comment

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

About the "add tests" part: Let's merge, it's good to have more tests!

About the "fix a longident bug about unparenthesized operators": that looks good and fixing a bug. I don't know enough the possible syntax of longidents to be confident there aren't other bugs though!

src/longident.ml Outdated Show resolved Hide resolved
test/base/test.ml Outdated Show resolved Hide resolved
@NathanReb NathanReb force-pushed the longident-bug branch 2 times, most recently from a2013ef to 4389da7 Compare January 31, 2024 10:50
src/longident.ml Outdated Show resolved Hide resolved
Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
@NathanReb NathanReb merged commit 9b55562 into ocaml-ppx:main Jan 31, 2024
5 checks passed
NathanReb added a commit to NathanReb/opam-repository that referenced this pull request Feb 1, 2024
CHANGES:

- Fix `Longident.parse` so it properly handles unparenthesized dotted operators
  such as `+.` or `*.`. (ocaml-ppx/ppxlib#111, @rgrinberg, @NathanReb)

- raising an exception does no longer cancel the whole context free phase(ocaml-ppx/ppxlib#453, @Burnleydev1)

- Sort embedded errors that are appended to the AST by location so the compiler
  reports the one closer to the beginning of the file first. (ocaml-ppx/ppxlib#463, @NathanReb)

- Update `Attribute.get` to ignore `loc_ghost`. (ocaml-ppx/ppxlib#460, @ceastlund)

- Add API to manipulate attributes that are used as flags (ocaml-ppx/ppxlib#408, @dianaoigo)

- Update changelog to use ISO 8061 date format: YYYY-MM-DD. (ocaml-ppx/ppxlib#445, @ceastlund)

- Replace `Caml` with `Stdlib`. (ocaml-ppx/ppxlib#427, @ceastlund)

- When a transformation raises, the last valid AST is used as input to the upcoming
  transformations. All such errors are collected and appended as
  extension nodes to the final AST (ocaml-ppx/ppxlib#447, @Burnleydev1)

- Fix a small mistake in the man pages: Embededding errors is done by default with
  `-as-pp`, not with `-dump-ast` (ocaml-ppx/ppxlib#464, @pitag-ha)

- Set appropriate binary mode when writing to `stdout` especially for Windows
  compatibility. (ocaml-ppx/ppxlib#466, @jonahbeckford)
NathanReb added a commit to NathanReb/opam-repository that referenced this pull request Feb 5, 2024
CHANGES:

- Add an optional `embed_errors` argument to `Context_free.map_top_down` that
  controls how to deal with exceptions thrown by context-free rules.
  (ocaml-ppx/ppxlib#468, @NathanReb)

- Fix `Longident.parse` so it properly handles unparenthesized dotted operators
  such as `+.` or `*.`. (ocaml-ppx/ppxlib#111, @rgrinberg, @NathanReb)

- raising an exception does no longer cancel the whole context free phase(ocaml-ppx/ppxlib#453, @Burnleydev1)

- Sort embedded errors that are appended to the AST by location so the compiler
  reports the one closer to the beginning of the file first. (ocaml-ppx/ppxlib#463, @NathanReb)

- Update `Attribute.get` to ignore `loc_ghost`. (ocaml-ppx/ppxlib#460, @ceastlund)

- Add API to manipulate attributes that are used as flags (ocaml-ppx/ppxlib#408, @dianaoigo)

- Update changelog to use ISO 8061 date format: YYYY-MM-DD. (ocaml-ppx/ppxlib#445, @ceastlund)

- Replace `Caml` with `Stdlib`. (ocaml-ppx/ppxlib#427, @ceastlund)

- When a transformation raises, the last valid AST is used as input to the upcoming
  transformations. All such errors are collected and appended as
  extension nodes to the final AST (ocaml-ppx/ppxlib#447, @Burnleydev1)

- Fix a small mistake in the man pages: Embededding errors is done by default with
  `-as-pp`, not with `-dump-ast` (ocaml-ppx/ppxlib#464, @pitag-ha)

- Set appropriate binary mode when writing to `stdout` especially for Windows
  compatibility. (ocaml-ppx/ppxlib#466, @jonahbeckford)
nberth pushed a commit to nberth/opam-repository that referenced this pull request Jun 18, 2024
CHANGES:

- Add an optional `embed_errors` argument to `Context_free.map_top_down` that
  controls how to deal with exceptions thrown by context-free rules.
  (ocaml-ppx/ppxlib#468, @NathanReb)

- Fix `Longident.parse` so it properly handles unparenthesized dotted operators
  such as `+.` or `*.`. (ocaml-ppx/ppxlib#111, @rgrinberg, @NathanReb)

- raising an exception does no longer cancel the whole context free phase(ocaml-ppx/ppxlib#453, @Burnleydev1)

- Sort embedded errors that are appended to the AST by location so the compiler
  reports the one closer to the beginning of the file first. (ocaml-ppx/ppxlib#463, @NathanReb)

- Update `Attribute.get` to ignore `loc_ghost`. (ocaml-ppx/ppxlib#460, @ceastlund)

- Add API to manipulate attributes that are used as flags (ocaml-ppx/ppxlib#408, @dianaoigo)

- Update changelog to use ISO 8061 date format: YYYY-MM-DD. (ocaml-ppx/ppxlib#445, @ceastlund)

- Replace `Caml` with `Stdlib`. (ocaml-ppx/ppxlib#427, @ceastlund)

- When a transformation raises, the last valid AST is used as input to the upcoming
  transformations. All such errors are collected and appended as
  extension nodes to the final AST (ocaml-ppx/ppxlib#447, @Burnleydev1)

- Fix a small mistake in the man pages: Embededding errors is done by default with
  `-as-pp`, not with `-dump-ast` (ocaml-ppx/ppxlib#464, @pitag-ha)

- Set appropriate binary mode when writing to `stdout` especially for Windows
  compatibility. (ocaml-ppx/ppxlib#466, @jonahbeckford)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants