equal
deleted
inserted
replaced
7 |
7 |
8 package isabelle |
8 package isabelle |
9 |
9 |
10 import java.lang.System |
10 import java.lang.System |
11 |
11 |
|
12 import scala.collection.mutable |
12 import scala.collection.immutable.SortedMap |
13 import scala.collection.immutable.SortedMap |
13 |
14 |
14 |
15 |
15 object Command |
16 object Command |
16 { |
17 { |
75 } |
76 } |
76 } |
77 } |
77 } |
78 } |
78 |
79 |
79 |
80 |
80 /* dummy commands */ |
81 /* make commands */ |
|
82 |
|
83 def apply(id: Document.Command_ID, node_name: Document.Node.Name, toks: List[Token]): Command = |
|
84 { |
|
85 val source: String = |
|
86 toks match { |
|
87 case List(tok) => tok.source |
|
88 case _ => toks.map(_.source).mkString |
|
89 } |
|
90 |
|
91 val span = new mutable.ListBuffer[Token] |
|
92 var i = 0 |
|
93 for (Token(kind, s) <- toks) { |
|
94 val n = s.length |
|
95 val s1 = source.substring(i, i + n) |
|
96 span += Token(kind, s1) |
|
97 i += n |
|
98 } |
|
99 |
|
100 new Command(id, node_name, span.toList, source) |
|
101 } |
|
102 |
|
103 def apply(node_name: Document.Node.Name, toks: List[Token]): Command = |
|
104 Command(Document.no_id, node_name, toks) |
81 |
105 |
82 def unparsed(source: String): Command = |
106 def unparsed(source: String): Command = |
83 new Command(Document.no_id, Document.Node.Name.empty, |
107 Command(Document.no_id, Document.Node.Name.empty, List(Token(Token.Kind.UNPARSED, source))) |
84 List(Token(Token.Kind.UNPARSED, source))) |
|
85 |
|
86 def span(node_name: Document.Node.Name, toks: List[Token]): Command = |
|
87 new Command(Document.no_id, node_name, toks) |
|
88 |
108 |
89 |
109 |
90 /* perspective */ |
110 /* perspective */ |
91 |
111 |
92 object Perspective |
112 object Perspective |
107 } |
127 } |
108 } |
128 } |
109 } |
129 } |
110 |
130 |
111 |
131 |
112 class Command( |
132 class Command private( |
113 val id: Document.Command_ID, |
133 val id: Document.Command_ID, |
114 val node_name: Document.Node.Name, |
134 val node_name: Document.Node.Name, |
115 val span: List[Token]) |
135 val span: List[Token], |
|
136 val source: String) |
116 { |
137 { |
117 /* classification */ |
138 /* classification */ |
118 |
139 |
119 def is_defined: Boolean = id != Document.no_id |
140 def is_defined: Boolean = id != Document.no_id |
120 |
141 |
127 id + "/" + (if (is_command) name else if (is_ignored) "IGNORED" else "MALFORMED") |
148 id + "/" + (if (is_command) name else if (is_ignored) "IGNORED" else "MALFORMED") |
128 |
149 |
129 |
150 |
130 /* source text */ |
151 /* source text */ |
131 |
152 |
132 val source: String = span.map(_.source).mkString |
|
133 def source(range: Text.Range): String = source.substring(range.start, range.stop) |
153 def source(range: Text.Range): String = source.substring(range.start, range.stop) |
134 def length: Int = source.length |
154 def length: Int = source.length |
135 |
155 |
136 val newlines = |
156 val newlines = |
137 (0 /: Symbol.iterator(source)) { |
157 (0 /: Symbol.iterator(source)) { |