src/Pure/PIDE/text.scala
changeset 38568 f117ba49a59c
parent 38565 32b924a832c4
child 38570 3fa11fb01f86
equal deleted inserted replaced
38567:b670faa807c9 38568:f117ba49a59c
    15   type Offset = Int
    15   type Offset = Int
    16 
    16 
    17 
    17 
    18   /* range -- with total quasi-ordering */
    18   /* range -- with total quasi-ordering */
    19 
    19 
       
    20   object Range
       
    21   {
       
    22     def apply(start: Offset): Range = Range(start, start)
       
    23   }
       
    24 
    20   sealed case class Range(val start: Offset, val stop: Offset)
    25   sealed case class Range(val start: Offset, val stop: Offset)
    21   {
    26   {
    22     // denotation: {start} Un {i. start < i & i < stop}
    27     // denotation: {start} Un {i. start < i & i < stop}
    23     require(start <= stop)
    28     require(start <= stop)
    24 
    29 
    28     def +(i: Offset): Range = map(_ + i)
    33     def +(i: Offset): Range = map(_ + i)
    29     def contains(i: Offset): Boolean = start == i || start < i && i < stop
    34     def contains(i: Offset): Boolean = start == i || start < i && i < stop
    30     def contains(that: Range): Boolean = this.contains(that.start) && that.stop <= this.stop
    35     def contains(that: Range): Boolean = this.contains(that.start) && that.stop <= this.stop
    31     def overlaps(that: Range): Boolean = this.contains(that.start) || that.contains(this.start)
    36     def overlaps(that: Range): Boolean = this.contains(that.start) || that.contains(this.start)
    32     def compare(that: Range): Int = if (overlaps(that)) 0 else this.start compare that.start
    37     def compare(that: Range): Int = if (overlaps(that)) 0 else this.start compare that.start
    33 
       
    34     def start_range: Range = Range(start, start)
       
    35     def stop_range: Range = Range(stop, stop)
       
    36 
    38 
    37     def restrict(that: Range): Range =
    39     def restrict(that: Range): Range =
    38       Range(this.start max that.start, this.stop min that.stop)
    40       Range(this.start max that.start, this.stop min that.stop)
    39   }
    41   }
    40 
    42