--- 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