Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.67 KB | None | 0 0
  1. def left(e: Expr): String = {
  2.     "<li>" +
  3.       "<span class=\"junct\">" + e + "</span>" +
  4.     "</li>"
  5.   }
  6.  
  7.   def right(e: Expr): String = {
  8.     "<li>" +
  9.       "<span class=\"junct\">" + e + "</span>" +
  10.     "</li>"
  11.   }
  12.  
  13.   def symbol(): String = {
  14.     "<span class=\"turnstile\">=></span>"
  15.   }
  16.  
  17.   def renderSequent(e: Expr): String = {
  18.     val s = "<div id=\"" + Gensym.gensym + "\">" +
  19.         "<ul class=\"commaList\">" +
  20.           left(e) +
  21.         "</ul>" +
  22.         symbol() +
  23.         "<ul class=\"commaList\">" +
  24.           right(e) +
  25.         "</ul>" +
  26.       "</div>"
  27.       s
  28.   }
  29.  
  30.   def buildNode(e: Expr): String = {
  31.       "<table>" +
  32.         "<tbody>" +
  33.           "<tr>" +
  34.             "<td class=\"inference\">" + renderSequent(e) +
  35.             "</td>" +
  36.             "<td class=\"tagBox\">" +
  37.               "<div class=\"tag\">" +
  38.                 "<span class=\"explained\" id=\"iw-20\">" + "(->l)" + "</span>" +
  39.               "</div>" +
  40.             "</td>" +
  41.           "</tr>" +
  42.         "</tbody>" +
  43.       "</table>"
  44.   }
  45.  
  46.   def buildSibling(e: Expr): String = {
  47.     "<div class=\"sibling\">" +
  48.       "<span></span>" +
  49.       buildNode(e) +
  50.     "</div>"
  51.   }
  52.  
  53.   def processChildren(children: List[Tree[Expr]]): String = children match {
  54.     case Nil => ""
  55.     case sibling :: rest => sibling match {
  56.       case Tree(e, Nil) => buildSibling(e) + processChildren(rest)
  57.         case _ => "<div class=\"sibling\">" + renderTree(sibling)  + "</div>" +
  58.               processChildren(rest)
  59.     }
  60.   }
  61.  
  62.   def renderTree(t: Tree[Expr]): String = {
  63.     t match {
  64.     case Tree(e, Nil) => buildSibling(e)
  65.     case Tree(e, children) => {
  66.         "<div>" + processChildren(children) + "</div>" + buildNode(e)
  67.     }
  68.   }
  69.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement