Ast_pattern: augment API with ebool, pbool helper, and a new map.#402
Conversation
Signed-off-by: Burnleydev1 <[email protected]>
Signed-off-by: Burnleydev1 <[email protected]>
Signed-off-by: Burnleydev1 <[email protected]>
|
The The second bullet point is almost good: You don't need to "implement" |
|
Hello @panglesd, what if I use the |
|
But it just hit me that |
|
You could have used However, those functions are easy to reimplement. |
|
Hello @panglesd,please I looked at which has the signature |
|
You don't need to take so much of the |
|
Hello @panglesd, please i am having issues identifying the branch where the given value is not a |
|
please is there documentation on this, please I would like to read it and understand |
let some (T f0) = (* some takes as input a pattern [T f0] (supposed to match the inside of the [Some _]*)
T
(fun ctx loc x k -> (* it returns a pattern which: *)
match x with (* match whether [x] is [Some _] or [None]: *)
| Some x0 -> (* - in the [Some _] case it *)
ctx.matched <- ctx.matched + 1;
let k = f0 ctx loc x0 k in (* applies the pattern given as input to the value enclosed in the [Some] *)
k
| _ -> fail loc "Some" (* - otherwise, it fails with location [loc], saying that it expects a [Some] (see the definition of [fail] *)) |
Signed-off-by: Burnleydev1 <[email protected]>
|
Hello @panglesd, thanks for explaining how |
|
Yes, that's perfect! You now have a function turning a |
|
Hello @panglesd, I am trying to carry out step 3 but I'm facing some difficulties, I took inspiration from this function below since it is the only place in let rec parse_elist (e : Parsetree.expression) acc =
Common.assert_no_attributes e.pexp_attributes;
match e.pexp_desc with
| Pexp_construct ({ txt = Lident "[]"; _ }, None) -> List.rev acc
| Pexp_construct ({ txt = Lident "::"; _ }, Some arg) -> (
Common.assert_no_attributes arg.pexp_attributes;
match arg.pexp_desc with
| Pexp_tuple [ hd; tl ] -> parse_elist tl (hd :: acc)
| _ -> fail arg.pexp_loc "list")
| _ -> fail e.pexp_loc "list"and started with something like this let ebool = Pexp_construct ({txt = Lident "true"; _} ,None) but I am getting errors like let ebool = Pexp_construct ({txt = Lident "true"; loc = Location.none} ,None) which gives no errors |
|
I tried using the method from this documentation as well to get something like this let ebool (parse_res : (bool, 'a, 'b) t) : (expression, 'a, 'b) t =
Pexp_construct ({txt = Lident bool'; loc = Location.none} ,None) but it did not work either. |
|
Lident converts and bool' converts |
Signed-off-by: Burnleydev1 <[email protected]>
Signed-off-by: Burnleydev1 <[email protected]>
Signed-off-by: Burnleydev1 <[email protected]>
Signed-off-by: Burnleydev1 <[email protected]>
|
Hello @panglesd, I think I finally got it, I have pushed the changes here. |
|
Very nice! Thank you @Burnleydev1! Why did you decide to include |
|
@panglesd, I noticed that other variables in the .ml had their signature in the .mli file and I named it like that because I noticed that each variable eg map has a map’ and int32 also has int32’.I don’t know why that’s the case but I just decide that bool should also have a bool |
|
And I noticed that the map’ was the map but with location |
|
I just saw how other vals were defined and used that as a template to define these ones but I can remove bool’ if it is not needed |
|
Or change it to something more conventional |
|
But the main reason is that |
Signed-off-by: Burnleydev1 <[email protected]>
|
@panglesd, could we name it |
|
If the existing helpers are called |
panglesd
left a comment
There was a problem hiding this comment.
Yes, bool' is coherent with other naming!
For some reason I missed the int32', ... convention, I only knew the map', ... convention (which is for "with location" variants).
With the removal of ebool' from the mli, It's now perfect, and ready to be merged!
|
Thanks @panglesd, @ceastlund for the review. |
CHANGES: - Adopt the OCaml Code of Conduct on the repo (ocaml-ppx/ppxlib#426, @pitag-ha) - Clean up misleading attribute hints when declared for proper context. (ocaml-ppx/ppxlib#425, @ceastlund) - Ast_pattern now has ebool, pbool helper, and a new map.(ocaml-ppx/ppxlib#402, @Burnleydev1) - multiple errors are now reported in `metaquot`. (ocaml-ppx/ppxlib#397, @Burnleydev1) - Add `Attribute.declare_with_attr_loc` (ocaml-ppx/ppxlib#396, @dvulakh) - Add "ns" and "res" as reserved namespaces(ocaml-ppx/ppxlib#388, @davesnx) - Make quoter `let` binding non-recursive (ocaml-ppx/ppxlib#401, @sim642) - Fix failure of 'lift_map_with_context' in traverse by compile-time evaluation of 'fst' and 'snd' (ocaml-ppx/ppxlib#390, @smuenzel) - Driver: Bias the mapping from magic to version towards the current version, as it is usually the common case and it helps when magic numbers are ambiguous (such as on development versions) (ocaml-ppx/ppxlib#409, @shym) - Remove unnecessary test dependencies towards base and stdio (ocaml-ppx/ppxlib#421, @kit-ty-kate) - Update description to reflect that `ppxlib` contains more than a library (ocaml-ppx/ppxlib#422, @pitag-ha) - Add support for OCaml 5.1, excluding OCaml `5.1.0~alpha1` (ocaml-ppx/ppxlib#428, @shym, @Octachron , @pitag-ha, @panglesd) - Driver: Fix `-locations-check` option for coercions with ground (ocaml-ppx/ppxlib#428, @Octachron)
CHANGES: - Adopt the OCaml Code of Conduct on the repo (ocaml-ppx/ppxlib#426, @pitag-ha) - Clean up misleading attribute hints when declared for proper context. (ocaml-ppx/ppxlib#425, @ceastlund) - Ast_pattern now has ebool, pbool helper, and a new map.(ocaml-ppx/ppxlib#402, @Burnleydev1) - multiple errors are now reported in `metaquot`. (ocaml-ppx/ppxlib#397, @Burnleydev1) - Add `Attribute.declare_with_attr_loc` (ocaml-ppx/ppxlib#396, @dvulakh) - Add "ns" and "res" as reserved namespaces(ocaml-ppx/ppxlib#388, @davesnx) - Make quoter `let` binding non-recursive (ocaml-ppx/ppxlib#401, @sim642) - Fix failure of 'lift_map_with_context' in traverse by compile-time evaluation of 'fst' and 'snd' (ocaml-ppx/ppxlib#390, @smuenzel) - Driver: Bias the mapping from magic to version towards the current version, as it is usually the common case and it helps when magic numbers are ambiguous (such as on development versions) (ocaml-ppx/ppxlib#409, @shym) - Remove unnecessary test dependencies towards base and stdio (ocaml-ppx/ppxlib#421, @kit-ty-kate) - Update description to reflect that `ppxlib` contains more than a library (ocaml-ppx/ppxlib#422, @pitag-ha) - Add support for OCaml 5.1, excluding OCaml `5.1.0~alpha1` (ocaml-ppx/ppxlib#428, @shym, @Octachron , @pitag-ha, @panglesd) - Driver: Fix `-locations-check` option for coercions with ground (ocaml-ppx/ppxlib#428, @Octachron)
CHANGES: - Adopt the OCaml Code of Conduct on the repo (ocaml-ppx/ppxlib#426, @pitag-ha) - Clean up misleading attribute hints when declared for proper context. (ocaml-ppx/ppxlib#425, @ceastlund) - Ast_pattern now has ebool, pbool helper, and a new map.(ocaml-ppx/ppxlib#402, @Burnleydev1) - multiple errors are now reported in `metaquot`. (ocaml-ppx/ppxlib#397, @Burnleydev1) - Add `Attribute.declare_with_attr_loc` (ocaml-ppx/ppxlib#396, @dvulakh) - Add "ns" and "res" as reserved namespaces(ocaml-ppx/ppxlib#388, @davesnx) - Make quoter `let` binding non-recursive (ocaml-ppx/ppxlib#401, @sim642) - Fix failure of 'lift_map_with_context' in traverse by compile-time evaluation of 'fst' and 'snd' (ocaml-ppx/ppxlib#390, @smuenzel) - Driver: Bias the mapping from magic to version towards the current version, as it is usually the common case and it helps when magic numbers are ambiguous (such as on development versions) (ocaml-ppx/ppxlib#409, @shym) - Remove unnecessary test dependencies towards base and stdio (ocaml-ppx/ppxlib#421, @kit-ty-kate) - Update description to reflect that `ppxlib` contains more than a library (ocaml-ppx/ppxlib#422, @pitag-ha) - Add support for OCaml 5.1, excluding OCaml `5.1.0~alpha1` (ocaml-ppx/ppxlib#428, @shym, @Octachron , @pitag-ha, @panglesd) - Driver: Fix `-locations-check` option for coercions with ground (ocaml-ppx/ppxlib#428, @Octachron)
fixes #399
map_valuefunction to turn a(bool, 'c, 'd) Ast_pattern.tinto a(string, c, d) Ast_pattern.tpexp_construct,lidentand the value previously created to defineeboolandpbool