equal
deleted
inserted
replaced
6 |
6 |
7 package isabelle |
7 package isabelle |
8 |
8 |
9 import scala.collection.mutable |
9 import scala.collection.mutable |
10 import scala.util.matching.Regex |
10 import scala.util.matching.Regex |
|
11 import scala.annotation.tailrec |
11 |
12 |
12 |
13 |
13 object Symbol |
14 object Symbol |
14 { |
15 { |
15 type Symbol = String |
16 type Symbol = String |
95 } |
96 } |
96 } |
97 } |
97 |
98 |
98 def explode(text: CharSequence): List[Symbol] = iterator(text).toList |
99 def explode(text: CharSequence): List[Symbol] = iterator(text).toList |
99 |
100 |
|
101 def advance_line_column(pos: (Int, Int), text: CharSequence): (Int, Int) = |
|
102 { |
|
103 var (line, column) = pos |
|
104 for (sym <- iterator(text)) { |
|
105 if (is_physical_newline(sym)) { line += 1; column = 1 } |
|
106 else column += 1 |
|
107 } |
|
108 (line, column) |
|
109 } |
|
110 |
100 |
111 |
101 /* decoding offsets */ |
112 /* decoding offsets */ |
102 |
113 |
103 class Index(text: CharSequence) |
114 class Index(text: CharSequence) |
104 { |
115 { |
119 } |
130 } |
120 def decode(sym1: Int): Int = |
131 def decode(sym1: Int): Int = |
121 { |
132 { |
122 val sym = sym1 - 1 |
133 val sym = sym1 - 1 |
123 val end = index.length |
134 val end = index.length |
124 def bisect(a: Int, b: Int): Int = |
135 @tailrec def bisect(a: Int, b: Int): Int = |
125 { |
136 { |
126 if (a < b) { |
137 if (a < b) { |
127 val c = (a + b) / 2 |
138 val c = (a + b) / 2 |
128 if (sym < index(c).sym) bisect(a, c) |
139 if (sym < index(c).sym) bisect(a, c) |
129 else if (c + 1 == end || sym < index(c + 1).sym) c |
140 else if (c + 1 == end || sym < index(c + 1).sym) c |