Skip to content

Commit

Permalink
Merge pull request #139 from qidi1/fix-limit-error
Browse files Browse the repository at this point in the history
fix limit parser not int
  • Loading branch information
qidi1 authored Aug 25, 2023
2 parents 49ed0dc + 83cbe42 commit 7256d07
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/parser/mysql_parser/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ def t_SCONST(t):


def t_NUMBER_START_WITH_XB(t):
r"""[xX]'[0-9A-Fa-f]*'|[bB]'[0-1]*'"""
r"""[-+]?[xX]'[0-9A-Fa-f]*'|[-+]?[bB]'[0-1]*'"""
t.type = "NUMBER"
return t


def t_IDENTIFIER(t):
r"""[a-zA-Z\u4e00-\u9fa50-9_$][a-zA-Z\u4e00-\u9fa50-9_@:$]*"""
if re.match(
r'(^0[xX][0-9a-fA-F]+$)|(^[xX]\'[0-9a-fA-F]+\'$)|(^0[bB][01]+$)|(^[bB]\'[01]+\'$)|(^\d+$)',
r'(^0[xX][0-9a-fA-F]+$)|(^0[bB][01]+$)|(^\d+$)',
t.value,
):
t.type = "NUMBER"
Expand Down
17 changes: 11 additions & 6 deletions src/parser/mysql_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,10 @@ def p_parameterization(p):
r"""parameterization : number
| QM
"""
p[0] = p[1]
if p.slice[1].type == "number":
p[0]=p[1].value
else:
p[0] = p[1]

def p_first_or_next(p):
r"""first_or_next : FIRST
Expand All @@ -693,7 +696,7 @@ def p_row_or_rows(p):

def p_number(p):
r"""number : NUMBER"""
p[0] = p[1]
p[0] = LongLiteral(p.lineno(1), p.lexpos(1), p[1])


def p_set_operation_expressions(p):
Expand Down Expand Up @@ -2680,7 +2683,10 @@ def p_field_param_list(p):
def p_field_parameter(p):
r"""field_parameter : number
| base_data_type"""
p[0] = p[1]
if p.slice[1].type == "number":
p[0]=p[1].value
else:
p[0] = p[1]


def p_float_opt(p):
Expand Down Expand Up @@ -3316,12 +3322,11 @@ def p_quoted_identifier(p):

def p_figure(p):
r"""figure : FRACTION
| NUMBER
| HEX_NUMBER"""
| number"""
if p.slice[1].type == "FRACTION":
p[0] = DoubleLiteral(p.lineno(1), p.lexpos(1), p[1])
else:
p[0] = LongLiteral(p.lineno(1), p.lexpos(1), p[1])
p[0] = p[1]


def p_empty(p):
Expand Down
4 changes: 2 additions & 2 deletions src/parser/oceanbase_parser/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ def t_SCONST(t):


def t_NUMBER_START_WITH_XB(t):
r"""[xX]'[0-9A-Fa-f]*'|[bB]'[0-1]*'"""
r"""[-+]?[xX]'[0-9A-Fa-f]*'|[-+]?[bB]'[0-1]*'"""
t.type = "NUMBER"
return t


def t_IDENTIFIER(t):
r"""[a-zA-Z\u4e00-\u9fa50-9_$][a-zA-Z\u4e00-\u9fa50-9_@:$]*"""
if re.match(
r'(^0[xX][0-9a-fA-F]+$)|(^[xX]\'[0-9a-fA-F]+\'$)|(^0[bB][01]+$)|(^[bB]\'[01]+\'$)|(^\d+$)',
r'(^0[xX][0-9a-fA-F]+$)|(^0[bB][01]+$)|(^\d+$)',
t.value,
):
t.type = "NUMBER"
Expand Down
17 changes: 11 additions & 6 deletions src/parser/oceanbase_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,10 @@ def p_parameterization(p):
r"""parameterization : number
| QM
"""
p[0] = p[1]
if p.slice[1].type == "number":
p[0]=p[1].value
else:
p[0] = p[1]

