-
Notifications
You must be signed in to change notification settings - Fork 412
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
test: Sibling modules should be accessible from qualified parsers #11118
Open
brendanzab
wants to merge
1
commit into
ocaml:main
Choose a base branch
from
brendanzab:test_menhir__qualified_parsers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
test/blackbox-tests/test-cases/menhir/include-subdirs-siblings.t/dune
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(include_subdirs qualified) | ||
|
||
(executable | ||
(name foo)) |
2 changes: 2 additions & 0 deletions
2
test/blackbox-tests/test-cases/menhir/include-subdirs-siblings.t/dune-project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
(lang dune 3.14) | ||
(using menhir 2.1) |
2 changes: 2 additions & 0 deletions
2
test/blackbox-tests/test-cases/menhir/include-subdirs-siblings.t/foo.ml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
let () = | ||
assert (Lang.Parser.expr (fun _ -> Lang.Parser.EOF) (Lexing.from_string "") = Lang.Ast.Unit) |
2 changes: 2 additions & 0 deletions
2
test/blackbox-tests/test-cases/menhir/include-subdirs-siblings.t/lang/ast.ml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
type expr = | ||
| Unit |
2 changes: 2 additions & 0 deletions
2
test/blackbox-tests/test-cases/menhir/include-subdirs-siblings.t/lang/dune
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
(menhir | ||
(modules parser)) | ||
8 changes: 8 additions & 0 deletions
8
test/blackbox-tests/test-cases/menhir/include-subdirs-siblings.t/lang/parser.mly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
%token EOF | ||
|
||
%start <Ast.expr> expr | ||
|
||
%% | ||
|
||
expr: | ||
| EOF { Ast.Unit } |
6 changes: 6 additions & 0 deletions
6
test/blackbox-tests/test-cases/menhir/include-subdirs-siblings.t/run.t
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Menhir parsers in qualified subdirectories should be able to refer to sibling modules: | ||
|
||
$ dune build | ||
File "lang/parser.mly", line 3, characters 8-16: | ||
Error: Unbound module Ast | ||
[1] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I see the error message is correct, as this makes the
Ast
module invisible to Menhir.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, why is that? I had assumed it would work similarly to other qualified modules - where you could mention sibling modules from within a subdirectory? See the directory tree from #11119:
If this is intentional is there a workaround for this, or is this pattern supposed to be impossible with Menhir?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve also tried the following from the root
dune
file:Which resulted in the same error.
I also tried:
Which resulted in:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you prefer it if I used an example that used one of the approaches above, or are those also intended behavior?
I think the main reason I used a
dune
file in the subdirectory was because I had no other way of referencing the.mly
from the root directory via themenhir
stanza. And I assume using thesubdir
stanza is isomorphic to the approach I am currently using (but I could be mistaken on that).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve also tried variations of
(modules Lang.Parser)
,(modules Lang__Parser)
,(modules dune__exe__Lang__parser)
to no avail in themenhir
stanza.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Leonidas-from-XIV If it helps, it seems #8987 was merged, which seems like a case where the
.mly
is the “group interface” of the subdirectory, which references a sibling module:https://github.com/ocaml/dune/pull/8987/files
In contrast the pattern I am after is:
Not sure if that test is enough to covers this use-case case as well, as in this case the
parser.mly
is not the group interface? But it’d be really cool if that issue was fixed, this pattern would be supported as well!