Basic Expressions 

Literals 

As we’ve seen earlier, literals are written as follows:

scala> import treehugger.forest._, definitions._, treehuggerDSL._
import treehugger.forest._
import definitions._
import treehuggerDSL._

scala> LIT(1)                       // 1
[1m[34mres0[0m: [1m[32mtreehugger.forest.Literal[0m = Literal(Constant(1))

scala> LIT(1L)                      // 1L
[1m[34mres1[0m: [1m[32mtreehugger.forest.Literal[0m = Literal(Constant(1))

scala> LIT(1.23)                    // 1.23
[1m[34mres2[0m: [1m[32mtreehugger.forest.Literal[0m = Literal(Constant(1.23))

scala> LIT(1.23F)                   // 1.23F
[1m[34mres3[0m: [1m[32mtreehugger.forest.Literal[0m = Literal(Constant(1.23))

scala> LIT('H')                     // 'H'
[1m[34mres4[0m: [1m[32mtreehugger.forest.Literal[0m = Literal(Constant(H))

scala> LIT("H")                     // "H"
[1m[34mres5[0m: [1m[32mtreehugger.forest.Literal[0m = Literal(Constant(H))

scala> LIT('Sym)                    // 'Sym
[1m[34mres6[0m: [1m[32mtreehugger.forest.Literal[0m = Literal(Constant('Sym))

scala> TRUE                         // true
[1m[34mres7[0m: [1m[32mtreehugger.forest.Literal[0m = Literal(Constant(true))

scala> FALSE                        // false
[1m[34mres8[0m: [1m[32mtreehugger.forest.Literal[0m = Literal(Constant(false))

scala> NULL                         // null
[1m[34mres9[0m: [1m[32mtreehugger.forest.Literal[0m = Literal(Constant(null))

scala> UNIT                         // ()
[1m[34mres10[0m: [1m[32mtreehugger.forest.Literal[0m = Literal(Constant(()))

Simple Names 

Simple names are written using REF(sym|"x") to refer to values and methods that immediately available in the current scope:

scala> object sym {
  val x = RootClass.newValue("x")
  val y = RootClass.newValue("y")
  val Address = RootClass.newClass("Address")
}
defined object sym

scala> REF("x")                     // x
[1m[34mres11[0m: [1m[32mtreehugger.forest.Ident[0m = Ident(x)

scala> REF(sym.x)                   // x
[1m[34mres12[0m: [1m[32mtreehugger.forest.Tree[0m = Ident(x)

Selection 

To refer to other values and methods, selections are written by calling DOT(sym|"y") either on a symbol or on a REF(sym|"x"). This returns an intermediate structure that can turn into a Tree by calling tree method or by implicit conversion:

scala> (sym.x DOT sym.y).tree       // x.y
[1m[34mres13[0m: [1m[32mtreehugger.forest.Select[0m = Select(Ident(x),y)

scala> (sym.x DOT "y": Tree)        // x.y
[1m[34mres14[0m: [1m[32mtreehugger.forest.Tree[0m = Select(Ident(x),y)

scala> (REF("x") DOT "y": Tree)     // x.y
[1m[34mres15[0m: [1m[32mtreehugger.forest.Tree[0m = Select(Ident(x),y)

scala> val tree = (REF("x") DOT "y").tree
[1m[34mtree[0m: [1m[32mtreehugger.forest.Select[0m = Select(Ident(x),y)

scala> treeToString(tree)
[1m[34mres16[0m: [1m[32mString[0m = x.y

This 

References to this are written using THIS or THIS(sym|"C"):

scala> THIS                         // this
[1m[34mres17[0m: [1m[32mtreehugger.forest.This[0m = This()

scala> val tree2 = THIS(sym.Address)
[1m[34mtree2[0m: [1m[32mtreehugger.forest.Tree[0m = This(Address)

scala> treeToString(tree2)
[1m[34mres18[0m: [1m[32mString[0m = Address.this

Super 

References to super are written using SUPER or SUPER(sym|"C"). This also returns an intermediate structure that can turn into a Tree by calling tree method or via implicit conversion:

scala> SUPER.tree                   // super
[1m[34mres19[0m: [1m[32mtreehugger.forest.Super[0m = Super(EmptyTree,)

scala> (SUPER("C"): Tree)           // C.super
[1m[34mres20[0m: [1m[32mtreehugger.forest.Tree[0m = Super(This(C),)

To add type parameter to super, call APPLYTYPE(sym|"T"):

scala> val tree3 = SUPER APPLYTYPE "T"
[1m[34mtree3[0m: [1m[32mtreehugger.forest.Super[0m = Super(EmptyTree,T)

scala> treeToString(tree3)
[1m[34mres21[0m: [1m[32mString[0m = super[T]