78 def apply(index: Markup_Index): Markup_Tree = |
78 def apply(index: Markup_Index): Markup_Tree = |
79 rep.getOrElse(index, Markup_Tree.empty) |
79 rep.getOrElse(index, Markup_Tree.empty) |
80 |
80 |
81 def add(index: Markup_Index, markup: Text.Markup): Markups = |
81 def add(index: Markup_Index, markup: Text.Markup): Markups = |
82 new Markups(rep + (index -> (this(index) + markup))) |
82 new Markups(rep + (index -> (this(index) + markup))) |
|
83 |
|
84 def other_id_iterator: Iterator[Document_ID.Generic] = |
|
85 for (Markup_Index(_, Text.Chunk.Id(other_id)) <- rep.keysIterator) |
|
86 yield other_id |
|
87 |
|
88 def retarget(other_id: Document_ID.Generic): Markups = |
|
89 new Markups( |
|
90 (for { |
|
91 (Markup_Index(status, Text.Chunk.Id(id)), markup) <- rep.iterator |
|
92 if other_id == id |
|
93 } yield (Markup_Index(status, Text.Chunk.Default), markup)).toMap) |
83 |
94 |
84 override def hashCode: Int = rep.hashCode |
95 override def hashCode: Int = rep.hashCode |
85 override def equals(that: Any): Boolean = |
96 override def equals(that: Any): Boolean = |
86 that match { |
97 that match { |
87 case other: Markups => rep == other.rep |
98 case other: Markups => rep == other.rep |
122 Protocol.Status.make((warnings ::: errors ::: status).iterator) |
133 Protocol.Status.make((warnings ::: errors ::: status).iterator) |
123 } |
134 } |
124 |
135 |
125 def markup(index: Markup_Index): Markup_Tree = markups(index) |
136 def markup(index: Markup_Index): Markup_Tree = markups(index) |
126 |
137 |
|
138 def retarget(other_command: Command): State = |
|
139 new State(other_command, Nil, Results.empty, markups.retarget(other_command.id)) |
|
140 |
127 |
141 |
128 def eq_content(other: State): Boolean = |
142 def eq_content(other: State): Boolean = |
129 command.source == other.command.source && |
143 command.source == other.command.source && |
130 status == other.status && |
144 status == other.status && |
131 results == other.results && |
145 results == other.results && |
141 markups.add(Markup_Index(true, chunk_name), m) |
155 markups.add(Markup_Index(true, chunk_name), m) |
142 else markups |
156 else markups |
143 copy(markups = markups1.add(Markup_Index(false, chunk_name), m)) |
157 copy(markups = markups1.add(Markup_Index(false, chunk_name), m)) |
144 } |
158 } |
145 |
159 |
146 def + (valid_id: Document_ID.Generic => Boolean, message: XML.Elem): State = |
160 def accumulate( |
|
161 self_id: Document_ID.Generic => Boolean, |
|
162 other_id: Document_ID.Generic => Option[(Text.Chunk.Id, Text.Chunk)], |
|
163 message: XML.Elem): State = |
147 message match { |
164 message match { |
148 case XML.Elem(Markup(Markup.STATUS, _), msgs) => |
165 case XML.Elem(Markup(Markup.STATUS, _), msgs) => |
149 (this /: msgs)((state, msg) => |
166 (this /: msgs)((state, msg) => |
150 msg match { |
167 msg match { |
151 case elem @ XML.Elem(markup, Nil) => |
168 case elem @ XML.Elem(markup, Nil) => |
161 (this /: msgs)((state, msg) => |
178 (this /: msgs)((state, msg) => |
162 { |
179 { |
163 def bad(): Unit = System.err.println("Ignored report message: " + msg) |
180 def bad(): Unit = System.err.println("Ignored report message: " + msg) |
164 |
181 |
165 msg match { |
182 msg match { |
166 case XML.Elem(Markup(name, |
183 case XML.Elem( |
167 atts @ Position.Reported(id, chunk_name, symbol_range)), args) |
184 Markup(name, atts @ Position.Reported(id, chunk_name, symbol_range)), args) => |
168 if valid_id(id) => |
185 |
169 command.chunks.get(chunk_name) match { |
186 val target = |
170 case Some(chunk) => |
187 if (self_id(id) && command.chunks.isDefinedAt(chunk_name)) |
171 chunk.incorporate(symbol_range) match { |
188 Some((chunk_name, command.chunks(chunk_name))) |
|
189 else if (chunk_name == Text.Chunk.Default) other_id(id) |
|
190 else None |
|
191 |
|
192 target match { |
|
193 case Some((target_name, target_chunk)) => |
|
194 target_chunk.incorporate(symbol_range) match { |
172 case Some(range) => |
195 case Some(range) => |
173 val props = Position.purge(atts) |
196 val props = Position.purge(atts) |
174 val info = Text.Info(range, XML.Elem(Markup(name, props), args)) |
197 val info = Text.Info(range, XML.Elem(Markup(name, props), args)) |
175 state.add_markup(false, chunk_name, info) |
198 state.add_markup(false, target_name, info) |
176 case None => bad(); state |
199 case None => bad(); state |
177 } |
200 } |
178 case None => bad(); state |
201 case None => /* FIXME bad(); */ state |
179 } |
202 } |
180 |
203 |
181 case XML.Elem(Markup(name, atts), args) |
204 case XML.Elem(Markup(name, atts), args) |
182 if !atts.exists({ case (a, _) => Markup.POSITION_PROPERTIES(a) }) => |
205 if !atts.exists({ case (a, _) => Markup.POSITION_PROPERTIES(a) }) => |
183 val range = command.proper_range |
206 val range = command.proper_range |
184 val props = Position.purge(atts) |
207 val props = Position.purge(atts) |
185 val info: Text.Markup = Text.Info(range, XML.Elem(Markup(name, props), args)) |
208 val info: Text.Markup = Text.Info(range, XML.Elem(Markup(name, props), args)) |
186 state.add_markup(false, Text.Chunk.Default, info) |
209 state.add_markup(false, Text.Chunk.Default, info) |
187 |
210 |
188 case _ => /* FIXME bad(); */ state |
211 case _ => bad(); state |
189 } |
212 } |
190 }) |
213 }) |
191 case XML.Elem(Markup(name, props), body) => |
214 case XML.Elem(Markup(name, props), body) => |
192 props match { |
215 props match { |
193 case Markup.Serial(i) => |
216 case Markup.Serial(i) => |
196 |
219 |
197 var st = copy(results = results + (i -> message1)) |
220 var st = copy(results = results + (i -> message1)) |
198 if (Protocol.is_inlined(message)) { |
221 if (Protocol.is_inlined(message)) { |
199 for { |
222 for { |
200 (chunk_name, chunk) <- command.chunks.iterator |
223 (chunk_name, chunk) <- command.chunks.iterator |
201 range <- Protocol.message_positions(valid_id, chunk_name, chunk, message) |
224 range <- Protocol.message_positions(self_id, chunk_name, chunk, message) |
202 } st = st.add_markup(false, chunk_name, Text.Info(range, message2)) |
225 } st = st.add_markup(false, chunk_name, Text.Info(range, message2)) |
203 } |
226 } |
204 st |
227 st |
205 |
228 |
206 case _ => |
229 case _ => |