16 { |
16 { |
17 /** XML trees **/ |
17 /** XML trees **/ |
18 |
18 |
19 /* datatype representation */ |
19 /* datatype representation */ |
20 |
20 |
|
21 type Attribute = Properties.Entry |
21 type Attributes = Properties.T |
22 type Attributes = Properties.T |
22 |
23 |
23 sealed abstract class Tree { override def toString: String = string_of_tree(this) } |
24 sealed abstract class Tree { override def toString: String = string_of_tree(this) } |
24 type Body = List[Tree] |
25 type Body = List[Tree] |
25 case class Elem(markup: Markup, body: Body) extends Tree |
26 case class Elem(markup: Markup, body: Body) extends Tree |
26 { |
27 { |
27 def name: String = markup.name |
28 def name: String = markup.name |
|
29 |
28 def update_attributes(more_attributes: Attributes): Elem = |
30 def update_attributes(more_attributes: Attributes): Elem = |
29 if (more_attributes.isEmpty) this |
31 if (more_attributes.isEmpty) this |
30 else Elem(markup.update_properties(more_attributes), body) |
32 else Elem(markup.update_properties(more_attributes), body) |
|
33 |
|
34 def + (att: Attribute): Tree = Elem(markup + att, body) |
31 } |
35 } |
32 case class Text(content: String) extends Tree |
36 case class Text(content: String) extends Tree |
33 |
37 |
34 def elem(name: String, body: Body): XML.Elem = XML.Elem(Markup(name, Nil), body) |
38 def elem(name: String, body: Body): XML.Elem = XML.Elem(Markup(name, Nil), body) |
35 def elem(name: String): XML.Elem = XML.Elem(Markup(name, Nil), Nil) |
39 def elem(name: String): XML.Elem = XML.Elem(Markup(name, Nil), Nil) |