--- a/src/main/scala/RDF.scala Thu Jan 07 19:16:51 2010 -0500
+++ b/src/main/scala/RDF.scala Thu Jan 07 19:18:56 2010 -0500
@@ -16,8 +16,12 @@
case class BlankNode(debugName:String)
-case class RDFLiteral(lexicalForm:String, datatype:Datatype)
-case class Datatype(uri:URI)
+case class RDFLiteral(lexicalForm:String, datatype:Datatype) {
+ override def toString = "\"" + lexicalForm + "\"" + datatype
+}
+case class Datatype(uri:URI) {
+ override def toString = "^^" + uri
+}
object RDFLiteral {
val StringDatatype = Datatype(new URI("http://www.w3.org/2001/XMLSchema#string"))
--- a/src/main/scala/SPARQL.scala Thu Jan 07 19:16:51 2010 -0500
+++ b/src/main/scala/SPARQL.scala Thu Jan 07 19:18:56 2010 -0500
@@ -31,25 +31,49 @@
case class CellValue(s:String)
sealed abstract class S
-case class SUri(obj:ObjUri) extends S
-case class SVar(v:Var) extends S
+case class SUri(obj:ObjUri) extends S {
+ override def toString = "" + obj
+}
+case class SVar(v:Var) extends S {
+ override def toString = "" + v
+}
sealed abstract class O
-case class OUri(obj:ObjUri) extends O
-case class OVar(v:Var) extends O
-case class OLit(lit:Literal) extends O
+case class OUri(obj:ObjUri) extends O {
+ override def toString = "" + obj
+}
+case class OVar(v:Var) extends O {
+ override def toString = "" + v
+}
+case class OLit(lit:Literal) extends O {
+ override def toString = "" + lit
+}
sealed abstract class P
-case class PUri(stem:Stem, rel:Rel, attr:Attr) extends P
-case class PVar(v:Var) extends P
-
-case class Literal(lit:RDFLiteral)
+case class PUri(stem:Stem, rel:Rel, attr:Attr) extends P {
+ override def toString = "<" + stem + "/" + rel + "#" + attr + ">"
+}
+case class PVar(v:Var) extends P {
+ override def toString = "" + v
+}
-case class Stem(s:String)
-case class Attr(s:String)
-case class Rel(s:String)
+case class Literal(lit:RDFLiteral) {
+ override def toString = "" + lit
+}
-case class Var(s:String)
+case class Stem(s:String) {
+ override def toString = "" + s
+}
+case class Attr(s:String) {
+ override def toString = "" + s
+}
+case class Rel(s:String) {
+ override def toString = "" + s
+}
+
+case class Var(s:String) {
+ override def toString = "?" + s
+}
case class Expression(conjuncts:List[PrimaryExpression])
sealed abstract class PrimaryExpression
@@ -164,7 +188,14 @@
def qnameORuri:Parser[String] = (
"<"~uri~">" ^^ { case "<"~x~">" => x }
- | name~":"~name ^^ { case prefix~":"~localName => prefixes(prefix) + localName }
+ | name~":"~name ^^ {
+ case prefix~":"~localName => try {
+ prefixes(prefix) + localName
+ } catch {
+ case e:java.util.NoSuchElementException =>
+ throw new Exception("unknown prefix " + prefix)
+ }
+ }
)
def literal:Parser[Literal] =