ScalaMatsuri2020 Scalaひどいコード選手権用 JSON parser だったもの
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type S=Seq[_] | |
def o(a:Seq[(_,_)],? :S):(Map[_,_],S)= ?match{case'}'+:r=>a.toMap->r | |
case','+:r=>o(a,r)case? =>val m=""""(.+?)":(.+)""".r | |
val m(k,t)= ?mkString | |
val(v,r)=p()(t.toSeq) | |
o(a:+(k->v),r)} | |
def y(a:S):S=>(S,S)={case']'+:r=>a->r | |
case','+:r=>y(a)(r)case s=>val(v,r)=p()(s) | |
y(a:+v)(r)} | |
def u(a:S,b:S):(S,S)=b match{case c+:r=>c match{case'}'|']'=>a->b | |
case','=>a->r | |
case x=>u(a:+c,r)}case _ =>a->Nil} | |
def p(a:S=""):S=>(Any,S)={case'{'+:r=>o(Nil,r)case'['+:r=>y("")(r)case','+:r=>a->r | |
case s=>val (t,r)= u("",s) | |
v(t.mkString)->r} | |
def v(? :String):Any= ?match{case"null"|"true"|"false"=> ?case? => ?toSeq match{case'"'+:t:+'"'=>t | |
case a=>if(?toSet('.'))?toDouble else?toInt}} | |
print(p()(io.StdIn.readLine.replaceAll("\\s",""))_1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment