Skip to content

Commit

Permalink
parser: Allow double quoted identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
dnicolodi committed Sep 30, 2023
1 parent bca732c commit e17f346
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
4 changes: 3 additions & 1 deletion beanquery/parser/bql.ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ list
@name
identifier
= /[a-zA-Z_][a-zA-Z0-9_]*/
=
| /[a-zA-Z_][a-zA-Z0-9_]*/
| /\"([^\"]+)\"/
;
asterisk
Expand Down
11 changes: 10 additions & 1 deletion beanquery/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,7 @@ def block3():
self._error(
'expecting one of: '
'<identifier> [a-zA-Z_][a-zA-Z0-9_]*'
'\\"([^\\"]+)\\"'
)

@tatsumasu('Column')
Expand Down Expand Up @@ -1104,7 +1105,15 @@ def block1():
@tatsumasu()
@isname
def _identifier_(self): # noqa
self._pattern('[a-zA-Z_][a-zA-Z0-9_]*')
with self._choice():
with self._option():
self._pattern('[a-zA-Z_][a-zA-Z0-9_]*')
with self._option():
self._pattern('\\"([^\\"]+)\\"')
self._error(
'expecting one of: '
'[a-zA-Z_][a-zA-Z0-9_]* \\"([^\\"]+)\\"'
)

@tatsumasu()
def _asterisk_(self): # noqa
Expand Down
19 changes: 19 additions & 0 deletions beanquery/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ def test_select(self):
ast.Target(ast.Column('position'), 'y')
]))

def test_quoted_identifier(self):
self.assertParse(
"""SELECT 1 AS "foo";""",
Select([
ast.Target(ast.Constant(1), 'foo'),
]))

self.assertParse(
"""SELECT 1 AS "foo bar";""",
Select([
ast.Target(ast.Constant(1), 'foo bar'),
]))

self.assertParse(
"""SELECT 2 AS "1 + 1";""",
Select([
ast.Target(ast.Constant(2), '1 + 1'),
]))

def test_literals(self):
# null
self.assertParseTarget("SELECT NULL;", ast.Constant(None))
Expand Down

0 comments on commit e17f346

Please sign in to comment.