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

Parsing of path-references to pages and modules #1142

Merged
merged 11 commits into from
Jul 10, 2024

Conversation

Julow
Copy link
Collaborator

@Julow Julow commented Jun 7, 2024

Add the parsing of references to pages and modules containing a slash: {!./foo}, {!/foo}, {!//foo}.
These are not resolved yet.

@panglesd
Copy link
Collaborator

panglesd commented Jun 7, 2024

Are {!foo/bar} also parsed?

@Julow
Copy link
Collaborator Author

Julow commented Jun 7, 2024

Yes! As well as many variations like {!foo/page-bar} and {!/foo/bar.label}.

src/model/paths_types.ml Outdated Show resolved Hide resolved
src/model/paths_types.ml Outdated Show resolved Hide resolved
@Julow Julow force-pushed the path_references branch 2 times, most recently from 39956f2 to dd68498 Compare July 9, 2024 09:54
@Julow
Copy link
Collaborator Author

Julow commented Jul 9, 2024

Rebased and ready for an other review. #1150 is rebased on top.

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.

Overall looks very good! Left a first round of comments. Not much left to review.

src/model/paths_types.ml Outdated Show resolved Hide resolved
test/xref2/refs/refs.md Outdated Show resolved Hide resolved
src/model/reference.ml Show resolved Hide resolved
src/model/reference.ml Outdated Show resolved Hide resolved
| `End_in_slash, [] ->
(* {!identifier'/identifier} *)
(`TRelativePath, next_token.identifier :: components)
| `End_in_slash, next_token' :: tokens' ->
Copy link
Collaborator

@panglesd panglesd Jul 10, 2024

Choose a reason for hiding this comment

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

Should we check here that next_token.identifier is not "", and raise an error otherwise? If not, it allows references such as {!////////////////////////////////}.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch! Added the error.

@@ -620,6 +629,7 @@ module rec Reference : sig
[ `Resolved of Resolved_reference.field_parent
| `Root of string * tag_parent
| `Dot of label_parent * string
| `Module_path of hierarchy
Copy link
Collaborator

Choose a reason for hiding this comment

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

Module path can only be of the form: /libname/. For example: {!/libname/module-M.type-t}.

I think that could be reflected in the type?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess that #1142 (comment) answers no to the question!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this can happen with {!/M.type-t}. I'm not in favor of enforcing that in the parser. The resolver has to match on the path to be able to lookup libname, that's where the reference should be rejected.

src/model/reference.ml Outdated Show resolved Hide resolved
src/model/reference.ml Outdated Show resolved Hide resolved
src/model/reference.ml Outdated Show resolved Hide resolved
src/model/reference.ml Outdated Show resolved Hide resolved
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.

I finished reviewing, and have no more comments than the one already made!

Once they are resolved, it's ready to be merged.

This add 3 new kinds of references to pages and units:

- Relative paths: {!./foo} {!foo/bar}
- Absolute paths: {!/foo}
- Paths relative to the current package: {!//foo}

The last component of the path can point to a page or a root module. It
can be prefixed: {!foo/page-bar} {!foo/module-Bar}.

Paths can be on the right of a dot: {!foo/bar.label}.

The new reference constructors are plumbed through xref2 but unimplemented.
The Page_path constructor cannot represent these references
differerently:

    {!foo/module-Bar}
    {!foo/page-Bar}
    {!foo/Bar}

The constructors Module_path and Any_path are added in the different
reference types and pipeped through to Ref_tools.

This also fixes the parsing of paths as label parents and add better
error messages when the last component of a path isn't as expected.
'Path' was an overloaded term.
Also improve the path parsing to be more readable.
@panglesd panglesd merged commit 7a4468d into ocaml:master Jul 10, 2024
12 checks passed
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.

2 participants