src/Tools/jEdit/src/proofdocument/Token.scala
author wenzelm
Mon, 19 Jan 2009 21:04:30 +0100
changeset 34482 0f4b34445f40
parent 34481 660c639870a4
child 34483 0923926022d7
permissions -rw-r--r--
turned Token.Kind into Enumeration;
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 {
34482
0f4b34445f40 turned Token.Kind into Enumeration;
wenzelm
parents: 34481
diff changeset
    12
  object Kind extends Enumeration {
0f4b34445f40 turned Token.Kind into Enumeration;
wenzelm
parents: 34481
diff changeset
    13
    val COMMAND_START = Value("COMMAND_START")
0f4b34445f40 turned Token.Kind into Enumeration;
wenzelm
parents: 34481
diff changeset
    14
    val COMMENT = Value("COMMENT")
0f4b34445f40 turned Token.Kind into Enumeration;
wenzelm
parents: 34481
diff changeset
    15
    val OTHER = Value("OTHER")
34388
23b8351ecbbe arbitrary type for tokens
immler@in.tum.de
parents: 34318
diff changeset
    16
  }
34389
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    17
34481
660c639870a4 replaced type parameter C by Command (thanks to globally simultaneous scope);
wenzelm
parents: 34407
diff changeset
    18
  def checkStart(t : Token, P : (Int) => Boolean)
34482
0f4b34445f40 turned Token.Kind into Enumeration;
wenzelm
parents: 34481
diff changeset
    19
  = t != null && P(t.start)
34389
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    20
34481
660c639870a4 replaced type parameter C by Command (thanks to globally simultaneous scope);
wenzelm
parents: 34407
diff changeset
    21
  def checkStop(t : Token, P : (Int) => Boolean)
34482
0f4b34445f40 turned Token.Kind into Enumeration;
wenzelm
parents: 34481
diff changeset
    22
  = t != null && P(t.stop)
34389
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    23
34481
660c639870a4 replaced type parameter C by Command (thanks to globally simultaneous scope);
wenzelm
parents: 34407
diff changeset
    24
  def scan(s : Token, f : Token => Boolean) : Token = {
34389
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    25
    var current = s
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    26
    while (current != null) {
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    27
      val next = current.next
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    28
      if (next == null || f(next))
34482
0f4b34445f40 turned Token.Kind into Enumeration;
wenzelm
parents: 34481
diff changeset
    29
      return current
34389
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    30
      current = next
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    31
    }
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    32
    return null
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    33
  }
e858aafb4809 moved methods to object Token
immler@in.tum.de
parents: 34388
diff changeset
    34
34388
23b8351ecbbe arbitrary type for tokens
immler@in.tum.de
parents: 34318
diff changeset
    35
}
23b8351ecbbe arbitrary type for tokens
immler@in.tum.de
parents: 34318
diff changeset
    36
34482
0f4b34445f40 turned Token.Kind into Enumeration;
wenzelm
parents: 34481
diff changeset
    37
class Token(var start : Int, var stop : Int, var kind : Token.Kind.Value) {
34481
660c639870a4 replaced type parameter C by Command (thanks to globally simultaneous scope);
wenzelm
parents: 34407
diff changeset
    38
  var next : Token = null
660c639870a4 replaced type parameter C by Command (thanks to globally simultaneous scope);
wenzelm
parents: 34407
diff changeset
    39
  var previous : Token = null
660c639870a4 replaced type parameter C by Command (thanks to globally simultaneous scope);
wenzelm
parents: 34407
diff changeset
    40
  var command : Command = null
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    41
  
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    42
  def length = stop - start
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    43
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    44
  def shift(offset : Int, bottomClamp : Int) {
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    45
    start = bottomClamp max (start + offset)
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    46
    stop = bottomClamp max (stop + offset)
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
  
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    49
  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
    50
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    51
  override def equals(obj : Any) : Boolean = {
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    52
    if (super.equals(obj))
34482
0f4b34445f40 turned Token.Kind into Enumeration;
wenzelm
parents: 34481
diff changeset
    53
    return true;
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    54
    
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    55
    if (null == obj)
34482
0f4b34445f40 turned Token.Kind into Enumeration;
wenzelm
parents: 34481
diff changeset
    56
    return false;
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    57
    
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    58
    obj match {
34481
660c639870a4 replaced type parameter C by Command (thanks to globally simultaneous scope);
wenzelm
parents: 34407
diff changeset
    59
      case other: Token => 
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    60
        (start == other.start) && (stop == other.stop)
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    61
      case other: Any => false  
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
  }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    64
}