def p_first_or_next(p):
r"""first_or_next : FIRST
Expand All @@ -687,7 +690,7 @@ def p_row_or_rows(p):

def p_number(p):
r"""number : NUMBER"""
p[0] = p[1]
p[0] = LongLiteral(p.lineno(1), p.lexpos(1), p[1])


def p_set_operation_expressions(p):
Expand Down Expand Up @@ -2756,7 +2759,10 @@ def p_field_param_list(p):
def p_field_parameter(p):
r"""field_parameter : number
| base_data_type"""
p[0] = p[1]
if p.slice[1].type == "number":
p[0]=p[1].value
else:
p[0] = p[1]


def p_float_opt(p):
Expand Down Expand Up @@ -3736,12 +3742,11 @@ def p_quoted_identifier(p):

def p_figure(p):
r"""figure : FRACTION
| NUMBER
| HEX_NUMBER"""
| number"""
if p.slice[1].type == "FRACTION":
p[0] = DoubleLiteral(p.lineno(1), p.lexpos(1), p[1])
else:
p[0] = LongLiteral(p.lineno(1), p.lexpos(1), p[1])
p[0] = p[1]


def p_empty(p):
Expand Down
4 changes: 2 additions & 2 deletions src/parser/odps_parser/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ def t_SCONST(t):


def t_NUMBER_START_WITH_XB(t):
r"""[xX]'[0-9A-Fa-f]*'|[bB]'[0-1]*'"""
r"""[-+]?[xX]'[0-9A-Fa-f]*'|[-+]?[bB]'[0-1]*'"""
t.type = "NUMBER"
return t


def t_IDENTIFIER(t):
r"""[a-zA-Z\u4e00-\u9fa50-9_$][a-zA-Z\u4e00-\u9fa50-9_@:$]*"""
if re.match(
r'(^0[xX][0-9a-fA-F]+$)|(^[xX]\'[0-9a-fA-F]+\'$)|(^0[bB][01]+$)|(^[bB]\'[01]+\'$)|(^\d+$)',
r'(^0[xX][0-9a-fA-F]+$)|(^0[bB][01]+$)|(^\d+$)',
t.value,
):
t.type = "NUMBER"
Expand Down
17 changes: 11 additions & 6 deletions src/parser/odps_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,10 @@ def p_parameterization(p):
r"""parameterization : number
| QM
"""
p[0] = p[1]
if p.slice[1].type == "number":
p[0]=p[1].value
else:
p[0] = p[1]

def p_first_or_next(p):
r"""first_or_next : FIRST
Expand All @@ -688,7 +691,7 @@ def p_row_or_rows(p):

def p_number(p):
r"""number : NUMBER"""
p[0] = p[1]
p[0] = LongLiteral(p.lineno(1), p.lexpos(1), p[1])


def p_set_operation_expressions(p):
Expand Down Expand Up @@ -2765,7 +2768,10 @@ def p_field_param_list(p):
def p_field_parameter(p):
r"""field_parameter : number
| base_data_type"""
p[0] = p[1]
if p.slice[1].type == "number":
p[0]=p[1].value
else:
p[0] = p[1]


def p_float_opt(p):
Expand Down Expand Up @@ -3746,12 +3752,11 @@ def p_quoted_identifier(p):

def p_figure(p):
r"""figure : FRACTION
| NUMBER
| HEX_NUMBER"""
| number"""
if p.slice[1].type == "FRACTION":
p[0] = DoubleLiteral(p.lineno(1), p.lexpos(1), p[1])
else:
p[0] = LongLiteral(p.lineno(1), p.lexpos(1), p[1])
p[0] = p[1]


def p_empty(p):
Expand Down
2 changes: 1 addition & 1 deletion test/parser/test_parser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_get_filter_column(self):
{'ordering': 'desc', 'column_name': 'b'},
]
assert min_max_list == ['age']
assert limit_number == '10'
assert limit_number == 10

def test_get_filter_column2(self):
sql = """SELECT
Expand Down

0 comments on commit 7256d07

Please sign in to comment.