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
res0: treehugger.forest.Literal = Literal(Constant(1))

scala> LIT(1L)                      // 1L
res1: treehugger.forest.Literal = Literal(Constant(1))

scala> LIT(1.23)                    // 1.23
res2: treehugger.forest.Literal = Literal(Constant(1.23))

scala> LIT(1.23F)                   // 1.23F
res3: treehugger.forest.Literal = Literal(Constant(1.23))

scala> LIT('H')                     // 'H'
res4: treehugger.forest.Literal = Literal(Constant(H))

scala> LIT("H")                     // "H"
res5: treehugger.forest.Literal = Literal(Constant(H))

scala> LIT('Sym)                    // 'Sym
res6: treehugger.forest.Literal = Literal(Constant('Sym))

scala> TRUE                         // true
res7: treehugger.forest.Literal = Literal(Constant(true))

scala> FALSE                        // false
res8: treehugger.forest.Literal = Literal(Constant(false))

scala> NULL                         // null
res9: treehugger.forest.Literal = Literal(Constant(null))

scala> UNIT                         // ()
res10: treehugger.forest.Literal = 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 module sym

scala> REF("x")                     // x
res11: treehugger.forest.Ident = Ident(x)

scala> REF(sym.x)                   // x
res12: treehugger.forest.Tree = 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
res13: treehugger.forest.Select = Select(Ident(x),y)

scala> (sym.x DOT "y": Tree)        // x.y
res14: treehugger.forest.Tree = Select(Ident(x),y)

scala> (REF("x") DOT "y": Tree)     // x.y
res15: treehugger.forest.Tree = Select(Ident(x),y)

scala> val tree = (REF("x") DOT "y").tree
tree: treehugger.forest.Select = Select(Ident(x),y)

scala> treeToString(tree)
res16: String = x.y

This 

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

scala> THIS                         // this
res17: treehugger.forest.This = This()

scala> val tree2 = THIS(sym.Address)
tree2: treehugger.forest.Tree = This(Address)

scala> treeToString(tree2)
res18: String = 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
res19: treehugger.forest.Super = Super(EmptyTree,)

scala> (SUPER("C"): Tree)           // C.super
res20: treehugger.forest.Tree = Super(This(C),)

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

scala> val tree3 = SUPER APPLYTYPE "T"
tree3: treehugger.forest.Super = Super(EmptyTree,T)

scala> treeToString(tree3)
res21: String = super[T]