Skip to content

Instantly share code, notes, and snippets.

Print Raw ASTs in the REPL

Sometimes it is just useful to see the typechecked AST of a scala expression.

Macros to the rescue:

import scala.reflect.macros.Context
import scala.language.experimental.macros

Desugar Scala Expressions

Use the compiler

scala -Xprint:typer -e "class A(val i: Int)" prints the desugarred expression after the typer phase. Use scala -Xshow-phases to get a list of all phases.

Or use a macro in the REPL

Paste this into a REPL session or in a file loaded with the :load command:

@Luegg
Luegg / index.html
Last active December 11, 2015 02:38
Minimal Plunk
<!DOCTYPE html>
<meta charset=utf-8>
<title>Minimal Plunk</title>
{
"cmd": ["tsc", "$file"],
"file_regex": "(.*\\.ts?)\\s\\(([0-9]+)\\,([0-9]+)\\)\\:\\s(...*?)$",
"selector": "source.ts",
"osx": {
"path": "/usr/local/bin:/opt/local/bin"
},
"windows": {
"cmd": ["tsc.cmd", "$file"],
"path": "C:\\Program Files\\nodejs\\;C:\\Users\\Lukas\\AppData\\Roaming\\npm\\"