Skip to content

Commit

Permalink
Allow identifiers to start with an underscore (fixes #175).
Browse files Browse the repository at this point in the history
  • Loading branch information
andialbrecht committed Mar 1, 2015
1 parent 811b69a commit 15b0cb9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions sqlparse/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -292,7 +292,6 @@ def get_tokens_unprocessed(self, stream, stack=('root',)):
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
Expand Down
9 changes: 9 additions & 0 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("""
Expand Down

0 comments on commit 15b0cb9

Please sign in to comment.