def __core(Original, Cutter): print("Original = " + Original).replace("\n", "\\n").replace("\t", "\\t") print("Cutter = " + Cutter).replace("\n", "\\n").replace("\t", "\\t") orig = regex.do(Original, {}).extract_sm() cutter = regex.do(Cutter, {}).extract_sm() #print orig.get_string(NormalizeF=False) #print cutter.get_string(NormalizeF=False) # ComplementBegin = intersection(P, complement(Q)\Any*) result = derived.not_begin(orig, cutter) print if not result.is_Empty(): print "superset(Original, result): %s" % superset.do( orig, result) if not result.is_Empty(): tmp = clean(intersection.do([cutter, result])) print "intersection(Cutter, result) is None: %s" % tmp.is_Empty() tmp = clean(union.do([orig, result])) print "union(Original, result) == Original: %s" % identity.do( tmp, orig) print print "result = ", result.get_string(NormalizeF=True) assert_considerations(orig, cutter, result) return result
def __indentation_setup_check(mode): indentation_setup = mode.options["indentation"] if indentation_setup is None: return # The newline pattern shall not have intersections with other patterns! newline_info = indentation_setup.newline_state_machine newline_suppressor_info = indentation_setup.newline_suppressor_state_machine assert newline_info is not None if newline_suppressor_info.get() is None: return # Newline and newline suppressor should never have a superset/subset relation if superset_check.do(newline_info.get(), newline_suppressor_info.get()) \ or superset_check.do(newline_suppressor_info.get(), newline_info.get()): __error_message(newline_info, newline_suppressor_info, ThisComment="matches on some common lexemes as", ThatComment="")
def assert_considerations(A, B, result): """Set of rules which must hold in case the '\NotBegin' has been applied. """ assert superset.do(A, result) assert intersection.do([result, B]).is_Empty() assert identity.do(union.do([result, A]), A) assert intersection.do([result, derived.is_begin(A, B)]).is_Empty() assert identity.do(union.do([result, derived.is_begin(A, B)]), A)
def do(element, history): priority, pattern, terminal = element if priority.mode_hierarchy_index > MHI: return False elif priority.pattern_index >= Info.pattern_index: return False elif not superset_check.do(Info.pattern, pattern): return False history.append( [ModeName, pattern.pattern_string(), pattern.sr.mode_name]) return True
def __core(SuperPattern, SubPattern): print("super = " + SuperPattern).replace("\n", "\\n").replace("\t", "\\t") print("sub = " + SubPattern).replace("\n", "\\n").replace("\t", "\\t") super_p = regex.do(SuperPattern, {}).finalize(None) sub_p = regex.do(SubPattern, {}).finalize(None) verdict_f = superset.do(super_p, sub_p) print "claim = ", verdict_f
def __indentation_setup_check(mode): indentation_setup = mode.options["indentation"] if indentation_setup is None: return # The newline pattern shall not have intersections with other patterns! newline_info = indentation_setup.newline_state_machine newline_suppressor_info = indentation_setup.newline_suppressor_state_machine assert newline_info is not None if newline_suppressor_info.get() is None: return # Newline and newline suppressor should never have a superset/subset relation if superset_check.do(newline_info.get(), newline_suppressor_info.get()) \ or superset_check.do(newline_suppressor_info.get(), newline_info.get()): __error_message(newline_info, newline_suppressor_info, ThisComment="matches on some common lexemes as", ThatComment="")
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_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 __dominated_pattern_check(mode, PAP): pattern_id = PAP.pattern().sm.get_id() for other_pap in mode.get_pattern_action_pair_list(): if other_pap.pattern().sm.get_id() >= pattern_id: continue if superset_check.do(other_pap.pattern(), PAP.pattern()): file_name, line_n = other_pap.get_action_location() __error_message(other_pap, PAP, ThisComment = "matches a superset of what is matched by", EndComment = "The former has precedence and the latter can never match.", ExitF = True)
def __core(SuperPattern, SubPattern): print ("super = " + SuperPattern).replace("\n", "\\n").replace("\t", "\\t") print ("sub = " + SubPattern).replace("\n", "\\n").replace("\t", "\\t") super_p = regex.do(SuperPattern, {}) super_p.mount_post_context_sm() super_p.mount_pre_context_sm() sub_p = regex.do(SubPattern, {}) sub_p.mount_post_context_sm() sub_p.mount_pre_context_sm() # print "##super:", super_p # print "##sub:", sub_p print "claim = ", superset.do(super_p, sub_p)
def test(SmList): print "-------------------------------------------------------------------------------" for tsm in SmList: print "##sm:", tsm sm = parallelize.do(SmList) print "RESULT:", sm complement_sm = complement.do(sm) assert all(superset.do(sm, tsm) == True for tsm in SmList) assert all( DFA.is_Empty(intersection.do([complement_sm, tsm])) for tsm in SmList)
def __core(SuperPattern, SubPattern): print("super = " + SuperPattern).replace("\n", "\\n").replace("\t", "\\t") print("sub = " + SubPattern).replace("\n", "\\n").replace("\t", "\\t") super_p = regex.do(SuperPattern, {}) super_p.mount_post_context_sm() super_p.mount_pre_context_sm() sub_p = regex.do(SubPattern, {}) sub_p.mount_post_context_sm() sub_p.mount_pre_context_sm() # print "##super:", super_p # print "##sub:", sub_p print "claim = ", superset.do(super_p, sub_p)
def __dominated_pattern_check(mode, PAP): pattern_id = PAP.pattern().sm.get_id() for other_pap in mode.get_pattern_action_pair_list(): if other_pap.pattern().sm.get_id() >= pattern_id: continue if superset_check.do(other_pap.pattern(), PAP.pattern()): file_name, line_n = other_pap.get_action_location() __error_message( other_pap, PAP, ThisComment="matches a superset of what is matched by", EndComment= "The former has precedence and the latter can never match.", ExitF=True)
def __subset_check(mode, PAP): """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 ReferenceSM = PAP.pattern().sm for other_pap in mode.get_pattern_action_pair_list(): sm = other_pap.pattern().sm if ReferenceSM.get_id() <= sm.get_id(): continue elif not superset_check.do(ReferenceSM, sm): continue __error_message(other_pap, PAP, ExitF=True, ThisComment="has higher priority and", ThatComment="matches a subset of")
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_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 __subset_check(mode, PAP): """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 ReferenceSM = PAP.pattern().sm for other_pap in mode.get_pattern_action_pair_list(): sm = other_pap.pattern().sm if ReferenceSM.get_id() <= sm.get_id(): continue elif not superset_check.do(ReferenceSM, sm): continue __error_message(other_pap, PAP, ExitF=True, ThisComment="has higher priority and", ThatComment="matches a subset of")
def __core(Original, Cutter): print ("Original = " + Original).replace("\n", "\\n").replace("\t", "\\t") print ("Cutter = " + Cutter).replace("\n", "\\n").replace("\t", "\\t") orig = regex.do(Original, {}).sm cutter = regex.do(Cutter, {}).sm #print orig.get_string(NormalizeF=False) #print cutter.get_string(NormalizeF=False) result = clean(complement_end.do(orig, cutter)) print if not special.is_none(result): print "superset(Original, result): %s" % superset.do(orig, result) if not special.is_none(result): tmp = clean(intersection.do([cutter, result])) print "intersection(Cutter, result) is None: %s" % special.is_none(tmp) tmp = clean(union.do([orig, result])) print "union(Original, result) == Original: %s" % identity.do(tmp, orig) print print "result = ", result.get_string(NormalizeF=True)
def delete(MHI, Info, ppt_list, ModeName, history): done_f = False size = len(ppt_list) i = 0 while i < size: priority, pattern, terminal = ppt_list[i] if priority.mode_hierarchy_index <= MHI \ and priority.pattern_index < Info.pattern_index \ and superset_check.do(Info.pattern, pattern): done_f = True del ppt_list[i] history.append([ModeName, pattern.pattern_string(), pattern.sr.mode_name]) size -= 1 else: i += 1 if not done_f and Info.sr.mode_name == ModeName: error.warning("DELETION mark does not have any effect.", Info.sr)
def delete(MHI, Info, ppt_list, ModeName, history): done_f = False size = len(ppt_list) i = 0 while i < size: priority, pattern, terminal = ppt_list[i] if priority.mode_hierarchy_index <= MHI \ and priority.pattern_index < Info.pattern_index \ and superset_check.do(Info.pattern, pattern): done_f = True del ppt_list[i] history.append([ModeName, pattern.pattern_string(), pattern.sr.mode_name]) size -= 1 else: i += 1 if not done_f and Info.sr.mode_name == ModeName: error_msg("DELETION mark does not have any effect.", Info.sr.file_name, Info.sr.line_n, DontExitF=True)
def __core(Original, Cutter): print("Original = " + Original).replace("\n", "\\n").replace("\t", "\\t") print("Cutter = " + Cutter).replace("\n", "\\n").replace("\t", "\\t") orig = regex.do(Original, {}).sm cutter = regex.do(Cutter, {}).sm #print orig.get_string(NormalizeF=False) #print cutter.get_string(NormalizeF=False) result = clean(complement_end.do(orig, cutter)) print if not special.is_none(result): print "superset(Original, result): %s" % superset.do( orig, result) if not special.is_none(result): tmp = clean(intersection.do([cutter, result])) print "intersection(Cutter, result) is None: %s" % special.is_none( tmp) tmp = clean(union.do([orig, result])) print "union(Original, result) == Original: %s" % identity.do( tmp, orig) print print "result = ", result.get_string(NormalizeF=True)
def commonality(A, B): return superset.do(A, B) or superset.do(B, A)
out_n = 0 def output(Sm): global out_n if "help" not in sys.argv: print "sm%i: %s" % (out_n, Sm) else: open("tmp%i.dot" % out_n, "wb").write(Sm.get_graphviz_string(NormalizeF=True)) print "written 'tmp%i.dot'" % out_n out_n += 1 sm0.mark_state_origins() sm1.mark_state_origins() sm2.mark_state_origins() output(sm0) output(sm1) output(sm2) sm_list = [sm0, sm1, sm2] sm = parallelize.do(sm_list) print "#-------------------------------------------------------------------------------" output(sm) complement_sm = complement.do(sm) assert all(superset.do(sm, tsm) == True for tsm in sm_list) assert all(DFA.is_Empty(intersection.do([complement_sm, tsm])) for tsm in sm_list) print "<terminated>"
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
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
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
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
def assert_considerations(A, B, result): assert superset.do(A, result) assert intersection.do([result, B]).is_Empty() assert identity.do(union.do([result, A]), A) assert intersection.do([result, derived.is_in(A, B)]).is_Empty() assert identity.do(union.do([result, derived.is_in(A, B)]), A)