changeset 350:c69b9aac210c

+ I18N'd single-quoted names
author Eric Prud'hommeaux <eric@w3.org>
date Wed, 16 Feb 2011 10:04:13 -0500
parents 0a9c000c9dd5
children c74c83253026
files sql/src/main/scala/SQL.scala sql/src/test/scala/SQLTest.scala
diffstat 2 files changed, 35 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/sql/src/main/scala/SQL.scala	Sat Feb 12 11:11:50 2011 -0500
+++ b/sql/src/main/scala/SQL.scala	Wed Feb 16 10:04:13 2011 -0500
@@ -345,22 +345,30 @@
     relvar ~ "." ~ attribute ^^
     { case relvar ~ "." ~ attribute => RelVarAttr(relvar, attribute) }
 
-  def attribute:Parser[RDB.AttrName] =
-    """[a-zA-Z_]\w*""".r ^^ { x => RDB.AttrName(x) }
+  def attribute:Parser[RDB.AttrName] = (
+      """[a-zA-Z_]\w*""".r ^^ { x => RDB.AttrName(x) }
+    | """'[^']+'""".r ^^ { x => RDB.AttrName(x.substring(1, x.size - 1)) }
+  )
 
-  def attralias:Parser[AttrAlias] =
-    """[a-zA-Z_]\w*""".r ^^ { x => AttrAlias(Name(x)) }
+  def attralias:Parser[AttrAlias] = (
+      """[a-zA-Z_]\w*""".r ^^ { x => AttrAlias(Name(x)) }
+    | """'[^']+'""".r ^^ { x => AttrAlias(Name(x.substring(1, x.size - 1))) }
+  )
 
   def relationORsubselect:Parser[RelationORSubselect] = (
       relation ^^ { x => RelationResource(x) }
     | "(" ~ selectORunion ~ ")" ^^ { case "("~s~")" => Subselect(s) }
   )
 
-  def relation:Parser[RDB.RelName] =
-    """[a-zA-Z_]\w*""".r ^^ { x => RDB.RelName(x) }
+  def relation:Parser[RDB.RelName] = (
+      """[a-zA-Z_]\w*""".r ^^ { x => RDB.RelName(x) }
+    | """'[^']+'""".r ^^ { x => RDB.RelName(x.substring(1, x.size - 1)) }
+  )
 
-  def relvar:Parser[RelVar] =
-    """[a-zA-Z_]\w*""".r ^^ { x => RelVar(Name(x)) }
+  def relvar:Parser[RelVar] = (
+      """[a-zA-Z_]\w*""".r ^^ { x => RelVar(Name(x)) }
+    | """'[^']+'""".r ^^ { x => RelVar(Name(x)) }
+  )
 
   def tablelist:Parser[(TableList, Set[Expression])] =
     "(?i)FROM".r ~ aliasedjoin ~ rep(innerORouter) ^^
--- a/sql/src/test/scala/SQLTest.scala	Sat Feb 12 11:11:50 2011 -0500
+++ b/sql/src/test/scala/SQLTest.scala	Wed Feb 16 10:04:13 2011 -0500
@@ -1029,6 +1029,25 @@
     assert((p1.parseAll(p1.ddl, upper).get) === (p2.parseAll(p2.ddl, lower).get))
   }
 
+  test("parse single-quoted CJK") {
+    val p = SqlParser()
+    val s = """
+CREATE TABLE '植物' ('名' varchar(50));
+INSERT INTO '植物' ('名') VALUES ('シソ');
+"""
+    val addrs = RDB.Relation(
+      "植物",
+      RDB.Header("名" -> RDB.Datatype.STRING),
+      List(RDB.Tuple("名" -> RDB.LexicalValue("シソ"))),
+      List(),
+      None,
+      RDB.ForeignKeys())
+
+    val expected = RDB.Database(List(addrs))
+    assert(expected === (p.parseAll(p.ddl, s).get))
+  }
+
+
 
   /**
    * junk that should be elsewhere
Set up and maintained by W3C Systems Team, please report bugs to sysreq@w3.org.

W3C would like to thank Microsoft who donated the server that allows us to run this service.