summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormjtnix <mjtnix@5914aa95-5b3a-0410-a3b5-7b719e7fe9b2>2007-10-21 00:33:53 +0000
committermjtnix <mjtnix@5914aa95-5b3a-0410-a3b5-7b719e7fe9b2>2007-10-21 00:33:53 +0000
commit5c313a83ff70810933db2b8027f455d25ae96712 (patch)
tree435236d3517ca3868bb982def7ed9d02922a78d2
parent3e4307fc5cef5a0709959b445e62f96e0e38ec22 (diff)
disallow whitespace and other magic characters in identifiers.
update js code and testcase accordingly. git-svn-id: http://freebase-python.googlecode.com/svn/trunk@20 5914aa95-5b3a-0410-a3b5-7b719e7fe9b2
-rwxr-xr-xfreebase/rison.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/freebase/rison.py b/freebase/rison.py
index c75dc8e..2f4eebc 100755
--- a/freebase/rison.py
+++ b/freebase/rison.py
@@ -36,16 +36,20 @@ class Parser(object):
#WHITESPACE = " \t\n\r\f"
# we divide the uri-safe glyphs into three sets
- # <rison> - used by rison ' ! : ( ) ,
- # <identifier> - common in strings - _ . / ~
- # <reserved> - not common in strings, reserved * @ $
- #
# <rison> and <reserved> classes are illegal in ids.
- # ids also can't look like numbers.
+ # <rison> - used by rison (possibly later)
+ # <reserved> - not common in strings, reserved
+ #not_idchar = "'!=:(),*@$;&";
- not_idchar = "'!:(),*@$";
+ idchar_punctuation = '_-./~'
+ not_idchar = ''.join([c for c in (chr(i) for i in range(127))
+ if not (c.isalnum()
+ or c in idchar_punctuation)])
+
+ # additionally, we need to distinguish ids and numbers by first char
not_idstart = "-0123456789";
+ # regexp string matching a valid id
idrx = ('[^' + not_idstart + not_idchar +
'][^' + not_idchar + ']*')
@@ -66,7 +70,7 @@ class Parser(object):
value = self.readValue()
if self.next():
- raise ParserException("extra characters at the end of the string")
+ raise ParserException("unable to parse rison string %r" % (str,))
return value
def readValue(self):
@@ -280,7 +284,7 @@ if __name__ == '__main__':
"G.",
"a",
"'0a'",
- "abc def",
+ "'abc def'",
"()",
"(a:0)",
"(id:!n,type:/common/document)",