This commit is contained in:
parent
aa2ff7b2f0
commit
2f3113f55d
11742 changed files with 1223940 additions and 0 deletions
|
|
@ -0,0 +1,8 @@
|
|||
(ocamllex lexer1)
|
||||
|
||||
(menhir
|
||||
(modules test_menhir1)
|
||||
(flags :standard --cmly))
|
||||
|
||||
(executables
|
||||
(names test))
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(lang dune 1.1)
|
||||
(using menhir 1.0)
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
open Test_menhir1
|
||||
}
|
||||
|
||||
rule lex = parse
|
||||
| 'c' { TOKEN 'c' }
|
||||
| eof { EOF }
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
$ dune build ./test.exe --debug-dependency-path
|
||||
$ ls _build/default/test.exe
|
||||
_build/default/test.exe
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
let s = "foo bar baz"
|
||||
|
||||
let () =
|
||||
let lex1 = Lexing.from_string s in
|
||||
ignore (Test_menhir1.main Lexer1.lex lex1);
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
%token <char> TOKEN
|
||||
%token EOF
|
||||
|
||||
%start <char list> main
|
||||
|
||||
%%
|
||||
|
||||
main:
|
||||
| c = TOKEN EOF { [c] }
|
||||
| c = TOKEN xs = main { c :: xs }
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(cram
|
||||
(applies_to :whole_subtree)
|
||||
(deps %{bin:menhir}))
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
%token <char> TOKEN
|
||||
%token EOF
|
||||
|
||||
%start <char list> main
|
||||
|
||||
%%
|
||||
|
||||
main:
|
||||
| c = TOKEN EOF { [c] }
|
||||
| c = TOKEN xs = main { c :: xs }
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
$ cat > dune-project <<EOF
|
||||
> (lang dune 2.2)
|
||||
> (using menhir 2.1)
|
||||
> EOF
|
||||
$ cat >dune <<EOF
|
||||
> (env (_ (menhir_flags :standard "--comment")))
|
||||
> (menhir
|
||||
> (modules parser)
|
||||
> (mode promote))
|
||||
> (library (name test))
|
||||
> EOF
|
||||
$ dune printenv --field menhir_flags 2>&1 | sed "s/(using menhir .*)/(using menhir <version>)/"
|
||||
(menhir_flags (--comment))
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
%token START
|
||||
%start <int> start
|
||||
%%
|
||||
start: START { 42 }
|
||||
|
|
@ -0,0 +1,205 @@
|
|||
Support (explain) field in (menhir) stanza to produce .conflicts file:
|
||||
|
||||
$ 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 3.0 of the menhir extension.
|
||||
Please update your dune-project file to have (using menhir 3.0).
|
||||
[1]
|
||||
|
||||
$ cat >dune-project <<EOF
|
||||
> (lang dune 3.12)
|
||||
> (using menhir 3.0)
|
||||
> EOF
|
||||
|
||||
$ dune build
|
||||
File "dune-project", line 2, characters 14-17:
|
||||
2 | (using menhir 3.0)
|
||||
^^^
|
||||
Error: Version 3.0 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 3.0)
|
||||
> EOF
|
||||
|
||||
$ dune build
|
||||
|
||||
Let's check that the conflicts file has been generated successfully:
|
||||
|
||||
$ test -f _build/default/parser.conflicts
|
||||
|
||||
Let's check we can also pass `(explain false)`:
|
||||
|
||||
$ cat >dune <<EOF
|
||||
> (menhir (modules parser) (explain false))
|
||||
> (library (name lib))
|
||||
> EOF
|
||||
|
||||
$ dune build
|
||||
|
||||
$ ! 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
|
||||
|
||||
$ test -f _build/default/parser.conflicts
|
||||
|
||||
... but only if the Dune version is recent enough:
|
||||
|
||||
$ cat >dune-project <<EOF
|
||||
> (lang dune 3.13)
|
||||
> (using menhir 2.1)
|
||||
> EOF
|
||||
|
||||
$ dune build
|
||||
|
||||
$ ! test -f _build/default/parser.conflicts
|
||||
|
||||
Let's check that the argument to (explain) can be a blang:
|
||||
|
||||
$ cat >dune-project <<EOF
|
||||
> (lang dune 3.13)
|
||||
> (using menhir 3.0)
|
||||
> EOF
|
||||
|
||||
$ cat >dune <<EOF
|
||||
> (menhir (modules parser) (explain (= true false)))
|
||||
> (library (name lib))
|
||||
> EOF
|
||||
|
||||
$ dune build
|
||||
|
||||
$ ! test -f _build/default/parser.conflicts
|
||||
|
||||
Let's check that we get a warning if we use --explain with the new mode
|
||||
|
||||
$ cat >dune-project <<EOF
|
||||
> (lang dune 3.13)
|
||||
> (using menhir 3.0)
|
||||
> EOF
|
||||
|
||||
$ cat >dune <<EOF
|
||||
> (menhir (modules parser) (flags --explain))
|
||||
> (library (name lib))
|
||||
> EOF
|
||||
|
||||
$ dune build
|
||||
File "dune", line 1, characters 32-41:
|
||||
1 | (menhir (modules parser) (flags --explain))
|
||||
^^^^^^^^^
|
||||
Error: The Menhir '.conflicts' file is generated by default, so '--explain'
|
||||
should not be explicitly added to the list of Menhir flags.
|
||||
[1]
|
||||
|
||||
Let's now test the new field of (env), (menhir):
|
||||
|
||||
$ cat >dune-project <<EOF
|
||||
> (lang dune 3.12)
|
||||
> (using menhir 2.1)
|
||||
> EOF
|
||||
|
||||
$ cat >dune <<EOF
|
||||
> (env (_ (menhir (explain false))))
|
||||
> (menhir (modules parser))
|
||||
> (library (name lib))
|
||||
> EOF
|
||||
|
||||
$ dune build
|
||||
File "dune", line 1, characters 8-32:
|
||||
1 | (env (_ (menhir (explain false))))
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
Error: 'menhir' is only available since version 3.0 of the menhir extension.
|
||||
Please update your dune-project file to have (using menhir 3.0).
|
||||
[1]
|
||||
|
||||
$ cat >dune-project <<EOF
|
||||
> (lang dune 3.13)
|
||||
> (using menhir 3.0)
|
||||
> EOF
|
||||
|
||||
$ cat >dune <<EOF
|
||||
> (env (_ (menhir_flags --explain)))
|
||||
> (menhir (modules parser))
|
||||
> (library (name lib))
|
||||
> EOF
|
||||
|
||||
$ dune build
|
||||
File "dune", line 1, characters 8-32:
|
||||
1 | (env (_ (menhir_flags --explain)))
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
Error: 'menhir_flags' was deleted in version 3.0 of the menhir extension. Use
|
||||
(menhir (flags ...)) instead.
|
||||
[1]
|
||||
|
||||
$ cat >dune <<EOF
|
||||
> (env (_ (menhir (explain false))))
|
||||
> (menhir (modules parser))
|
||||
> (library (name lib))
|
||||
> EOF
|
||||
|
||||
$ dune build
|
||||
|
||||
$ ! test -f _build/default/parser.conflicts
|
||||
|
||||
$ cat >dune <<EOF
|
||||
> (env (_ (menhir (explain false))))
|
||||
> (menhir (modules parser) (explain true))
|
||||
> (library (name lib))
|
||||
> EOF
|
||||
|
||||
$ dune build
|
||||
|
||||
$ test -f _build/default/parser.conflicts
|
||||
|
||||
Also in subdirectories:
|
||||
|
||||
$ mkdir -p sub
|
||||
$ cp parser.mly sub/parser2.mly
|
||||
|
||||
$ cat >sub/dune <<EOF
|
||||
> (menhir (modules parser2))
|
||||
> (library (name lib2))
|
||||
> EOF
|
||||
|
||||
$ dune printenv sub | grep menhir
|
||||
(menhir_flags ())
|
||||
(menhir_explain (false))
|
||||
|
||||
$ dune build @sub/all
|
||||
|
||||
$ ! test -f _build/default/sub/parser2.conflicts
|
||||
|
||||
$ true >dune
|
||||
|
||||
$ dune printenv sub | grep menhir
|
||||
(menhir_flags ())
|
||||
(menhir_explain ())
|
||||
|
||||
$ dune build @sub/all
|
||||
|
||||
$ test _build/default/sub/parser2.conflicts
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
Dune should not crash when `menhir_flags` are passed in a workspace file.
|
||||
See #9024.
|
||||
|
||||
$ cat > dune-project << EOF
|
||||
> (lang dune 3.0)
|
||||
> (using menhir 2.0)
|
||||
> EOF
|
||||
|
||||
$ cat > dune-workspace << EOF
|
||||
> (lang dune 3.0)
|
||||
> (env
|
||||
> (test (menhir_flags --table)))
|
||||
> EOF
|
||||
|
||||
$ dune build 2>&1 | head -n 5
|
||||
Internal error, please report upstream including the contents of _build/log.
|
||||
Description:
|
||||
("Syntax identifier is unset",
|
||||
{ name = "menhir"
|
||||
; supported_versions =
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(lang dune 1.4)
|
||||
(using menhir 2.0)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
Test the menhir extension version 2.0
|
||||
|
||||
$ dune build ./src/test.exe --debug-dependency-path
|
||||
$ ls _build/default/src/test.exe
|
||||
_build/default/src/test.exe
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
(ocamllex lexer1 lexer2)
|
||||
|
||||
(menhir
|
||||
(modules test_menhir1)
|
||||
(flags :standard --unused-tokens))
|
||||
|
||||
(menhir
|
||||
(merge_into test_base)
|
||||
(flags --explain)
|
||||
(modules tokens parser))
|
||||
|
||||
(executables
|
||||
(names test))
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
open Test_menhir1
|
||||
}
|
||||
|
||||
rule lex = parse
|
||||
| 'c' { TOKEN 'c' }
|
||||
| eof { EOF }
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
open Test_base
|
||||
}
|
||||
|
||||
rule lex = parse
|
||||
| 'c' { TOKEN 'c' }
|
||||
| eof { EOF }
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
%start <char list> main
|
||||
|
||||
%%
|
||||
|
||||
main:
|
||||
| c = TOKEN EOF { [c] }
|
||||
| c = TOKEN xs = main { c :: xs }
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
let s = "foo bar baz"
|
||||
|
||||
let () =
|
||||
let lex1 = Lexing.from_string s in
|
||||
let lex2 = Lexing.from_string s in
|
||||
ignore (Test_menhir1.main Lexer1.lex lex1);
|
||||
ignore (Test_base.main Lexer2.lex lex2)
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
%token <char> TOKEN
|
||||
%token EOF
|
||||
|
||||
%start <char list> main
|
||||
|
||||
%%
|
||||
|
||||
main:
|
||||
| c = TOKEN EOF { [c] }
|
||||
| c = TOKEN xs = main { c :: xs }
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
%token <char> TOKEN
|
||||
%token EOF
|
||||
|
||||
%%
|
||||
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
Build and run a source file that requires a menhir parser.
|
||||
|
||||
$ cat >dune-project <<EOF
|
||||
> (lang dune 1.0)
|
||||
> (using menhir 1.0)
|
||||
> EOF
|
||||
|
||||
$ dune build ./src/test.exe --debug-dependency-path
|
||||
$ ls _build/default/src/test.exe
|
||||
_build/default/src/test.exe
|
||||
|
||||
$ cat >dune-project <<EOF
|
||||
> (lang dune 2.0)
|
||||
> (using menhir 2.0)
|
||||
> EOF
|
||||
|
||||
$ dune build ./src/test.exe --debug-dependency-path
|
||||
$ ls _build/default/src/test.exe
|
||||
_build/default/src/test.exe
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
(ocamllex lexer1 lexer2)
|
||||
|
||||
(menhir
|
||||
(modules test_menhir1)
|
||||
(flags :standard --unused-tokens))
|
||||
|
||||
(menhir
|
||||
(merge_into test_base)
|
||||
(flags --explain)
|
||||
(modules tokens parser))
|
||||
|
||||
(executables
|
||||
(names test))
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
open Test_menhir1
|
||||
}
|
||||
|
||||
rule lex = parse
|
||||
| 'c' { TOKEN 'c' }
|
||||
| eof { EOF }
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
open Test_base
|
||||
}
|
||||
|
||||
rule lex = parse
|
||||
| 'c' { TOKEN 'c' }
|
||||
| eof { EOF }
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
%start <char list> main
|
||||
|
||||
%%
|
||||
|
||||
main:
|
||||
| c = TOKEN EOF { [c] }
|
||||
| c = TOKEN xs = main { c :: xs }
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
let s = "foo bar baz"
|
||||
|
||||
let () =
|
||||
let lex1 = Lexing.from_string s in
|
||||
let lex2 = Lexing.from_string s in
|
||||
ignore (Test_menhir1.main Lexer1.lex lex1);
|
||||
ignore (Test_base.main Lexer2.lex lex2)
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
%token <char> TOKEN
|
||||
%token EOF
|
||||
|
||||
%start <char list> main
|
||||
|
||||
%%
|
||||
|
||||
main:
|
||||
| c = TOKEN EOF { [c] }
|
||||
| c = TOKEN xs = main { c :: xs }
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
%token <char> TOKEN
|
||||
%token EOF
|
||||
|
||||
%%
|
||||
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
$ cat > dune-project << EOF
|
||||
> (lang dune 3.13)
|
||||
> (using menhir 3.0)
|
||||
> EOF
|
||||
|
||||
$ mkdir -p src/a
|
||||
$ cat > dune << EOF
|
||||
> (include_subdirs unqualified)
|
||||
> (library (name foo))
|
||||
> (menhir
|
||||
> (modules parser)
|
||||
> (flags --dump))
|
||||
> (ocamllex lexer)
|
||||
> EOF
|
||||
|
||||
$ cat >lexer.mll <<EOF
|
||||
> {
|
||||
> }
|
||||
> rule lex = parse
|
||||
> | _ { true }
|
||||
> | eof { false }
|
||||
> EOF
|
||||
$ touch src/a/parser.mly
|
||||
$ dune build
|
||||
File "dune", lines 3-5, characters 0-42:
|
||||
3 | (menhir
|
||||
4 | (modules parser)
|
||||
5 | (flags --dump))
|
||||
Error: No rule found for parser.mly
|
||||
[1]
|
||||
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
We should be able to use menhir as a group interface:
|
||||
|
||||
$ cat >dune-project <<EOF
|
||||
> (lang dune 3.11)
|
||||
> (using menhir 2.1)
|
||||
> EOF
|
||||
|
||||
$ cat >dune <<EOF
|
||||
> (include_subdirs qualified)
|
||||
> (executable (name foo))
|
||||
> EOF
|
||||
$ touch foo.ml
|
||||
|
||||
$ mkdir group
|
||||
$ cat >group/dune <<EOF
|
||||
> (menhir (modules group))
|
||||
> EOF
|
||||
|
||||
$ cat >group/group.mly <<EOF
|
||||
> %{
|
||||
> module M = M
|
||||
> %}
|
||||
> %token EOF
|
||||
>
|
||||
> %start<unit> unit
|
||||
> %%
|
||||
>
|
||||
> unit:
|
||||
> | EOF { () }
|
||||
> EOF
|
||||
|
||||
$ touch group/m.ml
|
||||
|
||||
$ dune build
|
||||
File "group/group.mly", line 2, characters 11-12:
|
||||
Error: Unbound module M
|
||||
[1]
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
We should be able to use menhir as a library interface:
|
||||
|
||||
$ cat >dune-project <<EOF
|
||||
> (lang dune 3.11)
|
||||
> (using menhir 2.1)
|
||||
> EOF
|
||||
|
||||
$ cat >dune <<EOF
|
||||
> (include_subdirs qualified)
|
||||
> (library (name foo))
|
||||
> (menhir (modules foo))
|
||||
> EOF
|
||||
|
||||
$ cat > m.ml << EOF
|
||||
> let x = ()
|
||||
> EOF
|
||||
|
||||
$ cat >foo.mly <<EOF
|
||||
> %token EOF
|
||||
>
|
||||
> %start<unit> unit
|
||||
> %%
|
||||
>
|
||||
> unit:
|
||||
> | EOF { M.x }
|
||||
> EOF
|
||||
|
||||
$ dune build foo.cma
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
%token EOF
|
||||
|
||||
%start<unit> unit
|
||||
%%
|
||||
|
||||
unit:
|
||||
| EOF { () }
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(menhir
|
||||
(modules baz))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(lang dune 3.7)
|
||||
(using menhir 2.1)
|
||||
(name foo)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
let () =
|
||||
Bar.Baz.unit (fun _ -> Bar.Baz.EOF) (Lexing.from_string "")
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
The use of (include_subdirs qualified) should be compatible with the use of
|
||||
Menhir in other places than the root of the file hierarchy.
|
||||
|
||||
$ test() {
|
||||
> cat >dune <<EOF
|
||||
> (include_subdirs $1)
|
||||
> (executable (name foo))
|
||||
> EOF
|
||||
> dune build foo.exe
|
||||
> }
|
||||
|
||||
$ test unqualified
|
||||
File "foo.ml", line 2, characters 2-14:
|
||||
2 | Bar.Baz.unit (fun _ -> Bar.Baz.EOF) (Lexing.from_string "")
|
||||
^^^^^^^^^^^^
|
||||
Error: Unbound module Bar
|
||||
Hint: Did you mean Baz?
|
||||
[1]
|
||||
$ test qualified
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
(menhir
|
||||
(modules parser)
|
||||
(mode promote))
|
||||
|
||||
(library
|
||||
(name test))
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(lang dune 1.7)
|
||||
(using menhir 2.0)
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
%token <char> TOKEN
|
||||
%token EOF
|
||||
|
||||
%start <char list> main
|
||||
|
||||
%%
|
||||
|
||||
main:
|
||||
| c = TOKEN EOF { [c] }
|
||||
| c = TOKEN xs = main { c :: xs }
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
Reproduction case for #1781, only the .ml and .mli should be promoted:
|
||||
|
||||
$ dune build @all
|
||||
$ ls -1 _build/default | sort | grep mock
|
||||
parser__mock.ml.mock
|
||||
parser__mock.mli.inferred
|
||||
$ ls -1 | grep mock
|
||||
[1]
|
||||
Check what is being generated exactly:
|
||||
$ ls -1
|
||||
_build
|
||||
dune
|
||||
dune-project
|
||||
parser.ml
|
||||
parser.mli
|
||||
parser.mly
|
||||
Loading…
Add table
Add a link
Reference in a new issue