Open XVilka opened 5 years ago
Make a pull request?
@pmetzger If I only knew how to implement this...
I don't know either. :)
What about:
$ utop-full
# #require "compiler-libs";;
# #require "ppx_tools";;
# Format.printf "%a@." (Printast.expression 0) [%expr 1 + 1];;
expression (_none_[1,0+-1]..[1,0+-1]) ghost
Pexp_apply
expression (_none_[1,0+-1]..[1,0+-1]) ghost
Pexp_ident "+" (_none_[1,0+-1]..[1,0+-1]) ghost
[
<arg>
Nolabel
expression (_none_[1,0+-1]..[1,0+-1]) ghost
Pexp_constant PConst_int (1,None)
<arg>
Nolabel
expression (_none_[1,0+-1]..[1,0+-1]) ghost
Pexp_constant PConst_int (1,None)
]
?
Strange, didn't work in my utop - it doesn't understand [%expr...]
. even though #require "ppx_tools";;
worked without any error.
Never mind, found out it should be #require "ppx_tools.metaquot";;
obviously.
Anyway, having a shortcut for this would be useful for utop, what do you think? Should I send a PR for this?
I suppose we could add a function in the UTop
module (src/lib/uTop.mli), a PR is welcome. Note that it cannot be a directive as directives cannot take arbitrary expressions as arguments.
@XVilka Also add documentation for the new facility. :)
More modern recipe using ppxlib will be something like this:
#require "ppxlib";;
#require "ppxlib.metaquot";;
# open Ppxlib;;
# let loc = Location.none;;
# [%expr 1+1];;
An alias in utop would still be nice though :)
When you write the PPX extension using
dumpast
from ppx_tools is often not enough or inconvenient to use. It might be a killer feature of utop - to dump the AST of some expression. Something like "#dumpast" command in utop might be solution. Moreover it makes sense to support also metaquot syntax in it, to make life of PPX developer even easier.