src/Pure/PIDE/command.scala
changeset 56463 013dfac0811a
parent 56462 b64b0cb845fe
child 56468 30128d1acfbc
equal deleted inserted replaced
56462:b64b0cb845fe 56463:013dfac0811a
    59   /* source chunks */
    59   /* source chunks */
    60 
    60 
    61   abstract class Chunk
    61   abstract class Chunk
    62   {
    62   {
    63     def name: Chunk.Name
    63     def name: Chunk.Name
    64     def length: Int
       
    65     def range: Text.Range
    64     def range: Text.Range
    66     def symbol_index: Symbol.Index
    65     def symbol_index: Symbol.Index
       
    66 
       
    67     private lazy val hash: Int = (name, range, symbol_index).hashCode
       
    68     override def hashCode: Int = hash
       
    69     override def equals(that: Any): Boolean =
       
    70       that match {
       
    71         case other: Chunk =>
       
    72           hash == other.hash &&
       
    73           name == other.name &&
       
    74           range == other.range &&
       
    75           symbol_index == other.symbol_index
       
    76         case _ => false
       
    77       }
       
    78     override def toString: String = "Command.Chunk(" + name + ")"
    67 
    79 
    68     def decode(symbol_offset: Symbol.Offset): Text.Offset = symbol_index.decode(symbol_offset)
    80     def decode(symbol_offset: Symbol.Offset): Text.Offset = symbol_index.decode(symbol_offset)
    69     def decode(symbol_range: Symbol.Range): Text.Range = symbol_index.decode(symbol_range)
    81     def decode(symbol_range: Symbol.Range): Text.Range = symbol_index.decode(symbol_range)
    70     def incorporate(symbol_range: Symbol.Range): Option[Text.Range] =
    82     def incorporate(symbol_range: Symbol.Range): Option[Text.Range] =
    71     {
    83     {
    82   {
    94   {
    83     sealed abstract class Name
    95     sealed abstract class Name
    84     case object Self extends Name
    96     case object Self extends Name
    85     case class File_Name(file_name: String) extends Name
    97     case class File_Name(file_name: String) extends Name
    86 
    98 
    87     class File(
    99     class File(file_name: String, text: CharSequence) extends Chunk
    88       file_name: String,
       
    89       text: CharSequence  // non-persistent!
       
    90     ) extends Chunk
       
    91     {
   100     {
    92       val name = Chunk.File_Name(file_name)
   101       val name = Chunk.File_Name(file_name)
    93       val length = text.length
   102       val range = Text.Range(0, text.length)
    94       val range = Text.Range(0, length)
       
    95       val symbol_index = Symbol.Index(text)
   103       val symbol_index = Symbol.Index(text)
    96 
       
    97       private val hash: Int = (name, length, symbol_index).hashCode
       
    98       override def hashCode: Int = hash
       
    99       override def equals(that: Any): Boolean =
       
   100         that match {
       
   101           case other: File =>
       
   102             hash == other.hash &&
       
   103             name == other.name &&
       
   104             length == other.length &&
       
   105             symbol_index == other.symbol_index
       
   106           case _ => false
       
   107         }
       
   108       override def toString: String = "Command.Chunk.File(" + file_name + ")"
       
   109     }
   104     }
   110   }
   105   }
   111 
   106 
   112 
   107 
   113   /* markup */
   108   /* markup */
   395   def source(range: Text.Range): String = source.substring(range.start, range.stop)
   390   def source(range: Text.Range): String = source.substring(range.start, range.stop)
   396 
   391 
   397   val chunk: Command.Chunk =
   392   val chunk: Command.Chunk =
   398     new Command.Chunk {
   393     new Command.Chunk {
   399       def name: Command.Chunk.Name = Command.Chunk.Self
   394       def name: Command.Chunk.Name = Command.Chunk.Self
   400       def length: Int = Command.this.length
       
   401       def range: Text.Range = Command.this.range
   395       def range: Text.Range = Command.this.range
   402       lazy val symbol_index = Symbol.Index(source)
   396       lazy val symbol_index = Symbol.Index(source)
   403     }
   397     }
   404 
   398 
   405   val chunks: Map[Command.Chunk.Name, Command.Chunk] =
   399   val chunks: Map[Command.Chunk.Name, Command.Chunk] =