author | wenzelm |
Mon, 19 Jan 2009 20:33:26 +0100 | |
changeset 34481 | 660c639870a4 |
parent 34407 | aad6834ba380 |
child 34482 | 0f4b34445f40 |
permissions | -rw-r--r-- |
34407 | 1 |
/* |
2 |
* Document tokens as text ranges |
|
3 |
* |
|
4 |
* @author Johannes Hölzl, TU Munich |
|
5 |
* @author Fabian Immler, TU Munich |
|
6 |
*/ |
|
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 | 11 |
object Token { |
12 |
object Kind { |
|
13 |
val COMMAND_START = "COMMAND_START" |
|
14 |
val COMMENT = "COMMENT" |
|
15 |
} |
|
34389 | 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 | 18 |
= t != null && P(t.start) |
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 | 21 |
= t != null && P(t.stop) |
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 | 24 |
var current = s |
25 |
while (current != null) { |
|
26 |
val next = current.next |
|
27 |
if (next == null || f(next)) |
|
28 |
return current |
|
29 |
current = next |
|
30 |
} |
|
31 |
return null |
|
32 |
} |
|
33 |
||
34388 | 34 |
} |
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 |
} |