progs/display/display.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Sun, 27 Sep 2020 09:15:32 +0100
changeset 764 6718ef6143b8
parent 738 084e2843f478
child 873 a25da86f7c8c
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
738
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
import scalatags.Text.all._
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
import scalatags.Text._
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
import scala.util.Random
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
object MinimalApplication extends cask.MainRoutes{
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
  abstract class Rexp 
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
  case object ZERO extends Rexp
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
  case object ONE extends Rexp
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
  case class CHAR(c: Char) extends Rexp
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
  case class ALT(r1: Rexp, r2: Rexp) extends Rexp 
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
  case class SEQ(r1: Rexp, r2: Rexp) extends Rexp 
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
  case class STAR(r: Rexp) extends Rexp 
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
  val evil2 = ALT(SEQ(STAR(STAR(CHAR('a'))), CHAR('b')), ONE)
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
  def pp(r: Rexp) : TypedTag[String] = r match {
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
    case CHAR(c) => li(code(c.toString))
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
    case ALT(r1, r2) => li(code("+"), ul(pp(r1), pp(r2)))
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
    case SEQ(r1, r2) => li(code("o"), ul(pp(r1), pp(r2)))
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
    case STAR(r1) => li(code("*"), ul(pp(r1)))
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
    case ZERO => li(code("0"))
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
    case ONE => li(code(div(style :="line-height:50%")
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
                           ("1",br, 
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
                            div(color:="blue", fontSize:=6.pt)("0101010101"))))
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
  } 
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
  abstract class ARexp 
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
  case object AZERO extends ARexp
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
  case class AONE(bs: String) extends ARexp
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
  case class ACHAR(bs:String, c: Char) extends ARexp
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
  case class AALT(bs:String, r1: ARexp, r2: ARexp) extends ARexp 
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
  case class ASEQ(bs: String,r1: ARexp, r2: ARexp) extends ARexp 
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
  case class ASTAR(bs:String,r: ARexp) extends ARexp 
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
  def node(s: String, bs: String) = {
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
    if (bs == "")
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
      code(div(div(style :="line-height:75%")(s, br, div(color:="blue", fontSize:=6.pt)(raw("&nbsp")))))
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
    else
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
      code(div(div(style :="line-height:75%")(s, br, div(color:="blue", fontSize:=6.pt)(bs))))
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
  }
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
  
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
  val aevil2 = AALT("", ASEQ(" ",ASTAR("111",ASTAR("0",ACHAR("00",'a'))), ACHAR("00",'b')), AONE("01"))
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
  def ppa(r: ARexp) : TypedTag[String] = r match {
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
    case ACHAR(bs, c) => li(node(c.toString, bs))
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
    case AALT(bs, r1, r2) => li(node("+", bs), ul(ppa(r1), ppa(r2)))
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
    case ASEQ(bs, r1, r2) => li(node("o", bs), ul(ppa(r1), ppa(r2)))
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
    case ASTAR(bs, r1) => li(node("*", bs), ul(ppa(r1)))
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
    case AZERO => li(node("0", ""))
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
    case AONE(bs) => li(node("1", bs))
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
  } 
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
  val bootstrap = "https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.css"
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
  var cnt = 0
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
  @cask.get("/")
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
  def hello() = 
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
      doctype("html")(
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
      html(
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
        head(link(rel := "stylesheet", href := bootstrap),
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
             link(rel := "stylesheet", href := "static/style.css")), 
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
        body(
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
          div(cls := "container")( 
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
            h1(s"Hello"),
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
            i(color.green)(s"$cnt"),
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
            form(action := "/", method := "post")(
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
              button(`type` := "submit", name := "name", value := 1)(s"1"),
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
            ),
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
            ul(cls := "tree")(pp(evil2)),
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
	    ul(cls := "tree")(ppa(aevil2))
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
          )
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
        )
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
      )
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
    )
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
  @cask.postForm("/")
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
  def answer(name: String) = {
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
    cnt = cnt + 1
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
    hello()
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
  }
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
  //@cask.staticFiles("/static/")
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
  //def staticFileRoutes() = "static"
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
  @cask.staticResources("/static")
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
  def staticResourceRoutes() = "static"
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
  initialize()
084e2843f478 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
}