diff -r 5f5e165c9a57 -r a25da86f7c8c progs/pprint/tree.sc --- a/progs/pprint/tree.sc Sat Apr 02 01:52:43 2022 +0100 +++ b/progs/pprint/tree.sc Mon Aug 29 01:16:32 2022 +0200 @@ -1,9 +1,4 @@ -// scalatags -import ammonite.ops._ -import $ivy.`com.lihaoyi::scalatags:0.8.2` -import scalatags.Text.all._ -import scalatags.Text._ // regular expressions including records abstract class Rexp @@ -62,6 +57,11 @@ } +// scalatags +import $ivy.`com.lihaoyi::scalatags:0.8.2` +import scalatags.Text.all._ +import scalatags.Text._ + def pp(r: Rexp) : TypedTag[String] = r match { case CHAR(c) => li(code(c.toString)) case ALT(r1, r2) => li(code("+"), ul(pp(r1), pp(r2))) @@ -104,6 +104,42 @@ @main def main(fname: String) = { - val content = index(List(r1)) - write.over(pwd / fname, content) + val content = index(List(r1, r2, evil2)) + os.write.over(os.pwd / fname, content) } + + + +// scalatags +import $ivy.`com.lihaoyi::scalatags:0.8.2` +import scalatags.Text.all._ +import scalatags.Text._ + +def pp(r: Rexp) : TypedTag[String] = r match { + case CHAR(c) => li(code(c.toString)) + case ALTs(rs) => li(code("+"), ul(rs.map(pp))) + case SEQs(rs) => li(code(raw("·")), ul(rs.map(pp))) + case STAR(r1) => li(code("*"), ul(pp(r1))) + case ZERO => li(code("0")) + case ONE => li(code("1")) + //case SPECIAL(s) => li(code(raw(s))) +} + +def mktree(r: Rexp) = + ul(cls := "tree")(pp(r)) + + +def index(rs: List[Rexp]) = + html( + head(link(rel := "stylesheet", href := "./style.css")), + body(rs.map(mktree)) + ) + + +@main +def main(fname: String) = { + val r = ("a" | "ab" | "a") ~ ("c" | "bc") + val strs = List("","a","ab","abc") + val content = index(strs.map(s => ders(s.toList, r))) + os.write.over(os.pwd / fname, content) +}