Skip to content

Commit 6ec0d9c

Browse files
committed
add >> and <<
1 parent 559c6be commit 6ec0d9c

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

mindsdb_sql_parser/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ def __init__(self, lexer, parser):
1313
self.parser = parser
1414
self.lexer = lexer
1515

16-
def process(self, error_info):
16+
def process(self) -> str:
17+
error_info = self.parser.error_info
1718
self.tokens = [t for t in error_info['tokens'] if t is not None]
1819
self.bad_token = error_info['bad_token']
1920
self.expected_tokens = error_info['expected_tokens']
@@ -175,7 +176,7 @@ def parse_sql(sql, dialect=None):
175176
if ast is None:
176177

177178
eh = ErrorHandling(lexer, parser)
178-
message = eh.process(parser.error_info)
179+
message = eh.process()
179180

180181
raise ParsingException(message)
181182

mindsdb_sql_parser/lexer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class MindsDBLexer(Lexer):
7272

7373
# Operators
7474
PLUS, MINUS, MATCH, NOT_MATCH, DIVIDE, MODULO,
75-
EQUALS, NEQUALS, GREATER, GEQ, LESS, LEQ,
75+
RIGHT_SHIFT, LEFT_SHIFT, EQUALS, NEQUALS, GREATER, GEQ, LESS, LEQ,
7676
AND, OR, NOT, IS, IS_NOT, TYPECAST,
7777
IN, NOT_IN, LIKE, NOT_LIKE, CONCAT, BETWEEN, WINDOW, OVER, PARTITION_BY,
7878
VECT_L2, VECT_L1, VECT_INNER, VECT_COS, VECT_HAMM, VECT_JACC,
@@ -296,6 +296,8 @@ class MindsDBLexer(Lexer):
296296
NOT_MATCH = r'!~'
297297
DIVIDE = r'/'
298298
MODULO = r'%'
299+
RIGHT_SHIFT = r'>>'
300+
LEFT_SHIFT = r'<<'
299301
EQUALS = r'='
300302
NEQUALS = r'(!=|<>)'
301303
GEQ = r'>='

mindsdb_sql_parser/parser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,8 @@ def star(self, p):
16331633
'expr MODULO expr',
16341634
'expr EQUALS expr',
16351635
'expr NEQUALS expr',
1636+
'expr RIGHT_SHIFT expr',
1637+
'expr LEFT_SHIFT expr',
16361638
'expr GEQ expr',
16371639
'expr GREATER expr',
16381640
'expr GEQ LAST',

tests/test_base_sql/test_base_lexer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ def test_binary_ops(self):
120120
('>=', 'GEQ'),
121121
('<', 'LESS'),
122122
('<=', 'LEQ'),
123+
('>>', 'RIGHT_SHIFT'),
124+
('<<', 'LEFT_SHIFT'),
123125
('AND', 'AND'),
124126
('OR', 'OR'),
125127
('IS', 'IS'),

tests/test_base_sql/test_select_operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class TestOperations:
88
def test_select_binary_operations(self):
9-
for op in ['+', '-', '/', '*', '%', '=', '!=', '>', '<', '>=', '<=',
9+
for op in ['+', '-', '/', '*', '%', '=', '!=', '>', '<', '>=', '<=', '>>', '<<',
1010
'is', 'IS NOT', 'like', 'in', 'and', 'or', '||']:
1111
sql = f'SELECT column1 {op.upper()} column2 FROM tab'
1212
ast = parse_sql(sql)

0 commit comments

Comments
 (0)