+ optional '.' at end of gp
authorEric Prud'hommeaux <eric@w3.org>
Thu, 11 Feb 2010 09:52:33 -0500
changeset 163 90cd6100e605
parent 162 800b4d9d114d
child 164 6a5bfefcfcdb
+ optional '.' at end of gp
+ 'a' predicate
+ '-'s in URIs
src/main/scala/SPARQL.scala
--- a/src/main/scala/SPARQL.scala	Wed Feb 10 18:28:25 2010 -0500
+++ b/src/main/scala/SPARQL.scala	Thu Feb 11 09:52:33 2010 -0500
@@ -6,7 +6,8 @@
 
 object MyParsers extends RegexParsers {
 
-  val uri = """[a-zA-Z0-9:/#_\.]+""".r
+  val uri = """[a-zA-Z0-9:/#_\.\-]+""".r
+  val integer = """[0-9]+""".r
   val name = """[a-zA-Z_][a-zA-Z0-9_]*""".r
   var prefixes:Map[String, String] = Map()
 }
@@ -256,7 +257,7 @@
   )
 
   def triplesblock:Parser[TriplesBlock] =
-    rep1sep(triplepattern, ".") ^^ { case pats => TriplesBlock(pats) }
+    rep1sep(triplepattern, ".") ~ opt(".") ^^ { case pats~x => TriplesBlock(pats) }
 
   def triplepattern:Parser[TriplePattern] =
     subject ~ predicate ~ objectt ^^ { case s~p~o => TriplePattern(s, p, o) }
@@ -268,6 +269,7 @@
 
   def predicate:Parser[Term] = (
       qnameORuri ^^ { x => TermUri(x) }
+    | "a" ^^ { x => TermUri(Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")) }
     | varr ^^ { x => TermVar(x) }
   )
 
@@ -289,7 +291,7 @@
     }
   )
 
-  def literal:Parser[Literal] =
+  def literal:Parser[Literal] = (
       stringLiteral~"^^"~qnameORuri ^^
       {
 	case lit~"^^"~dt => Literal(RDFLiteral(lit.substring(1,lit.size - 1), dt.s match {
@@ -300,6 +302,8 @@
 	  case x => error("only programed to deal with string and integer, not " + x)
 	}))
       }
+    | integer ^^ { l => Literal(RDFLiteral(l, RDFLiteral.IntegerDatatype)) }
+  )
 
   def varr:Parser[Var] = "?"~ident ^^ { case "?"~x => Var(x) }