src/Tools/jEdit/src/proofdocument/ProofDocument.scala
changeset 34674 f9b71bcf2eb7
parent 34667 3f20110dfe2f
child 34676 9e725d34df7b
equal deleted inserted replaced
34673:1a30c075c202 34674:f9b71bcf2eb7
     6  * @author Makarius
     6  * @author Makarius
     7  */
     7  */
     8 
     8 
     9 package isabelle.proofdocument
     9 package isabelle.proofdocument
    10 
    10 
       
    11 import scala.actors.Actor
       
    12 import scala.actors.Actor._
    11 import scala.collection.mutable.ListBuffer
    13 import scala.collection.mutable.ListBuffer
    12 import java.util.regex.Pattern
    14 import java.util.regex.Pattern
    13 import isabelle.prover.{Prover, Command}
    15 import isabelle.prover.{Prover, Command, Command_State}
    14 import isabelle.utils.LinearSet
    16 import isabelle.utils.LinearSet
    15 
    17 
    16 
    18 
    17 object ProofDocument
    19 object ProofDocument
    18 {
    20 {
    32       "`([^\\\\`]?(\\\\(.|\\z))?)*+(`|\\z)|" +
    34       "`([^\\\\`]?(\\\\(.|\\z))?)*+(`|\\z)|" +
    33       "[()\\[\\]{}:;]", Pattern.MULTILINE)
    35       "[()\\[\\]{}:;]", Pattern.MULTILINE)
    34 
    36 
    35   val empty =
    37   val empty =
    36     new ProofDocument(isabelle.jedit.Isabelle.system.id(),
    38     new ProofDocument(isabelle.jedit.Isabelle.system.id(),
    37       LinearSet(), Map(), LinearSet(), Map(), _ => false)
    39       LinearSet(), Map(), LinearSet(), Map(), _ => false,
       
    40       actor(loop(react{case _ =>}))) // ignoring actor
    38 
    41 
    39   type StructureChange = List[(Option[Command], Option[Command])]
    42   type StructureChange = List[(Option[Command], Option[Command])]
    40 
    43 
    41 }
    44 }
    42 
    45 
    44   val id: String,
    47   val id: String,
    45   val tokens: LinearSet[Token],
    48   val tokens: LinearSet[Token],
    46   val token_start: Map[Token, Int],
    49   val token_start: Map[Token, Int],
    47   val commands: LinearSet[Command],
    50   val commands: LinearSet[Command],
    48   var states: Map[Command, IsarDocument.State_ID],
    51   var states: Map[Command, IsarDocument.State_ID],
    49   is_command_keyword: String => Boolean)
    52   is_command_keyword: String => Boolean,
       
    53   change_receiver: Actor)
    50 {
    54 {
    51   import ProofDocument.StructureChange
    55   import ProofDocument.StructureChange
    52 
    56 
    53   def set_command_keyword(f: String => Boolean): ProofDocument =
    57   def set_command_keyword(f: String => Boolean): ProofDocument =
    54     new ProofDocument(id, tokens, token_start, commands, states, f)
    58     new ProofDocument(id, tokens, token_start, commands, states, f, change_receiver)
       
    59 
       
    60   def set_change_receiver(cr: Actor): ProofDocument =
       
    61     new ProofDocument(id, tokens, token_start, commands, states, is_command_keyword, cr)
    55 
    62 
    56   def content = Token.string_from_tokens(Nil ++ tokens, token_start)
    63   def content = Token.string_from_tokens(Nil ++ tokens, token_start)
    57 
    64 
    58 
    65 
    59   /** token view **/
    66   /** token view **/
   190       tokens match {
   197       tokens match {
   191         case Nil => Nil
   198         case Nil => Nil
   192         case t :: ts =>
   199         case t :: ts =>
   193           val (cmd, rest) =
   200           val (cmd, rest) =
   194             ts.span(t => t.kind != Token.Kind.COMMAND_START && t.kind != Token.Kind.COMMENT)
   201             ts.span(t => t.kind != Token.Kind.COMMAND_START && t.kind != Token.Kind.COMMENT)
   195           new Command(t :: cmd, new_token_start) :: tokens_to_commands(rest)
   202           new Command(t :: cmd, new_token_start, change_receiver) :: tokens_to_commands(rest)
   196       }
   203       }
   197     }
   204     }
   198 
   205 
   199     val split_begin =
   206     val split_begin =
   200       if (before_change.isDefined) {
   207       if (before_change.isDefined) {
   231     // build new document
   238     // build new document
   232     val new_commandset = commands.delete_between(cmd_before_change, cmd_after_change).
   239     val new_commandset = commands.delete_between(cmd_before_change, cmd_after_change).
   233         insert_after(cmd_before_change, inserted_commands)
   240         insert_after(cmd_before_change, inserted_commands)
   234 
   241 
   235     val doc =
   242     val doc =
   236       new ProofDocument(new_id, new_tokenset, new_token_start,
   243       new ProofDocument(new_id, new_tokenset, new_token_start, new_commandset,
   237         new_commandset, states -- removed_commands, is_command_keyword)
   244         states -- removed_commands, is_command_keyword, change_receiver)
   238 
   245 
   239     val removes =
   246     val removes =
   240       for (cmd <- removed_commands) yield (cmd_before_change -> None)
   247       for (cmd <- removed_commands) yield (cmd_before_change -> None)
   241     val inserts =
   248     val inserts =
   242       for (cmd <- inserted_commands) yield (doc.commands.prev(cmd) -> Some(cmd))
   249       for (cmd <- inserted_commands) yield (doc.commands.prev(cmd) -> Some(cmd))