Skip to content

Latest commit

 

History

History
44 lines (30 loc) · 1.53 KB

File metadata and controls

44 lines (30 loc) · 1.53 KB

Writing PPXs

Description

After knowing what is an AST, how to build an AST and destructure it, we can now write our own PPX in OCaml.

Transformations

The soul of a PPX is the transformation. We want to get our AST and transform it into something else, like a new AST or lint errors.

Those transformations can be divided into two categories that we will cover on nested folders:

And they can work in different phases:

  • Lint (Global)
  • Preprocess (Global)
  • Instrumentation - Before (Global)
  • Context-free
  • Global Trasformation (Global)
  • Instrumentation - After (Global)

The following diagram shows the order of the phases and Driver's methods:

The beautiful MDN logo.

Drive's methods phases diagram. (reference)

How

PPXs commonly follow these steps:

  • Match the AST we want.
  • Work with the AST. For example:
    • Returning a new AST. Add new functions, change the name of a variable, etc.
    • Linting the code.
    • or doing anything else. Really, you're programming, everything is possible!