summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2003-12-08 15:38:34 +0000
committerburaq <buraq@epfl.ch>2003-12-08 15:38:34 +0000
commit6e7244f1c097278c35409c59b370f0721464127c (patch)
tree05eea4c26761f2ce36a2177b8c291abc4c2a761e /sources
parent613a52d58f5eebdae85f99078901eca7186c81d3 (diff)
downloadscala-6e7244f1c097278c35409c59b370f0721464127c.tar.gz
scala-6e7244f1c097278c35409c59b370f0721464127c.tar.bz2
scala-6e7244f1c097278c35409c59b370f0721464127c.zip
added a lot of XML functionality, replacing sca...
added a lot of XML functionality, replacing scala.xml.nobinding.Element
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/Symbol.scala66
1 files changed, 60 insertions, 6 deletions
diff --git a/sources/scala/Symbol.scala b/sources/scala/Symbol.scala
index ad98a0eff0..18ef98a1cc 100644
--- a/sources/scala/Symbol.scala
+++ b/sources/scala/Symbol.scala
@@ -9,22 +9,76 @@
package scala;
-import scala.xml.{Node,Text};
+import scala.xml.{AttributedNode,Node, Text,Utility};
import scala.xml.nobinding.Element;
+import scala.collection.Map ;
import scala.collection.immutable.ListMap ;
/** Instances of <code>Symbol</code> can be created easily with
* Scala's built-in quote mechanism. For instance, the Scala term
* <code>'mysym</code> will invoke the constructor of the
* <code>Symbol</code> class in the following way:
- * <code>new Symbol("mysym")</code>.
+ * <code>new Symbol("mysym", Nil)</code>. The Scala term <code>'mysym('foo,'bar)</code>
+ * will be treated as <code>new Symbol("mysym", List(new Symbol("foo",Nil), new Symbol("bar",Nil)</code>
*
- * @author Martin Odersky
- * @version 1.0, 08/08/2003
+ * @author Burak Emir, Martin Odersky
+ * @version 1.5, 2003-12-08
*/
-case class Symbol(name: String, elems: Any*) {
+case class Symbol(name: String, elems: Any*) extends AttributedNode {
- override def toString() = "'" + name;
+ // Node methods
+ def label = name;
+ def children:Seq[Node] = List.fromIterator( elems.elements map ( x => x match {
+ case n:Node => n;
+ case _ => Text( x.toString() );
+ }));
+
+ var attrMap:ListMap[String,String] = ListMap.Empty[String,String];
+
+ // AttributedNode methods, duplicated because of mixin misery
+ override def attributes : Map[String,String] = attrMap;
+
+ /** converts this symbol to a string */
+ override def toString():String = {
+ val s = new StringBuffer("'" + name) ;
+ val it = elems.elements;
+ if( it.hasNext ) {
+ s.append("(");
+ val e1 = it.next.toString();
+ s.append( e1 );
+ for( val e <- it ) {
+ s.append(','); s.append( e.toString() );
+ }
+ s.append(")");
+ }
+ s.toString();
+ }
+
+ /** this method <b>destructively</b> updates attributes of this symbol.
+ */
+ final def % (attrs:List[AttrDef]):Symbol = {
+ attrMap = ListMap.Empty[String,String];
+ for( val a <- attrs.elements ) {
+ attrMap = attrMap.update( a.key, a.value );
+ }
+ this
+ }
+
+ final def <=( value:String ) = new AttrDef( name, value );
+
+ case class AttrDef( key:String, value:String );
+
+ final def saveTo( filename:String ) = Symbol_IO.save( filename, this );
}
+object Symbol_IO {
+ // functions for generic symbol loading, saving
+
+ /** loads symbol from a given file*/
+ def load( filename:String ):Symbol = scala.xml.nobinding.XML.load( filename );
+
+ /** saves symbol to filename (with encoding ISO-8859-1) */
+ def save( filename:String, doc:Symbol ):Unit = scala.xml.nobinding.XML.save( filename, doc );
+
+}