How to dump the ast of an expression

I’m writting a ppx which is handling the unicode as an attribute payload. It works as I intended with ascii chars, but it doesn’t with the unicode chars.

My approach to resolve this issue is that constructing the backtick string literal in my ppx as a returning value, and as a pattern as well.

But I couldn’t find the way to dump the backtick expression in order to see the AST nodes in rescript such as dumpast command in OCaml.

Is it possible to construct the backick string literal with Parsetree module btw?

You can use bsc -dparsetree to print ast.

1 Like

Thank you! It prints the AST.

yarn bsc -dparsetree -e "let _ = \`하나\`"
[
  structure_item
    Pstr_value Nonrec
    [
      <def>
        pattern
          Ppat_any
        expression
          Pexp_constant PConst_string ("\237\149\152\235\130\152",Some "*j")
    ]
]

Hi please don’t use ppx unless you are willing to deal with the potential big breaking changes.

Most existing ppx tutorials are targeted to Ocaml compiler libs which are not the same as Rescript compiler libs.

This is a heads up warning since a lot of times people ask why we break their code. It’s typically either the case they are using some long deprecated features or some internal stuff.

For Unicode stuff, we will have built in support in next release

1 Like

HI! Glad to have your comment. Thank you for your advice.
I’m very excited about the next release with built-in support for Unicode, I can’t wait!.

Just curious, Is there the rescript compiler lib as you mentioned against the ppxlib for OCaml?

That’s discussed here:

1 Like