summaryrefslogtreecommitdiff
path: root/test/pending/run/reify_addressbook.scala
diff options
context:
space:
mode:
authorAleksandar Prokopec <aleksandar.prokopec@gmail.com>2011-12-07 14:53:37 +0100
committerAleksandar Prokopec <aleksandar.prokopec@gmail.com>2011-12-07 14:53:37 +0100
commit014a13d2be634bb3ab3468d0c071a9a870a9a9b0 (patch)
tree491ad18ca796a70b34be1d4732b80c371bfd650d /test/pending/run/reify_addressbook.scala
parenta36175feb5bfce59909fa4f3d9d5df6753b6ee3a (diff)
parent332fec96e31840878bed41dd7b5314b97d8da7c2 (diff)
downloadscala-014a13d2be634bb3ab3468d0c071a9a870a9a9b0.tar.gz
scala-014a13d2be634bb3ab3468d0c071a9a870a9a9b0.tar.bz2
scala-014a13d2be634bb3ab3468d0c071a9a870a9a9b0.zip
Merge branch 'master' of https://github.com/scala/scala into execution-context
Diffstat (limited to 'test/pending/run/reify_addressbook.scala')
-rw-r--r--test/pending/run/reify_addressbook.scala71
1 files changed, 71 insertions, 0 deletions
diff --git a/test/pending/run/reify_addressbook.scala b/test/pending/run/reify_addressbook.scala
new file mode 100644
index 0000000000..225f26b75e
--- /dev/null
+++ b/test/pending/run/reify_addressbook.scala
@@ -0,0 +1,71 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ case class Person(name: String, age: Int)
+
+ /** An AddressBook takes a variable number of arguments
+ * which are accessed as a Sequence
+ */
+ class AddressBook(a: Person*) {
+ private val people: List[Person] = a.toList
+
+ /** Serialize to XHTML. Scala supports XML literals
+ * which may contain Scala expressions between braces,
+ * which are replaced by their evaluation
+ */
+ def toXHTML =
+ <table cellpadding="2" cellspacing="0">
+ <tr>
+ <th>Name</th>
+ <th>Age</th>
+ </tr>
+ { for (p <- people) yield
+ <tr>
+ <td> { p.name } </td>
+ <td> { p.age.toString() } </td>
+ </tr>
+ }
+ </table>;
+ }
+
+ /** We introduce CSS using raw strings (between triple
+ * quotes). Raw strings may contain newlines and special
+ * characters (like \) are not interpreted.
+ */
+ val header =
+ <head>
+ <title>
+ { "My Address Book" }
+ </title>
+ <style type="text/css"> {
+ """table { border-right: 1px solid #cccccc; }
+ th { background-color: #cccccc; }
+ td { border-left: 1px solid #acacac; }
+ td { border-bottom: 1px solid #acacac;"""}
+ </style>
+ </head>;
+
+ val people = new AddressBook(
+ Person("Tom", 20),
+ Person("Bob", 22),
+ Person("James", 19));
+
+ val page =
+ <html>
+ { header }
+ <body>
+ { people.toXHTML }
+ </body>
+ </html>;
+
+ println(page)
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ toolbox.runExpr(ttree)
+}