src/Pure/Tools/server.scala
changeset 67784 543e36ae489c
parent 67178 70576478bda9
child 67785 ad96390ceb5d
equal deleted inserted replaced
67783:839de121665c 67784:543e36ae489c
   173     def reply_ok(t: JSON.T) { reply(Server.Reply.OK, t) }
   173     def reply_ok(t: JSON.T) { reply(Server.Reply.OK, t) }
   174     def reply_error(t: JSON.T) { reply(Server.Reply.ERROR, t) }
   174     def reply_error(t: JSON.T) { reply(Server.Reply.ERROR, t) }
   175     def reply_error_message(message: String, more: (String, JSON.T)*): Unit =
   175     def reply_error_message(message: String, more: (String, JSON.T)*): Unit =
   176       reply_error(Map("message" -> message) ++ more)
   176       reply_error(Map("message" -> message) ++ more)
   177 
   177 
   178     val Command_Line = """^(\S+)\s*(.*)$""".r
       
   179 
       
   180     reader.readLine() match {
   178     reader.readLine() match {
   181       case null =>
   179       case null =>
   182       case bad if bad != password => reply_error("Bad password -- connection closed")
   180       case bad if bad != password => reply_error("Bad password -- connection closed")
   183       case _ =>
   181       case _ =>
   184         var finished = false
   182         var finished = false
   185         while (!finished) {
   183         while (!finished) {
   186           reader.readLine() match {
   184           reader.readLine() match {
   187             case null => finished = true
   185             case null => finished = true
   188             case Command_Line(cmd, input) =>
   186             case line =>
       
   187               val cmd = line.takeWhile(c => Symbol.is_ascii_letter(c) || Symbol.is_ascii_letdig(c))
       
   188               val input = line.substring(cmd.length).dropWhile(Symbol.is_ascii_blank(_))
   189               Server.commands.get(cmd) match {
   189               Server.commands.get(cmd) match {
   190                 case None => reply_error("Unknown command " + quote(cmd))
   190                 case None => reply_error("Bad command " + quote(cmd))
   191                 case Some(body) =>
   191                 case Some(body) =>
   192                   proper_string(input) getOrElse "{}" match {
   192                   proper_string(input) getOrElse "{}" match {
   193                     case JSON.Format(arg) =>
   193                     case JSON.Format(arg) =>
   194                       if (body.isDefinedAt(arg)) {
   194                       if (body.isDefinedAt(arg)) {
   195                         try { reply_ok(body(arg)) }
   195                         try { reply_ok(body(arg)) }