src/Pure/PIDE/protocol.scala
changeset 70664 2bd9e30183b1
parent 70661 9c4809ec28ef
child 70665 94442fce40a5
equal deleted inserted replaced
70663:4a358f8c7cb7 70664:2bd9e30183b1
   243   /* interned items */
   243   /* interned items */
   244 
   244 
   245   def define_blob(digest: SHA1.Digest, bytes: Bytes): Unit =
   245   def define_blob(digest: SHA1.Digest, bytes: Bytes): Unit =
   246     protocol_command_raw("Document.define_blob", List(Bytes(digest.toString), bytes))
   246     protocol_command_raw("Document.define_blob", List(Bytes(digest.toString), bytes))
   247 
   247 
   248   def define_command(command: Command)
   248   private def encode_command(command: Command): (String, String, String, String, List[String]) =
   249   {
   249   {
       
   250     import XML.Encode._
       
   251 
   250     val blobs_yxml =
   252     val blobs_yxml =
   251     {
   253     {
   252       import XML.Encode._
       
   253       val encode_blob: T[Command.Blob] =
   254       val encode_blob: T[Command.Blob] =
   254         variant(List(
   255         variant(List(
   255           { case Exn.Res((a, b)) =>
   256           { case Exn.Res((a, b)) =>
   256               (Nil, pair(string, option(string))((a.node, b.map(p => p._1.toString)))) },
   257               (Nil, pair(string, option(string))((a.node, b.map(p => p._1.toString)))) },
   257           { case Exn.Exn(e) => (Nil, string(Exn.message(e))) }))
   258           { case Exn.Exn(e) => (Nil, string(Exn.message(e))) }))
   258 
   259 
   259       Symbol.encode_yxml(pair(list(encode_blob), int)(command.blobs, command.blobs_index))
   260       Symbol.encode_yxml(pair(list(encode_blob), int)(command.blobs, command.blobs_index))
   260     }
   261     }
   261 
   262 
   262     val toks = command.span.content
       
   263     val toks_yxml =
   263     val toks_yxml =
   264     {
   264     {
   265       import XML.Encode._
       
   266       val encode_tok: T[Token] = (tok => pair(int, int)((tok.kind.id, Symbol.length(tok.source))))
   265       val encode_tok: T[Token] = (tok => pair(int, int)((tok.kind.id, Symbol.length(tok.source))))
   267       Symbol.encode_yxml(list(encode_tok)(toks))
   266       Symbol.encode_yxml(list(encode_tok)(command.span.content))
   268     }
   267     }
   269 
   268     val toks_sources = command.span.content.map(tok => Symbol.encode(tok.source))
   270     protocol_command_args("Document.define_command",
   269 
   271       Document_ID(command.id) :: Symbol.encode(command.span.name) :: blobs_yxml :: toks_yxml ::
   270     (Document_ID(command.id), Symbol.encode(command.span.name), blobs_yxml, toks_yxml, toks_sources)
   272         toks.map(tok => Symbol.encode(tok.source)))
   271   }
       
   272 
       
   273   def define_command(command: Command)
       
   274   {
       
   275     val (command_id, name, blobs_yxml, toks_yxml, toks_sources) = encode_command(command)
       
   276     protocol_command_args(
       
   277       "Document.define_command", command_id :: name :: blobs_yxml :: toks_yxml :: toks_sources)
       
   278   }
       
   279 
       
   280   def define_commands(commands: List[Command])
       
   281   {
       
   282     protocol_command_args("Document.define_commands",
       
   283       commands.map(command =>
       
   284       {
       
   285         import XML.Encode._
       
   286         val (command_id, name, blobs_yxml, toks_yxml, toks_sources) = encode_command(command)
       
   287         val body =
       
   288           pair(string, pair(string, pair(string, pair(string, list(string)))))(
       
   289             command_id, (name, (blobs_yxml, (toks_yxml, toks_sources))))
       
   290         YXML.string_of_body(body)
       
   291       }))
       
   292   }
       
   293 
       
   294   def define_commands_bulk(commands: List[Command])
       
   295   {
       
   296     val (irregular, regular) = commands.partition(command => YXML.detect(command.source))
       
   297     irregular.foreach(define_command(_))
       
   298     regular match {
       
   299       case Nil =>
       
   300       case List(command) => define_command(command)
       
   301       case _ => define_commands(regular)
       
   302     }
   273   }
   303   }
   274 
   304 
   275 
   305 
   276   /* execution */
   306   /* execution */
   277 
   307