def check_indentation_setup(isetup): """None of the elements 'comment', 'newline', 'newline_suppressor' should not match some subsets of each other. Otherwise, the behavior would be too confusing. """ sm_newline = isetup.sm_newline.get() sm_newline_suppressor = isetup.sm_newline_suppressor.get() sm_comment = isetup.sm_comment.get() candidates = (sm_newline, sm_newline_suppressor, sm_comment) def mutually_subset(Sm1, Sm2): if Sm1 is None or Sm2 is None: return False elif superset_check.do(Sm1, Sm2): return True elif superset_check.do(Sm2, Sm1): return True return False for i, candidate1 in enumerate(candidates): if candidate1 is None: continue for candidate2 in candidates[i + 1:]: if candidate2 is None: continue elif not mutually_subset(candidate1, candidate2): continue c_error_message(candidate1, candidate2, ThisComment="matches on some common lexemes as", ThatComment="")
def check_low_priority_outruns_high_priority_pattern(self): """Warn when low priority patterns may outrun high priority patterns. Assume that the pattern list is sorted by priority! """ for high, low in self.unique_pattern_pair_iterable(): if outrun_checker.do(high.sm, low.sm): c_error_message(low, high, ExitF=False, ThisComment="may outrun")
def check_dominated_pattern(self, ErrorCode): for high, low in self.unique_pattern_pair_iterable(): # 'low' comes after 'high' => 'i' has precedence # Check for domination. if superset_check.do(high, low): c_error_message(high, low, ThisComment = "matches a superset of what is matched by", EndComment = "The former has precedence and the latter can never match.", ExitF = True, SuppressCode = ErrorCode)
def check_special_incidence_outrun(self, ErrorCode): for high, low in self.unique_pattern_pair_iterable(): if high.pattern_string() not in Mode.focus \ and low.pattern_string() not in Mode.focus: continue elif not outrun_checker.do(high.sm, low.sm): continue c_error_message(high, low, ExitF=True, ThisComment = "has lower priority but", ThatComment = "may outrun", SuppressCode = ErrorCode)
def check_higher_priority_matches_subset(self, ErrorCode): """Checks whether a higher prioritized pattern matches a common subset of the ReferenceSM. For special patterns of skipper, etc. this would be highly confusing. """ global special_pattern_list for high, low in self.unique_pattern_pair_iterable(): if high.pattern_string() not in Mode.focus \ and low.pattern_string() not in Mode.focus: continue if not superset_check.do(high.sm, low.sm): continue c_error_message(high, low, ExitF=True, ThisComment = "has higher priority and", ThatComment = "matches a subset of", SuppressCode = ErrorCode)
def check_match_same(self, ErrorCode): """Special patterns shall never match on some common lexemes.""" for high, low in self.unique_pattern_pair_iterable(): if high.pattern_string() not in Mode.focus \ and low.pattern_string() not in Mode.focus: continue # A superset of B, or B superset of A => there are common matches. if not same_check.do(high.sm, low.sm): continue # The 'match what remains' is exempted from check. if high.pattern_string() == "." or low.pattern_string() == ".": continue c_error_message(high, low, ThisComment = "matches on some common lexemes as", ThatComment = "", ExitF = True, SuppressCode = ErrorCode)
def check_indentation_setup(isetup): """None of the elements 'comment', 'newline', 'newline_suppressor' should not match some subsets of each other. Otherwise, the behavior would be too confusing. """ sm_newline = isetup.sm_newline.get() sm_newline_suppressor = isetup.sm_newline_suppressor.get() sm_comment = isetup.sm_comment.get() candidates = (sm_newline, sm_newline_suppressor, sm_comment) def mutually_subset(Sm1, Sm2): if Sm1 is None or Sm2 is None: return False elif superset_check.do(sm_newline, sm_newline_suppressor): return True elif superset_check.do(sm_newline_suppressor, sm_newline): return True return False for i, candidate1 in enumerate(candidates): if candidate1 is None: continue for candidate2 in candidates[i+1:]: if candidate2 is None: continue elif not mutually_subset(candidate1, candidate2): continue c_error_message(candidate1, candidate2, ThisComment="matches on some common lexemes as", ThatComment="")