예제 #1
0
    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
예제 #2
0
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="") 
예제 #3
0
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)
예제 #4
0
 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
예제 #5
0
 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
예제 #6
0
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="")
예제 #7
0
파일: mode.py 프로젝트: xxyzzzq/quex
 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)
예제 #8
0
파일: mode.py 프로젝트: dkopecek/amplify
 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)
예제 #9
0
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)
예제 #10
0
 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)
예제 #11
0
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)
예제 #12
0
 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)
예제 #13
0
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)
예제 #14
0
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")
예제 #15
0
파일: mode.py 프로젝트: dkopecek/amplify
    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)
예제 #16
0
파일: mode.py 프로젝트: xxyzzzq/quex
    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)
예제 #17
0
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")
예제 #18
0
 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)
예제 #19
0
    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)
예제 #20
0
    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)
예제 #21
0
 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)
예제 #22
0
def commonality(A, B):
    return superset.do(A, B) or superset.do(B, A)
예제 #23
0
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>"
예제 #24
0
 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
예제 #25
0
 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
예제 #26
0
 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
예제 #27
0
 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
예제 #28
0
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)