diff --git a/core/rule_generator.py b/core/rule_generator.py index 0d3f001..b210550 100644 --- a/core/rule_generator.py +++ b/core/rule_generator.py @@ -3680,7 +3680,7 @@ def parse_validate(pattern: str, rewrite: str) -> Tuple[bool, str, int]: patternASTJson = mosql.parse(pattern) except Exception as e: #if mosql error, find index of the offending part - var = re.search("[Ee]xpecting(.*)found \"(.*)\" \(at char (\d+)", RuleGenerator.dereplaceVars(e.message, mapping)) + var = re.search(r"[Ee]xpecting(.*)found \"(.*)\" \(at char (\d+)", RuleGenerator.dereplaceVars(e.message, mapping)) if var: errorindex2 = int(var.group(3)) - ScopeInfoLength[patternScope] return False, "Error in first query, current Scope is " + ScopeInfo[patternScope] + " if that is not intended check spelling at index 0. Expecting " + var.group(1).strip() + " found " + var.group(2).strip(), errorindex2 @@ -3694,14 +3694,14 @@ def parse_validate(pattern: str, rewrite: str) -> Tuple[bool, str, int]: except Exception as e: #checks case that there are variables in the rewrite that are not in the original query partialSQL = RuleGenerator.extractPartialSQL(rewrite, rewriteScope) - regexPattern = VarTypesInfo[VarType.Var]['markerStart'] + '(\w+)' + VarTypesInfo[VarType.Var]['markerEnd'] + regexPattern = VarTypesInfo[VarType.Var]['markerStart'] + r'(\w+)' + VarTypesInfo[VarType.Var]['markerEnd'] var = re.search(regexPattern, partialSQL) if var: #returns the index of variable that is not in first query return False, str(var.group()) + "not in first rule", var.start() # if all variables present, then mosql error, find index of the offending part - var = re.search("[Ee]xpecting(.*)found \"(.*)\" \(at char (\d+)", RuleGenerator.dereplaceVars(e.message, mapping)) + var = re.search(r"[Ee]xpecting(.*)found \"(.*)\" \(at char (\d+)", RuleGenerator.dereplaceVars(e.message, mapping)) if var: errorindex2 = int(var.group(3)) - ScopeInfoLength[patternScope] return False, "Error in second query, current Scope is " + ScopeInfo[patternScope] + " if that is not intended check spelling at index 0. Expecting " + var.group(1).strip() + " found " + var.group(2).strip(), errorindex2 @@ -3763,7 +3763,7 @@ def parse_validate_single(pattern: str) -> Tuple[bool, str, int]: return True, "success", 0 except Exception as e: #if mosql error, find index of the offending part - var = re.search("[Ee]xpecting(.*)found \"(.*)\" \(at char (\d+)", RuleGenerator.dereplaceVars(e.message, mapping)) + var = re.search(r"[Ee]xpecting(.*)found \"(.*)\" \(at char (\d+)", RuleGenerator.dereplaceVars(e.message, mapping)) if var: errorindex2 = int(var.group(3)) - ScopeInfoLength[patternScope] return False, "Error in first query, current Scope is " + ScopeInfo[patternScope] + " if that is not intended check spelling at index 0. Expecting " + var.group(1).strip() + " found " + var.group(2).strip(), errorindex2 diff --git a/core/rule_parser.py b/core/rule_parser.py index d7cf910..f0de16d 100644 --- a/core/rule_parser.py +++ b/core/rule_parser.py @@ -122,7 +122,7 @@ def replaceVars(pattern: str, rewrite: str) -> Tuple[str, str, dict]: # common function to replace one VarType # def replaceVars(pattern: str, rewrite: str, varType: VarType, mapping: dict) -> Tuple[str, str]: - regexPattern = VarTypesInfo[varType]['markerStart'] + '(\w+)' + VarTypesInfo[varType]['markerEnd'] + regexPattern = VarTypesInfo[varType]['markerStart'] + r'(\w+)' + VarTypesInfo[varType]['markerEnd'] vars = re.findall(regexPattern, pattern) varInternalBase = VarTypesInfo[varType]['internalBase'] varInternalCount = 1 @@ -235,13 +235,13 @@ def parse_actions(actions: str, mapping: str) -> list: @staticmethod def find_malformed_brackets(pattern: str) -> int: CommonMistakeVarTypesInfo = { - 'markerStart': ['\(', '\{', '\['], - 'markerEnd': ['\)', '\}', '\]'], + 'markerStart': [r'\(', r'\{', r'\['], + 'markerEnd': [r'\)', r'\}', r'\]'], } for i in range(len(CommonMistakeVarTypesInfo['markerStart'])): - regexPatternVarStart = CommonMistakeVarTypesInfo['markerStart'][i] + '(\w+)' + VarTypesInfo[VarType.Var]['markerEnd'] - regexPatternVarEnd = VarTypesInfo[VarType.Var]['markerStart'] + '(\w+)' + CommonMistakeVarTypesInfo['markerEnd'][i] + regexPatternVarStart = CommonMistakeVarTypesInfo['markerStart'][i] + r'(\w+)' + VarTypesInfo[VarType.Var]['markerEnd'] + regexPatternVarEnd = VarTypesInfo[VarType.Var]['markerStart'] + r'(\w+)' + CommonMistakeVarTypesInfo['markerEnd'][i] varStart = re.search(regexPatternVarStart, pattern) varEnd = re.search(regexPatternVarEnd, pattern) diff --git a/tests/test_ast.py b/tests/test_ast.py index d6006a4..3296398 100644 --- a/tests/test_ast.py +++ b/tests/test_ast.py @@ -234,8 +234,6 @@ def test_complete_query(): # Analyze query structure clause_types = [child.type for child in query.children] print(f" Clause types: {[ct.value for ct in clause_types]}") - - return query def test_varsql_pattern_matching(): @@ -274,9 +272,6 @@ def test_varsql_pattern_matching(): multi_select = SelectNode({var_columns}) print(f"\nVarSet pattern for multiple columns:") print(f" VarSet {var_columns.name} can match multiple SELECT items") - - return pattern_query - def test_node_relationships(): """Test node relationships and tree structure"""