Literals are the basic foundation of treehugger DSL. Numeric literals, String
, and symbols are written by wrapping a Scala literal with LIT()
:
scala> import treehugger.forest._, definitions._, treehuggerDSL._
import treehugger.forest._
import definitions._
import treehuggerDSL._
scala> LIT(1) // Int
[1m[34mres0[0m: [1m[32mtreehugger.forest.Literal[0m = Literal(Constant(1))
scala> LIT(1L) // Long
[1m[34mres1[0m: [1m[32mtreehugger.forest.Literal[0m = Literal(Constant(1))
scala> LIT(1.23) // Double
[1m[34mres2[0m: [1m[32mtreehugger.forest.Literal[0m = Literal(Constant(1.23))
scala> LIT(1.23F) // Float
[1m[34mres3[0m: [1m[32mtreehugger.forest.Literal[0m = Literal(Constant(1.23))
scala> LIT('H') // Char
[1m[34mres4[0m: [1m[32mtreehugger.forest.Literal[0m = Literal(Constant(H))
scala> LIT("H") // String
[1m[34mres5[0m: [1m[32mtreehugger.forest.Literal[0m = Literal(Constant(H))
scala> LIT('Sym) // scala.Symbol
[1m[34mres6[0m: [1m[32mtreehugger.forest.Literal[0m = Literal(Constant('Sym))
Boolean literals, ()
, and null
are written as follows:
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(()))