-
Notifications
You must be signed in to change notification settings - Fork 396
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 (explain) field to (menhir) stanza #9512
Merged
Merged
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4bd8fd2
Add (explain) field to (menhir) stanza
nojb 028cabc
Doc
nojb 0b46891
Also detect --menhir flag
nojb 72de97e
Revert "Also detect --menhir flag"
nojb 2626c7a
Switch to (explain <bool>)
nojb 4a32150
Generate file by default
nojb 922c580
Control the default with the version of the Menhir extension
nojb 045407f
Allow (explain <blang>)
nojb 3c42b01
Doc
nojb 2f8afb1
Merge branch 'main' into menhir_explain
nojb 560a1a9
Warn if passing --explain under the new mode
nojb 683c645
Changes
nojb 571412f
Cleanup
nojb 67f006e
Less verbose tests
nojb 4aafa94
Introduce (menhir) field in (env) stanza
nojb d8127be
Use List.equal
nojb 50ec8da
Bump Menhir extension version to 3.0
nojb ee94d7f
Accept tests
nojb 1468c5e
Merge branch 'main' into menhir_explain
nojb 0546401
Fix Doc
nojb 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
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
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
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
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
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,157 @@ | ||
Support (explain) field in (menhir) stanza to produce .conflicts file: | ||
|
||
$ cat >parser.mly <<EOF | ||
> %token START | ||
> %start <int> start | ||
> %% | ||
> start: START | START { 42 } | ||
> EOF | ||
|
||
$ cat >dune <<EOF | ||
> (menhir (modules parser) (explain true)) | ||
> (library (name lib)) | ||
> EOF | ||
|
||
First we check the version guards: | ||
|
||
$ cat >dune-project <<EOF | ||
> (lang dune 3.12) | ||
> (using menhir 2.1) | ||
> EOF | ||
|
||
$ dune build | ||
File "dune", line 1, characters 25-39: | ||
1 | (menhir (modules parser) (explain true)) | ||
^^^^^^^^^^^^^^ | ||
Error: 'explain' is only available since version 2.2 of the menhir extension. | ||
Please update your dune-project file to have (using menhir 2.2). | ||
[1] | ||
|
||
$ cat >dune-project <<EOF | ||
> (lang dune 3.12) | ||
> (using menhir 2.2) | ||
> EOF | ||
|
||
$ dune build | ||
File "dune-project", line 2, characters 14-17: | ||
2 | (using menhir 2.2) | ||
^^^ | ||
Error: Version 2.2 of the menhir extension is not supported until version | ||
3.13 of the dune language. | ||
Supported versions of this extension in version 3.12 of the dune language: | ||
- 1.0 to 1.1 | ||
- 2.0 to 2.1 | ||
[1] | ||
|
||
$ cat >dune-project <<EOF | ||
> (lang dune 3.13) | ||
> (using menhir 2.2) | ||
> EOF | ||
|
||
$ dune build | ||
Warning: one state has reduce/reduce conflicts. | ||
Warning: one reduce/reduce conflict was arbitrarily resolved. | ||
File "parser.mly", line 4, characters 15-20: | ||
Warning: production start -> START is never reduced. | ||
Warning: in total, 1 production is never reduced. | ||
|
||
Let's check that the conflicts file has been generated successfully: | ||
|
||
$ cat _build/default/parser.conflicts | ||
|
||
** Conflict (reduce/reduce) in state 1. | ||
** Token involved: # | ||
** This state is reached from start after reading: | ||
|
||
START | ||
|
||
** The derivations that appear below have the following common factor: | ||
** (The question mark symbol (?) represents the spot where the derivations begin to differ.) | ||
|
||
start // lookahead token is inherited | ||
(?) | ||
|
||
** In state 1, looking ahead at #, reducing production | ||
** start -> START | ||
** is permitted because of the following sub-derivation: | ||
|
||
START . | ||
|
||
** In state 1, looking ahead at #, reducing production | ||
** start -> START | ||
** is permitted because of the following sub-derivation: | ||
|
||
START . | ||
|
||
|
||
|
||
|
||
|
||
|
||
Let's check we can also pass `(explain false)`: | ||
|
||
$ cat >dune <<EOF | ||
> (menhir (modules parser) (explain false)) | ||
> (library (name lib)) | ||
> EOF | ||
|
||
$ dune build | ||
Warning: one state has reduce/reduce conflicts. | ||
Warning: one reduce/reduce conflict was arbitrarily resolved. | ||
File "parser.mly", line 4, characters 15-20: | ||
Warning: production start -> START is never reduced. | ||
Warning: in total, 1 production is never reduced. | ||
|
||
$ ! test -f _build/default/parser.conflicts | ||
|
||
Let's check that it is generated by default if we omit the (explain) field: | ||
|
||
$ cat >dune <<EOF | ||
> (menhir (modules parser)) | ||
> (library (name lib)) | ||
> EOF | ||
|
||
$ dune build | ||
Warning: one state has reduce/reduce conflicts. | ||
Warning: one reduce/reduce conflict was arbitrarily resolved. | ||
File "parser.mly", line 4, characters 15-20: | ||
Warning: production start -> START is never reduced. | ||
Warning: in total, 1 production is never reduced. | ||
|
||
$ cat _build/default/parser.conflicts | ||
|
||
** Conflict (reduce/reduce) in state 1. | ||
** Token involved: # | ||
** This state is reached from start after reading: | ||
|
||
START | ||
|
||
** The derivations that appear below have the following common factor: | ||
** (The question mark symbol (?) represents the spot where the derivations begin to differ.) | ||
|
||
start // lookahead token is inherited | ||
(?) | ||
|
||
** In state 1, looking ahead at #, reducing production | ||
** start -> START | ||
** is permitted because of the following sub-derivation: | ||
|
||
START . | ||
|
||
** In state 1, looking ahead at #, reducing production | ||
** start -> START | ||
** is permitted because of the following sub-derivation: | ||
|
||
START . | ||
|
||
|
||
... but only if the Dune version is recent enough: | ||
|
||
$ cat >dune-project <<EOF | ||
> (lang dune 3.12) | ||
> (using menhir 2.1) | ||
> EOF | ||
|
||
$ dune build | ||
|
||
$ ! test -f _build/default/parser.conflicts |
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.
I think you should use the version of the menhir syntax to control this behavior.
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.
Good point, done.