src/Tools/jEdit/src/prover/Command.scala
changeset 34717 3f32e08bbb6c
parent 34708 611864f2729d
child 34724 b1079c3ba1da
equal deleted inserted replaced
34716:b8f2b44529fd 34717:3f32e08bbb6c
    17 import isabelle.XML
    17 import isabelle.XML
    18 
    18 
    19 
    19 
    20 trait Accumulator extends Actor
    20 trait Accumulator extends Actor
    21 {
    21 {
    22 
       
    23   start() // start actor
    22   start() // start actor
    24 
    23 
    25   protected var _state: State
    24   protected var _state: State
    26   def state = _state
    25   def state = _state
    27 
    26 
    42     val UNPROCESSED = Value("UNPROCESSED")
    41     val UNPROCESSED = Value("UNPROCESSED")
    43     val FINISHED = Value("FINISHED")
    42     val FINISHED = Value("FINISHED")
    44     val FAILED = Value("FAILED")
    43     val FAILED = Value("FAILED")
    45   }
    44   }
    46 
    45 
    47   case object RootInfo
       
    48   case class HighlightInfo(highlight: String) { override def toString = highlight }
    46   case class HighlightInfo(highlight: String) { override def toString = highlight }
    49   case class TypeInfo(type_kind: String) { override def toString = type_kind }
    47   case class TypeInfo(ty: String)
    50   case class RefInfo(file: Option[String], line: Option[Int],
    48   case class RefInfo(file: Option[String], line: Option[Int],
    51     command_id: Option[String], offset: Option[Int]) {
    49     command_id: Option[String], offset: Option[Int])
    52       override def toString = (file, line, command_id, offset).toString
       
    53     }
       
    54 }
    50 }
    55 
    51 
    56 
    52 
    57 class Command(
    53 class Command(
    58   val tokens: List[Token],
    54     val tokens: List[Token],
    59   val starts: Map[Token, Int],
    55     val starts: Map[Token, Int],
    60   change_receiver: Actor) extends Accumulator
    56   change_receiver: Actor) extends Accumulator
    61 {
    57 {
    62   require(!tokens.isEmpty)
    58   require(!tokens.isEmpty)
    63 
    59 
    64   val id = Isabelle.system.id()
    60   val id = Isabelle.system.id()
    71 
    67 
    72   override def toString = name
    68   override def toString = name
    73 
    69 
    74   val name = tokens.head.content
    70   val name = tokens.head.content
    75   val content: String = Token.string_from_tokens(tokens, starts)
    71   val content: String = Token.string_from_tokens(tokens, starts)
       
    72   def content(i: Int, j: Int): String = content.substring(i, j)
    76   val symbol_index = new Symbol.Index(content)
    73   val symbol_index = new Symbol.Index(content)
    77 
    74 
    78   def start(doc: ProofDocument) = doc.token_start(tokens.first)
    75   def start(doc: ProofDocument) = doc.token_start(tokens.first)
    79   def stop(doc: ProofDocument) = doc.token_start(tokens.last) + tokens.last.length
    76   def stop(doc: ProofDocument) = doc.token_start(tokens.last) + tokens.last.length
    80 
    77 
    83   protected override var _state = new State(this)
    80   protected override var _state = new State(this)
    84 
    81 
    85 
    82 
    86   /* markup */
    83   /* markup */
    87 
    84 
    88   lazy val empty_root_node =
    85   lazy val empty_markup = new Markup_Text(Nil, content)
    89     new MarkupNode(0, starts(tokens.last) - starts(tokens.first) + tokens.last.length,
       
    90       content, Command.RootInfo, Nil)
       
    91 
    86 
    92   def markup_node(begin: Int, end: Int, info: Any): MarkupNode =
    87   def markup_node(begin: Int, end: Int, info: Any): Markup_Tree =
    93   {
    88   {
    94     val start = symbol_index.decode(begin)
    89     val start = symbol_index.decode(begin)
    95     val stop = symbol_index.decode(end)
    90     val stop = symbol_index.decode(end)
    96     new MarkupNode(start, stop, content.substring(start, stop), info, Nil)
    91     new Markup_Tree(new Markup_Node(start, stop, info), Nil)
    97   }
    92   }
    98 
    93 
    99 
    94 
   100   /* results, markup, ... */
    95   /* results, markup, ... */
   101 
    96 
   104     doc.states.getOrElse(this, empty_cmd_state)
    99     doc.states.getOrElse(this, empty_cmd_state)
   105 
   100 
   106   def status(doc: ProofDocument) = cmd_state(doc).state.status
   101   def status(doc: ProofDocument) = cmd_state(doc).state.status
   107   def result_document(doc: ProofDocument) = cmd_state(doc).result_document
   102   def result_document(doc: ProofDocument) = cmd_state(doc).result_document
   108   def markup_root(doc: ProofDocument) = cmd_state(doc).markup_root
   103   def markup_root(doc: ProofDocument) = cmd_state(doc).markup_root
   109   def highlight_node(doc: ProofDocument) = cmd_state(doc).highlight_node
   104   def highlight(doc: ProofDocument) = cmd_state(doc).highlight
   110   def type_at(doc: ProofDocument, offset: Int) = cmd_state(doc).type_at(offset)
   105   def type_at(doc: ProofDocument, offset: Int) = cmd_state(doc).type_at(offset)
   111   def ref_at(doc: ProofDocument, offset: Int) = cmd_state(doc).ref_at(offset)
   106   def ref_at(doc: ProofDocument, offset: Int) = cmd_state(doc).ref_at(offset)
   112 }
   107 }
   113 
   108 
   114 
   109 
   122         case Nil => XML.Elem("message", Nil, Nil)
   117         case Nil => XML.Elem("message", Nil, Nil)
   123         case List(elem) => elem
   118         case List(elem) => elem
   124         case elems => XML.Elem("messages", Nil, elems)
   119         case elems => XML.Elem("messages", Nil, elems)
   125       }, "style")
   120       }, "style")
   126 
   121 
   127   def markup_root: MarkupNode =
   122   def markup_root: Markup_Text =
   128     (command.state.markup_root /: state.markup_root.children)(_ + _)
   123     (command.state.markup_root /: state.markup_root.markup)(_ + _)
   129 
   124 
   130   def type_at(pos: Int): String = state.type_at(pos)
   125   def type_at(pos: Int): Option[String] = state.type_at(pos)
   131 
   126 
   132   def ref_at(pos: Int): Option[MarkupNode] = state.ref_at(pos)
   127   def ref_at(pos: Int): Option[Markup_Node] = state.ref_at(pos)
   133 
   128 
   134   def highlight_node: MarkupNode =
   129   def highlight: Markup_Text =
   135     (command.state.highlight_node /: state.highlight_node.children)(_ + _)
   130     (command.state.highlight /: state.highlight.markup)(_ + _)
   136 }
   131 }