src/Tools/jEdit/src/proofdocument/Token.scala
author wenzelm
Mon, 19 Jan 2009 20:33:26 +0100
changeset 34481 660c639870a4
parent 34407 aad6834ba380
child 34482 0f4b34445f40
permissions -rw-r--r--
replaced type parameter C by Command (thanks to globally simultaneous scope);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34407
aad6834ba380 added some headers and comments;
wenzelm
parents: 34390
diff changeset
     1
/*
aad6834ba380 added some headers and comments;
wenzelm
parents: 34390
diff changeset
     2
 * Document tokens as text ranges
aad6834ba380 added some headers and comments;
wenzelm
parents: 34390
diff changeset
     3
 *
aad6834ba380 added some headers and comments;
wenzelm
parents: 34390
diff changeset
     4
 * @author Johannes Hölzl, TU Munich
aad6834ba380 added some headers and comments;
wenzelm
parents: 34390
diff changeset
     5
 * @author Fabian Immler, TU Munich
aad6834ba380 added some headers and comments;
wenzelm
parents: 34390
diff changeset
     6
 */
aad6834ba380 added some headers and comments;
wenzelm
parents: 34390
diff changeset
     7
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
     8
package isabelle.proofdocument
34481
660c639870a4 replaced type parameter C by Command (thanks to globally simultaneous scope);
wenzelm
parents: 34407
diff changeset
     9
import isabelle.prover.Command
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    10
34388
23b8351ecbbe arbitrary type for tokens
immler@in.tum.de
parents: 34318
diff changeset
    11
object Token {
23b8351ecbbe arbitrary type for tokens
immler@in.tum.de
parents: 34318
diff changeset
    12
  object Kind {
23b8351ecbbe arbitrary type for tokens
immler@in.tum.de
parents: 34318
diff changeset
    13
    val COMMAND_START = "COMMAND_START"
23b8351ecbbe arbitrary type for tokens
immler@in.tum.de
parents: 34318
diff changeset
    14
    val COMMENT = "COMMENT"
23b8351ecbbe arbitrary type for tokens
immler@in.tum.de
parents: 34318
diff changeset
    15
  }
34389
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    16
34481
660c639870a4 replaced type parameter C by Command (thanks to globally simultaneous scope);
wenzelm
parents: 34407
diff changeset
    17
  def checkStart(t : Token, P : (Int) => Boolean)
34389
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    18
    = t != null && P(t.start)
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    19
34481
660c639870a4 replaced type parameter C by Command (thanks to globally simultaneous scope);
wenzelm
parents: 34407
diff changeset
    20
  def checkStop(t : Token, P : (Int) => Boolean)
34389
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    21
    = t != null && P(t.stop)
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    22
34481
660c639870a4 replaced type parameter C by Command (thanks to globally simultaneous scope);
wenzelm
parents: 34407
diff changeset
    23
  def scan(s : Token, f : Token => Boolean) : Token = {
34389
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    24
    var current = s
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    25
    while (current != null) {
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    26
      val next = current.next
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    27
      if (next == null || f(next))
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    28
        return current
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    29
      current = next
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    30
    }
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    31
    return null
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    32
  }
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    33
34388
23b8351ecbbe arbitrary type for tokens
immler@in.tum.de
parents: 34318
diff changeset
    34
}
23b8351ecbbe arbitrary type for tokens
immler@in.tum.de
parents: 34318
diff changeset
    35
34481
660c639870a4 replaced type parameter C by Command (thanks to globally simultaneous scope);
wenzelm
parents: 34407
diff changeset
    36
class Token(var start : Int, var stop : Int, var kind : String) {
660c639870a4 replaced type parameter C by Command (thanks to globally simultaneous scope);
wenzelm
parents: 34407
diff changeset
    37
  var next : Token = null
660c639870a4 replaced type parameter C by Command (thanks to globally simultaneous scope);
wenzelm
parents: 34407
diff changeset
    38
  var previous : Token = null
660c639870a4 replaced type parameter C by Command (thanks to globally simultaneous scope);
wenzelm
parents: 34407
diff changeset
    39
  var command : Command = null
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    40
  
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    41
  def length = stop - start
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    42
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    43
  def shift(offset : Int, bottomClamp : Int) {
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    44
    start = bottomClamp max (start + offset)
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    45
    stop = bottomClamp max (stop + offset)
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    46
  }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    47
  
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    48
  override def hashCode() : Int = (31 + start) * 31 + stop
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    49
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    50
  override def equals(obj : Any) : Boolean = {
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    51
    if (super.equals(obj))
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    52
      return true;
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    53
    
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    54
    if (null == obj)
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    55
      return false;
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    56
    
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    57
    obj match {
34481
660c639870a4 replaced type parameter C by Command (thanks to globally simultaneous scope);
wenzelm
parents: 34407
diff changeset
    58
      case other: Token => 
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    59
        (start == other.start) && (stop == other.stop)
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    60
      case other: Any => false  
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    61
    }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    62
  }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    63
}