-
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
Ast_pattern: augment API with ebool
, pbool
helper, and a new map
.
#399
Comments
Hello @panglesd, please I would like to work on this issue. |
Hello @Burnleydev1! Great, feel free to ask me any question you would have: |
Thanks @panglesd, my first question may be offtopic, I wish to ask if there is a way for me to locally build the API website. |
Sure! You can run |
Some potentially useful information: some part of the code of |
Thanks, @panglesd, if I am not mistaken, it means that I need to add those values in such a way that it shows on the api in the manner you described in the comment above? |
Hello @panglesd, please correct me if I am wrong, I think I understand now, what we want to do is to add a constant like |
I may be totally wrong, but the reason I stated the above observation is because when i use
|
It is important to understand well the AST types in order to solve this issue! The AST type can be found here: https://ocaml.org/p/ppxlib/latest/doc/Astlib/Ast_500/Parsetree/index.html If you look at We are interested in how to turn a bool into an expression. If you want to know the AST that corresponds to a specific expression, you can run If you use any of the tool to know the AST corresponding to Before adding So, the function to add to (* in Ast_builder.Default *)
val ebool : ~loc:location -> bool -> expression
val pbool : ~loc:location -> bool -> pattern
(* in Ast_builder.Make *)
val ebool : bool -> expression
val pbool : bool -> pattern They would respectively build an expression or a pattern representing a boolean, from such a boolean. To build such values, you can use other values of When I say "add to the API", I mean:
and that's it! They will automatically appear in the documentation. I hope it is clearer what you have to do, and how! |
ebool
, pbool
helper, and a new map
.ebool
, pbool
helper, and a new map
.
@panglesd, Thanks a lot for the pointers, I will get on it right away. |
Hello @panglesd, I noticed that |
Good point, sorry I missed that! In this case, you can try the |
ebool
, pbool
helper, and a new map
.ebool
, pbool
helper, and a new map
.
Okay @panglesd, I will get on that right away. |
Hello @panglesd, Ast_pattern really is tricky
or
is a good start to solving this issue |
I think the first thing is to understand well For this, you need to read (again, with fresh mind!) the manual on it: here and understand how to use it.
type ('matched_value, 'k, 'k_result) t =
| T of (context -> Location.t -> 'matched_value -> 'k -> 'k_result) So, an
At this point,
This is because of how the OCaml AST has been designed: some values (strings, integer, float, ...) were encoded as constants, but others ( That's why you have to write |
if b then
pexp_construct (Longident.Lident "true")
else
pexp_construct (Longident.Lident "false")"
let ebool b =
if b then
pexp_construct (pconst_string "true" b)
else
pexp_construct ( pconst_string "false")
Definitely a good start! However, in your two attempts, |
Thanks a lot for the pointers @panglesd, I will get on it right away. |
Hi @panglesd, I decided to use your second method to go about the solution,applying the (match, continuation, result) concept, does this mean that the signature of map_value will be something like this: |
I will create a pull request to track the changes |
Hello @panglesd, I am trying to implement |
I'll answer in the PR directly |
estring
,echar
,efloat
, ... helpers are created using functions generated from theconstant
type.However, this type does not contain boolean constants, such as
true
andfalse
. Indeed, such constants are defined as constructors (without argument, nor uppercase), as seen usingutop -dparsetree
:As a consequence,
ebool
was not added to theAst_pattern
API, even though it is useful (as illustrated here)It would be useful to have such values in the API:
While looking at this, I noticed that we are also missing two maps:
with which it is simple to generate
ebool
andpbool
, and that should be added to the API as well!The text was updated successfully, but these errors were encountered: