Commit 69104370 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Clean up the regular expressions.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@19275 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d0c7599a
......@@ -69,19 +69,19 @@ class DateTimeKey(SearchKey):
'LESSTHAN', 'LESSTHANEQUAL', 'NOT', 'EQUAL',)
def t_OR(self, t):
r'(\s+OR\s+|\s+or\s+)'
r'\s+(OR|or)\s+'
# operator has leading and trailing ONLY one white space character
t.value = 'OR'
return t
def t_AND(self, t):
r'(\s+AND\s+|\s+and\s+)'
r'\s+(AND|and)\s+'
# operator has leading and trailing ONLY one white space character
t.value = 'AND'
return t
def t_NOT(self, t):
r'(\s+NOT\s+|\s+not\s+|!=)'
r'(\s+(NOT|not)\s+|!=)'
# operator has leading and trailing ONLY one white space character
t.value = t.value.upper().strip()
return t
......
......@@ -57,21 +57,21 @@ class DefaultKey(SearchKey):
# Note: Order of placing rules (t_WORD for example) is very important
def t_OR(self, t):
r'(\s+OR\s+|\s+or\s+)'
r'\s+(OR|or)\s+'
# operator must have leading and trailing ONLY one white space character
# otherwise it's treated as a WORD
t.value = 'OR'
return t
def t_AND(self, t):
r'(\s+AND\s+|\s+and\s+)'
r'\s+(AND|and)\s+'
# operator must have leading and trailing ONLY one white space character
# otherwise it's treated as a WORD
t.value = 'AND'
return t
def t_NOT(self, t):
r'(\s+NOT\s+|\s+not\s+|!=)'
r'(\s+(NOT|not)\s+|!=)'
# operator must have leading and trailing ONLY one white space character
# otherwise it's treated as a WORD
t.value = '!='
......@@ -83,21 +83,23 @@ class DefaultKey(SearchKey):
t_LESSTHAN = r'<'
def t_WORD(self, t):
r'[\x7F-\xFF\w\d\/\.\-~!@#$%^&*()_+\n][\x7F-\xFF\w\d\/\.\-~!@#$%^&*()_+\n]*'
#r'[\x7F-\xFF\w\d\/%][\x7F-\xFF\w\d\/%]*'
r'([^"\s<>!][\S\n]*|!([^=\s][\S\n]*)?)'
# newlines are allowed, because variations are delimited by newlines.
# WORD may contain arbitrary letters and numbers without white space
# WORD may contain '%' but not at the beginning or end (otherwise it's KEYWORD)
value = t.value.strip()
t.value = "%s" %value
if value[0] == '=':
value = value[1:]
t.value = value
return t
def t_WORDSET(self, t):
r'"[\x7F-\xFF\w\d\s\/\.~!@#$%^&*()_+][\x7F-\xFF\w\d\s\/\.~!@#$%^&*()_+]*"'
r'"[^"]*"'
#r'"[\x7F-\xFF\w\d\s/%][\x7F-\xFF\w\d\s/%]*"'
# WORDSET is a combination of WORDs separated by white space
# and starting/ending with "
value = t.value.replace('"', '').strip()
t.value = "%s" %value
t.value = value
return t
def quoteSQLString(self, value, format):
......
......@@ -45,21 +45,21 @@ class FloatKey(SearchKey):
# Note: Order of placing rules (t_WORD for example) is very important
def t_OR(self, t):
r'(\s+OR\s+|\s+or\s+)'
r'\s+(OR|or)\s+'
# operator must have leading and trailing ONLY one white space character
# otherwise it's treated as a WORD
t.value = 'OR'
return t
def t_AND(self, t):
r'(\s+AND\s+|\s+and\s+)'
r'\s+(AND|and)\s+'
# operator must have leading and trailing ONLY one white space character
# otherwise it's treated as a WORD
t.value = 'AND'
return t
def t_NOT(self, t):
r'(\s+NOT\s+|\s+not\s+|!=)'
r'(\s+(NOT|not)\s+|!=)'
# operator must have leading and trailing ONLY one white space character
# otherwise it's treated as a WORD
t.value = '!='
......@@ -74,7 +74,7 @@ class FloatKey(SearchKey):
r'[\d.][\d.]*'
# FLOAT is a float number
value = t.value.replace('"', '').strip()
t.value = "%s" %value
t.value = value
return t
def quoteSQLString(self, value, format):
......
......@@ -58,11 +58,11 @@ class FullTextKey(SearchKey):
t_DOUBLEQUOTE = r'(\")'
def t_WORD(self, t):
r'[\x7F-\xFF\w\d\/\.!@#$%^&_][\x7F-\xFF\w\d\/\.!@#$%^&_]*'
r'[^\+\-<>\(\)\~\*\"\s]\S*'
#r'[\x7F-\xFF\w\d][\x7F-\xFF\w\d]*'
# WORD may contain arbitrary letters and numbers without white space
word_value = t.value
t.value = "'%s'" %word_value
t.value = "'%s'" % word_value
return t
def buildSQLExpression(self, key, value,
......
......@@ -66,25 +66,25 @@ class KeyWordKey(SearchKey):
# Note: Order of placing rules (t_WORD for example) is very important
def t_OR(self, t):
r'(\s+OR\s+|\s+or\s+)'
r'\s+(OR|or)\s+'
# operator must have leading and trailing ONLY one white space character
# otherwise it's treated as a WORD
t.value = 'OR'
return t
def t_AND(self, t):
r'(\s+AND\s+|\s+and\s+)'
r'\s+(AND|and)\s+'
# operator must have leading and trailing ONLY one white space character
# otherwise it's treated as a WORD
t.value = 'AND'
return t
def t_NOT(self, t):
r'(\s+NOT\s+|\s+not\s+|!=)'
r'(\s+(NOT|not)\s+|!=)'
# operator must have leading and trailing ONLY one white space character
# otherwise it's treated as a WORD
t.value = t.value.upper().strip()
return t
return t
t_GREATERTHANEQUAL = r'>='
t_LESSTHANEQUAL = r'<='
......@@ -92,7 +92,7 @@ class KeyWordKey(SearchKey):
t_LESSTHAN = r'<'
def t_EXPLICITEQUALLITYWORD(self, t):
r'=[\x7F-\xFF\w\d\/\.~!@#$^&*()_+][\x7F-\xFF\w\d\/\.~!@#$^&*()_+]*'
r'=\S*'
# EXPLICITEQUALLITYWORD may contain arbitrary letters and numbers without white space
# EXPLICITEQUALLITYWORD must contain '=' at the beginning
value = t.value.strip()
......@@ -101,30 +101,30 @@ class KeyWordKey(SearchKey):
return t
def t_KEYWORD(self, t):
r'%?[\x7F-\xFF\w\d/\.~!@#$%^&*()_+][\x7F-\xFF\w\d/\.~!@#$%^&*()_+]*%?'
# KEYWORD may starts(1) and may ends (2) with '%' but always must either #1 or #2
# be true. It may contains arbitrary letters, numbers and white space
r'(%\S*|([^!<>=\s%]\S*|!([^=\s]\S*)?)%)'
# KEYWORD must start and/or end with '%'.
# It may contain arbitrary letters and numbers without white space
value = t.value.strip()
if not value.startswith('%') and not value.endswith('%'):
t.type = 'WORD'
t.value = value
return t
def t_WORD(self, t):
r'[\x7F-\xFF\w\d\/\.~!@#$^&*()_+][\x7F-\xFF\w\d\/\.~!@#$^&*()_+]*'
r'([^"\s<>!=%]([^ \t\r\f\v]*[^ \t\r\f\v%])?|!([^= \t\r\f\v%]|[^= \t\r\f\v][\S\n]*[^ \t\r\f\v%])?)'
# WORD may contain arbitrary letters and numbers without white space
# WORD may contain '%' but not at the beginning or end (otherwise it's KEYWORD)
value = t.value.strip()
t.value = value
return t
return t
def t_WORDSET(self, t):
r'=?"[\x7F-\xFF\w\d\s\/\.~!@#$%^&*()_+][\x7F-\xFF\w\d\s\/\.~!@#$%^&*()_+]*"'
r'=?"[^"]*"'
# WORDSET is a combination of WORDs separated by white space
# and starting/ending with " (optionally with '=')
value = t.value.replace('"', '')
t.value = "%s" %value
return t
if value[0] == '=':
value = value[1:]
t.value = value
return t
def quoteSQLString(self, value, format):
""" Return a quoted string of the value. """
......
......@@ -91,21 +91,21 @@ class ScriptableKey(SearchKey):
# Note: Order of placing rules (t_WORD for example) is very important
def t_OR(self, t):
r'(\s+OR\s+|\s+or\s+)'
r'\s+(OR|or)\s+'
# operator must have leading and trailing ONLY one white space character
# otherwise it's treated as a WORD
t.value = 'OR'
return t
def t_AND(self, t):
r'(\s+AND\s+|\s+and\s+)'
r'\s+(AND|and)\s+'
# operator must have leading and trailing ONLY one white space character
# otherwise it's treated as a WORD
t.value = 'AND'
return t
def t_KEYMAPPING(self, t):
r'[\x7F-\xFF\w\d\/~!@#$^&*()_+-][\x7F-\xFF\w\d\/~!@#$^&*()_+-]*\s*(>|<|<=|>=|:)\s*[\x7F-\xFF\w\d\/~!@#$^&*()_+-][\x7F-\xFF\w\d\/~!@#$^&*()_+-]*'
r'[^<>=:\s]+\s*(>|<|<=|>=|:)\s*\S+'
# KEYMAPPING has following format: KEY OPERATOR VALUE
# where OPERATOR in ['<', '>', '<=', '>=', ':']
# example: 'creation_date < 2007-12-12'
......@@ -114,7 +114,7 @@ class ScriptableKey(SearchKey):
return t
def t_WORD(self, t):
r'[\x7F-\xFF\w\d\/~!@#$^&*()_+][\x7F-\xFF\w\d\/~!@#$^&*()_+]*'
r'[^<>=\s:]+'
# WORD may contain arbitrary letters and numbers without white space
# WORD may contain '%' but not at the beginning or end (otherwise it's KEYWORD)
value = t.value.strip()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment