summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2003-12-19 11:46:31 +0000
committerburaq <buraq@epfl.ch>2003-12-19 11:46:31 +0000
commit7c0e0f3ca315678ea61498fef6fd093cb964b63b (patch)
treee5c40546ef459fa8a6c7df6d7334fa0b94de138c /sources
parent3351f53801c0a845112f8e033994b91011b7c1f4 (diff)
downloadscala-7c0e0f3ca315678ea61498fef6fd093cb964b63b.tar.gz
scala-7c0e0f3ca315678ea61498fef6fd093cb964b63b.tar.bz2
scala-7c0e0f3ca315678ea61498fef6fd093cb964b63b.zip
attributes handled in functional manner
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/Symbol.scala24
1 files changed, 14 insertions, 10 deletions
diff --git a/sources/scala/Symbol.scala b/sources/scala/Symbol.scala
index 1077dbb49d..5cfd26b4ee 100644
--- a/sources/scala/Symbol.scala
+++ b/sources/scala/Symbol.scala
@@ -12,7 +12,7 @@ package scala;
import org.xml.sax.InputSource;
import scala.xml.{AttributedNode,Node, Text,Utility};
-import scala.collection.Map;
+import scala.collection.immutable.Map;
import scala.collection.immutable.ListMap;
@@ -40,11 +40,11 @@ case class Symbol(name: String, elems: Any*) extends AttributedNode {
case _ => Text(x.toString());
}));
- private var attrMap: ListMap[String, String] = ListMap.Empty[String,String];
+ //private val attrMap: ListMap[String, String] = ListMap.Empty[String,String];
/** Returns a map representing the attributes of this node.
*/
- def attributes: Map[String, String] = attrMap;
+ def attributes: Map[String, String] = ListMap.Empty;
/** Converts this symbol to a string
*/
@@ -63,14 +63,18 @@ case class Symbol(name: String, elems: Any*) extends AttributedNode {
s.toString();
}
- /** This method <b>destructively</b> updates attributes of this symbol.
+ /** returns a new symbol with updated attributes
*/
- final def %(attrs: List[Pair[String, String]]): Symbol = {
- attrMap = ListMap.Empty[String,String];
- for(val a <- attrs.elements) {
- attrMap = attrMap.update(a._1, a._2);
- }
- this
+ final def %(attrs: List[Pair[String, String]]): Symbol = new Symbol( name, elems:_* ) {
+ val themap = Symbol.this.attributes.incl( attrs );
+ override def attributes = themap;
+ }
+
+ /** returns a new symbol with updated attribute
+ */
+ final def %(attr: Pair[String, String]): Symbol = new Symbol( name, elems:_* ) {
+ val themap = Symbol.this.attributes.incl( attr );
+ override def attributes = themap;
}
final def <=(value: String) = new Pair(name, value);