-
Notifications
You must be signed in to change notification settings - Fork 99
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
Metaquot: Embed errors in the AST instead of raising #392
Comments
Note that we decided that we will change the ppxlib behaviour regarding the handling of exceptions, to match the current use of However, embedding errors still have advantages: It allows reporting multiple errors, while still outputting valid AST for the part that were successful. In the case of this PPX, an example where embedding errors is better could written as: let invalid = [%expr [%e? _] [%e? _]] which, when raising instead of embedding errors, would not list both errors (both |
Hello @panglesd, I would love to work on this issue but I am still new to ocaml language and would like to please request for your guidance in working on this task. |
Hello @Burnleydev1 ! In order to work on this issue, you will have to:
In order to understand metaquot itself, in addition to the resources that you should have read in the outreachy issue #389, you can read the chapter of ppxlib on metaquot: https://ocaml.org/p/ppxlib/latest/doc/generating-code.html#metaquot and https://ocaml.org/p/ppxlib/latest/doc/matching-code.html#metaquot Finally, to turn raising into embeddings, you can look at ppxlib's example: here is the version raising: https://github.com/ocaml-ppx/ppxlib/blob/427f96e126d306538eb541ac591f71b2c68e5dd4/examples/simple-extension-rewriter/ppx_get_env.ml and the same file where the raising has been turned into error embedding: https://github.com/ocaml-ppx/ppxlib/blob/main/examples/simple-extension-rewriter/ppx_get_env.ml |
Hi @panglesd, thanks for the pointers. I’ll get on it right away. |
Hello @panglesd,
in
is a good start to solving the issue, |
Hello @panglesd, I think I understood this steps: |
That is a very good start! The result type is when you cannot embed the error directly in a part of AST. In the present case, you can directly return an AST node, as you've tried to do it in the code sample you sent me, so you don't need to use the result type. There are still errors in the code you sent me (the
You need to replace 3. with: It would be good if you can try the code before sending it for help! Could you successfully setup and compile the project? In which case, were you able to make your modifications, get an error from the compiler, and understand the error message? |
@panglesd thanks a lot, I will get on in right away
I actually created a new project using |
This comment was marked as outdated.
This comment was marked as outdated.
I will try to apply the corrections you suggested. |
@panglesd Please I wish to ask if you mean the error message I get when I run |
I assume you were able to clone the ppxlib repo (this one), install the dependencies if needed, and run Once you have successfully run The file in |
Hello @panglesd, thank you for this information.
|
You should try as much as you can to read the error message, they are already informing you what is wrong!
|
Hello @panglesd, I have been trying the various values from the |
Hello @panglesd, I created a Pull request to this issue here, I decide to use the Ppat_extension since i kept getting the error |
I think you were misled by the extension constructor thing. Extension constructors are for the "extensive sum types": see here and here. Even though you don't need
|
I now understand why |
Fixed in #397. |
Currently, when
ppxlib.metaquot
encounters an error, it uses theraise_errorf
function to raise a located error.The exception is caught by
ppxlib
, which in this case:[%%%ocaml.error ...]
extension node) to the last valid astThe interruption of the rewriting is quite bad for the user experience! The implication for the users are:
ppxlib.metaquotl
runs at the "context-free" phase, the "last valid AST" is before the context-free phase. So, no other derivers/extenders get run, which generates a lot of noise in the errors (such as "uninterpreted extensions" or "unbound identifiers")Example
For instance:
would report several errors:
expression expected
forinvalid1
(the right error, but not super explicit!)for
invalid1,
invalid2and
invalid3`.The right error for
invalid2
("pattern expected", again it could be more precise) is not shown, and similarly the error forinvalid3
("guard not expected here") is not displayed.Moreover, the "uninterpreted extension" errors add a lot of noise!
Since
ppxlib.metaquot
can (in my opinion) be confusing with antiquote, it would be nice if the error reporting were user-friendly and precise!This issue is part of an outreachy internship: see more information here.
The text was updated successfully, but these errors were encountered: