src/Pure/PIDE/protocol.scala
changeset 72946 9329abcdd651
parent 72878 80465b791f95
child 73340 0ffcad1f6130
equal deleted inserted replaced
72945:756b9cb8a176 72946:9329abcdd651
   319   /* interned items */
   319   /* interned items */
   320 
   320 
   321   def define_blob(digest: SHA1.Digest, bytes: Bytes): Unit =
   321   def define_blob(digest: SHA1.Digest, bytes: Bytes): Unit =
   322     protocol_command_raw("Document.define_blob", List(Bytes(digest.toString), bytes))
   322     protocol_command_raw("Document.define_blob", List(Bytes(digest.toString), bytes))
   323 
   323 
   324   private def encode_command(command: Command): (String, String, String, String, List[String]) =
   324   private def encode_command(resources: Resources, command: Command)
       
   325     : (String, String, String, String, String, List[String]) =
   325   {
   326   {
   326     import XML.Encode._
   327     import XML.Encode._
       
   328 
       
   329     val parents = command.theory_parents(resources).map(name => File.standard_url(name.node))
       
   330     val parents_yxml = Symbol.encode_yxml(list(string)(parents))
   327 
   331 
   328     val blobs_yxml =
   332     val blobs_yxml =
   329     {
   333     {
   330       val encode_blob: T[Exn.Result[Command.Blob]] =
   334       val encode_blob: T[Exn.Result[Command.Blob]] =
   331         variant(List(
   335         variant(List(
   342       val encode_tok: T[Token] = (tok => pair(int, int)((tok.kind.id, Symbol.length(tok.source))))
   346       val encode_tok: T[Token] = (tok => pair(int, int)((tok.kind.id, Symbol.length(tok.source))))
   343       Symbol.encode_yxml(list(encode_tok)(command.span.content))
   347       Symbol.encode_yxml(list(encode_tok)(command.span.content))
   344     }
   348     }
   345     val toks_sources = command.span.content.map(tok => Symbol.encode(tok.source))
   349     val toks_sources = command.span.content.map(tok => Symbol.encode(tok.source))
   346 
   350 
   347     (Document_ID(command.id), Symbol.encode(command.span.name), blobs_yxml, toks_yxml, toks_sources)
   351     (Document_ID(command.id), Symbol.encode(command.span.name), parents_yxml,
   348   }
   352       blobs_yxml, toks_yxml, toks_sources)
   349 
   353   }
   350   def define_command(command: Command)
   354 
   351   {
   355   def define_command(resources: Resources, command: Command)
   352     val (command_id, name, blobs_yxml, toks_yxml, toks_sources) = encode_command(command)
   356   {
       
   357     val (command_id, name, parents_yxml, blobs_yxml, toks_yxml, toks_sources) =
       
   358       encode_command(resources, command)
   353     protocol_command_args(
   359     protocol_command_args(
   354       "Document.define_command", command_id :: name :: blobs_yxml :: toks_yxml :: toks_sources)
   360       "Document.define_command", command_id :: name :: parents_yxml :: blobs_yxml ::
   355   }
   361         toks_yxml :: toks_sources)
   356 
   362   }
   357   def define_commands(commands: List[Command])
   363 
       
   364   def define_commands(resources: Resources, commands: List[Command])
   358   {
   365   {
   359     protocol_command_args("Document.define_commands",
   366     protocol_command_args("Document.define_commands",
   360       commands.map(command =>
   367       commands.map(command =>
   361       {
   368       {
   362         import XML.Encode._
   369         import XML.Encode._
   363         val (command_id, name, blobs_yxml, toks_yxml, toks_sources) = encode_command(command)
   370         val (command_id, name, parents_yxml, blobs_yxml, toks_yxml, toks_sources) =
       
   371           encode_command(resources, command)
   364         val body =
   372         val body =
   365           pair(string, pair(string, pair(string, pair(string, list(string)))))(
   373           pair(string, pair(string, pair(string, pair(string, pair(string, list(string))))))(
   366             command_id, (name, (blobs_yxml, (toks_yxml, toks_sources))))
   374             command_id, (name, (parents_yxml, (blobs_yxml, (toks_yxml, toks_sources)))))
   367         YXML.string_of_body(body)
   375         YXML.string_of_body(body)
   368       }))
   376       }))
   369   }
   377   }
   370 
   378 
   371   def define_commands_bulk(commands: List[Command])
   379   def define_commands_bulk(resources: Resources, commands: List[Command])
   372   {
   380   {
   373     val (irregular, regular) = commands.partition(command => YXML.detect(command.source))
   381     val (irregular, regular) = commands.partition(command => YXML.detect(command.source))
   374     irregular.foreach(define_command)
   382     irregular.foreach(define_command(resources, _))
   375     regular match {
   383     regular match {
   376       case Nil =>
   384       case Nil =>
   377       case List(command) => define_command(command)
   385       case List(command) => define_command(resources, command)
   378       case _ => define_commands(regular)
   386       case _ => define_commands(resources, regular)
   379     }
   387     }
   380   }
   388   }
   381 
   389 
   382 
   390 
   383   /* execution */
   391   /* execution */