-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add -keywords CLI argument to the driver, matching the compilers
Signed-off-by: Nathan Rebours <[email protected]>
- Loading branch information
Showing
7 changed files
with
106 additions
and
29 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
val is_keyword : string -> bool | ||
(** Check if a string is an OCaml keyword. *) | ||
|
||
val apply_keyword_edition : unit -> unit | ||
val apply_keyword_edition : cli:string option -> unit -> unit | ||
(** Processes any keywords= sections from the OCAMLPARAM environment variable | ||
and initialises the compiler's lexer with the correct keyword set. *) | ||
and CLI option and initialises the compiler's lexer with the correct keyword | ||
set. *) |
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 @@ | ||
let () = Ppxlib.Driver.standalone () |
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,10 @@ | ||
(executable | ||
(name driver) | ||
(enabled_if | ||
(>= %{ocaml_version} "5.3")) | ||
(libraries ppxlib)) | ||
|
||
(cram | ||
(enabled_if | ||
(>= %{ocaml_version} "5.3")) | ||
(deps driver.exe)) |
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,38 @@ | ||
This test can only work with OCaml 5.3 or higher. | ||
|
||
OCaml 5.3 introduced the new `effect` keyword. To allow old code to compile | ||
under 5.3 it also introduced a `-keyword=version+list` CLI option, allowing one to | ||
override the set of keywords. | ||
|
||
The ppxlib driver also has such an option now to properly configure the lexer before | ||
attempting to parse source code. | ||
|
||
Let's consider the following source file: | ||
$ cat > test.ml << EOF | ||
> let effect = 1 | ||
> EOF | ||
If passed to the driver as is, it will trigger a parse error: | ||
$ ./driver.exe --impl test.ml -o ignore.ml | ||
File "test.ml", line 1, characters 4-10: | ||
1 | let effect = 1 | ||
^^^^^^ | ||
Error: Syntax error | ||
[1] | ||
Now, if we use the 5.2 set of keywords, it should happily handle the file: | ||
$ ./driver.exe --keywords 5.2 --impl test.ml -o ignore.ml | ||
It can also be set using OCAMLPARAM: | ||
$ OCAMLPARAM=_,keywords=5.2 ./driver.exe --impl test.ml -o ignore.ml | ||
The priority between the CLI option and OCAMLPARAM must be respected, therefore | ||
both of the following invocation should parse: | ||
$ OCAMLPARAM=_,keywords=5.2 ./driver.exe --keywords 5.3 --impl test.ml -o ignore.ml | ||
$ OCAMLPARAM=keywords=5.3,_ ./driver.exe --keywords 5.2 --impl test.ml -o ignore.ml |