20 { |
20 { |
21 /* content */ |
21 /* content */ |
22 |
22 |
23 lazy val results = reverse_results.reverse |
23 lazy val results = reverse_results.reverse |
24 |
24 |
|
25 def add_status(st: Markup): State = copy(status = st :: status) |
|
26 def add_markup(info: Text.Info[Any]): State = copy(markup = markup + info) |
25 def add_result(result: XML.Tree): State = copy(reverse_results = result :: reverse_results) |
27 def add_result(result: XML.Tree): State = copy(reverse_results = result :: reverse_results) |
26 |
|
27 def add_markup(info: Text.Info[Any]): State = copy(markup = markup + info) |
|
28 |
28 |
29 def root_info: Text.Info[Any] = |
29 def root_info: Text.Info[Any] = |
30 new Text.Info(command.range, |
30 new Text.Info(command.range, |
31 XML.Elem(Markup(Markup.STATUS, Nil), status.reverse.map(XML.Elem(_, Nil)))) |
31 XML.Elem(Markup(Markup.STATUS, Nil), status.reverse.map(XML.Elem(_, Nil)))) |
32 def root_markup: Markup_Tree = markup + root_info |
32 def root_markup: Markup_Tree = markup + root_info |
34 |
34 |
35 /* message dispatch */ |
35 /* message dispatch */ |
36 |
36 |
37 def accumulate(message: XML.Tree): Command.State = |
37 def accumulate(message: XML.Tree): Command.State = |
38 message match { |
38 message match { |
39 case XML.Elem(Markup(Markup.STATUS, _), body) => // FIXME explicit body check!? |
39 case XML.Elem(Markup(Markup.STATUS, _), msgs) => |
40 copy(status = (for (XML.Elem(markup, _) <- body) yield markup) ::: status) |
40 (this /: msgs)((state, msg) => |
|
41 msg match { |
|
42 case XML.Elem(markup, Nil) => state.add_status(markup) |
|
43 case _ => System.err.println("Ignored status message: " + msg); state |
|
44 }) |
41 |
45 |
42 case XML.Elem(Markup(Markup.REPORT, _), msgs) => |
46 case XML.Elem(Markup(Markup.REPORT, _), msgs) => |
43 (this /: msgs)((state, msg) => |
47 (this /: msgs)((state, msg) => |
44 msg match { |
48 msg match { |
45 case XML.Elem(Markup(name, atts), args) |
49 case XML.Elem(Markup(name, atts), args) |
46 if Position.get_id(atts) == Some(command.id) && Position.get_range(atts).isDefined => |
50 if Position.get_id(atts) == Some(command.id) && Position.get_range(atts).isDefined => |
47 val range = command.decode(Position.get_range(atts).get) |
51 val range = command.decode(Position.get_range(atts).get) |
48 val props = atts.filterNot(p => Markup.POSITION_PROPERTIES(p._1)) |
52 val props = atts.filterNot(p => Markup.POSITION_PROPERTIES(p._1)) |
49 val info = Text.Info[Any](range, XML.Elem(Markup(name, props), args)) |
53 val info = Text.Info[Any](range, XML.Elem(Markup(name, props), args)) |
50 add_markup(info) |
54 state.add_markup(info) |
51 case _ => System.err.println("Ignored report message: " + msg); state |
55 case _ => System.err.println("Ignored report message: " + msg); state |
52 }) |
56 }) |
53 case _ => add_result(message) |
57 case _ => add_result(message) |
54 } |
58 } |
55 } |
59 } |