summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2015-03-01 11:52:34 +0100
committerAndi Albrecht <albrecht.andi@gmail.com>2015-03-01 11:52:34 +0100
commit15b0cb9e75ca378e94b55b7f1ff23108f0899cde (patch)
treeecaac782a6f5366022a017967ecea2461edacdf2
parent811b69ad540fa98a310252b3e55d3ac5d8e28ba4 (diff)
downloadsqlparse-15b0cb9e75ca378e94b55b7f1ff23108f0899cde.tar.gz
Allow identifiers to start with an underscore (fixes #175).
-rw-r--r--CHANGES1
-rw-r--r--sqlparse/lexer.py3
-rw-r--r--tests/test_parse.py9
3 files changed, 11 insertions, 2 deletions
diff --git a/CHANGES b/CHANGES
index 24f3858..36842bc 100644
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,7 @@ Bug Fixes
* Add missing SQL types (issue154, issue155, issue156, by jukebox).
* Fix parsing of multi-line comments (issue172, by JacekPliszka).
* Fix parsing of escaped backslashes (issue174, by caseyching).
+* Fix parsing of identifiers starting with underscore (issue175).
Enhancements
* Improve formatting of HAVING statements.
diff --git a/sqlparse/lexer.py b/sqlparse/lexer.py
index 5282ad3..999eb2c 100644
--- a/sqlparse/lexer.py
+++ b/sqlparse/lexer.py
@@ -202,7 +202,7 @@ class Lexer(object):
(r'CREATE(\s+OR\s+REPLACE)?\b', tokens.Keyword.DDL),
(r'DOUBLE\s+PRECISION\b', tokens.Name.Builtin),
(r'(?<=\.)[^\W\d_]\w*', tokens.Name),
- (r'[^\W\d_]\w*', is_keyword),
+ (r'[^\W\d]\w*', is_keyword),
(r'[;:()\[\],\.]', tokens.Punctuation),
(r'[<>=~!]+', tokens.Operator.Comparison),
(r'[+/@#%^&|`?^-]+', tokens.Operator),
@@ -292,7 +292,6 @@ class Lexer(object):
for rexmatch, action, new_state in statetokens:
m = rexmatch(text, pos)
if m:
- # print rex.pattern
value = m.group()
if value in known_names:
yield pos, known_names[value], value
diff --git a/tests/test_parse.py b/tests/test_parse.py
index 24eea2d..ad5d2db 100644
--- a/tests/test_parse.py
+++ b/tests/test_parse.py
@@ -145,6 +145,15 @@ def test_quoted_identifier():
assert t[2].get_real_name() == 'y'
+@pytest.mark.parametrize('name', [
+ 'foo',
+ '_foo',
+])
+def test_valid_identifier_names(name): # issue175
+ t = sqlparse.parse(name)[0].tokens
+ assert isinstance(t[0], sqlparse.sql.Identifier)
+
+
def test_psql_quotation_marks(): # issue83
# regression: make sure plain $$ work
t = sqlparse.split("""