当前位置: 首页>>代码示例>>Python>>正文


Python interval_handling.NumberSet类代码示例

本文整理汇总了Python中quex.engine.misc.interval_handling.NumberSet的典型用法代码示例。如果您正苦于以下问题:Python NumberSet类的具体用法?Python NumberSet怎么用?Python NumberSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NumberSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

    def get(self):
        # Transform 'cursor' into a number set
        result = NumberSet()
        K   = len(self.__cursor)
        if K == 0: return None
        k   = 0
        end = 0
        while k < K - 1:
            begin = end   + self.__cursor[k]
            end   = begin + self.__cursor[k+1]
            if end > self.N: 
                self.__cursor.pop()
                K -= 1
                break
            if begin != end:
                result.quick_append_interval(Interval(begin, end))
            k += 2

        # Increment cursor
        k = 0
        while k < K:
            if k == 0:
                self.__cursor[k] += 2
                if self.__cursor[k] < 8: 
                    break
            else:
                self.__cursor[k] += 1
                if self.__cursor[k] < 3:
                    break
            self.__cursor[k] = 1
            k += 1

        return result
开发者ID:mplucinski,项目名称:quex,代码行数:33,代码来源:test-NumberSet-mmcc.py

示例2: buffer_codec_prepare

    def buffer_codec_prepare(self, BufferCodecName, BufferCodecFileName=None, Module=None):
        """Determines: Setup.buffer_codec_name
                       Setup.buffer_codec
        """
        assert    BufferCodecName == "unit-test" \
               or self.__buffer_element_specification_done_f == True

        if   BufferCodecName in ("utf8", "utf16"):
            assert Module is not None
            result = codec_db.CodecDynamicInfo(BufferCodecName, Module)
        elif BufferCodecFileName:
            os.path.splitext(os.path.basename(BufferCodecFileName))
            try: 
               os.path.splitext(os.path.basename(BufferCodecFileName))
            except:
                error.log("cannot interpret string following '--codec-file'")
            result = codec_db.CodecTransformationInfo(FileName=BufferCodecFileName)
        elif BufferCodecName == "unicode":
            # (Still, 'icu' or 'iconv' may provide converted content, but ...) 
            # If the internal buffer is 'unicode', then the pattern's state 
            # machines are not converted. The requirement for the pattern's
            # range is the same as for the 'buffer element chunks'.
            result = codec_db.CodecInfo("unicode", 
                                NumberSet.from_range(0, self.get_character_value_limit()), 
                                NumberSet.from_range(0, self.get_character_value_limit()))
        elif BufferCodecName == "unit-test":
            result = codec_db.CodecInfo("unicode", 
                                NumberSet.from_range(-sys.maxint, sys.maxint),
                                NumberSet.from_range(-sys.maxint, sys.maxint))

        else:
            result = codec_db.CodecTransformationInfo(BufferCodecName)

        self.buffer_codec = result
开发者ID:mplucinski,项目名称:quex,代码行数:34,代码来源:setup.py

示例3: general_checks

def general_checks(loop_map, appendix_sm_list):
    print "#_[ Checks ]__________________________________________________"
    print
    print "character sets do not intersect",
    all_set = NumberSet()
    for lei in loop_map:
        assert lei.character_set is not None
        assert not lei.character_set.has_intersection(all_set)
        all_set.unite_with(lei.character_set)
    print "[ok]"

    print "count actions do not appear more than once",
    count_action_couple_set = set()
    count_action_plain_set  = set()
    exit_exists_f           = False
    appendix_sm_id_set      = set()
    for lei in loop_map:
        if lei.count_action is None: 
            assert lei.appendix_sm_id is None
            exit_exists_f = True
        elif lei.appendix_sm_id is None:
            assert lei.incidence_id not in count_action_plain_set
            count_action_plain_set.add(lei.incidence_id)
        else:
            assert lei.incidence_id not in count_action_couple_set
            count_action_couple_set.add(lei.incidence_id)
            appendix_sm_id_set.add(lei.appendix_sm_id)
    print "[ok]"
    list_id_set = set(sm.get_id() for sm in appendix_sm_list)
    assert appendix_sm_id_set == list_id_set
    print "appendix sm-ids are the same in loop map and sm list: [ok]"
    print "exit character set exits: [%s]" % exit_exists_f

    print
开发者ID:xxyzzzq,项目名称:quex,代码行数:34,代码来源:loop-get_loop_map.py

示例4: __init__

 def __init__(self):
     EncodingTrafoBySplit.__init__(self, "utf16", 
                                      CodeUnitRange=NumberSet.from_range(0, 0x10000))
     self.error_range_code_unit0 = NumberSet([
         Interval(0x0000, 0xDC00), Interval(0xE000, 0x10000)
     ]).get_complement(NumberSet_All())
     self.error_range_code_unit1 = NumberSet([
         Interval(0xDC00, 0xE000)
     ]).get_complement(NumberSet_All())
开发者ID:xxyzzzq,项目名称:quex,代码行数:9,代码来源:utf16_state_split.py

示例5: __get_remaining_set

 def __get_remaining_set(self):
     ignored = (E_CharacterCountType.BAD, 
                E_CharacterCountType.BEGIN_NEWLINE_SUPPRESSOR, 
                E_CharacterCountType.BEGIN_NEWLINE, 
                E_CharacterCountType.END_NEWLINE) 
     result  = NumberSet()
     for character_set, info in self.__map:
         if info.cc_type in ignored: continue
         result.unite_with(character_set)
     return result.get_complement(Setup.buffer_codec.source_set)
开发者ID:xxyzzzq,项目名称:quex,代码行数:10,代码来源:counter.py

示例6: load_Composition_Exclusion

    def load_Composition_Exclusion(self):
        # Column 0 contains what is interesting ...
        table = parse_table("CompositionExclusions.txt", NumberColumnList=[0])

        number_set = NumberSet()
        for row in table:
           begin = row[0]
           number_set.quick_append_interval(Interval(begin, begin + 1))
        number_set.clean()    

        self.db["CE"].code_point_db = number_set
开发者ID:mplucinski,项目名称:quex,代码行数:11,代码来源:parser.py

示例7: prepare

def prepare(A_list, B_list):
    A = NumberSet()
    B = NumberSet()
    for begin, end in A_list:
        A.add_interval(Interval(begin, end))
    for begin, end in B_list:
        B.add_interval(Interval(begin, end))

    A.assert_consistency()
    B.assert_consistency()
    return A, B
开发者ID:mplucinski,项目名称:quex,代码行数:11,代码来源:test-NumberSet-is_superset.py

示例8: verify

def verify(A, TrafoInfo):
    result = NumberSet()
    for interval in A.get_intervals():
        for x in range(interval.begin, interval.end):
            for source_begin, source_end, target_begin in TrafoInfo:
                if x >= source_begin and x < source_end:
                    offset = x - source_begin
                    y      = target_begin + offset
                    result.add_interval(Interval(y))
    result.assert_consistency()
    return result
开发者ID:xxyzzzq,项目名称:quex,代码行数:11,代码来源:test-NumberSet-transform.py

示例9: get_ending_character_set

 def get_ending_character_set(self):
     """Returns the union of all characters that trigger to an acceptance
        state in the given state machine. This is to detect whether the
        newline or suppressor end with an indentation character (grid or space).
     """
     result = NumberSet()
     for end_state_index in self.get_acceptance_state_index_list():
         for state in self.states.itervalues():
             if state.target_map.has_target(end_state_index) == False: continue
             result.unite_with(state.target_map.get_trigger_set_to_target(end_state_index))
     return result
开发者ID:mplucinski,项目名称:quex,代码行数:11,代码来源:core.py

示例10: test

 def test(X):
     print "#_______________________________________________"
     nset  = NumberSet([ Interval(x, y) for x, y in X])
     clone = nset.clone()
     print "#NumberSet:         %s" % nset
     result = nset.clone()
     result.complement(all)
     print "#NumberSet.inverse: %s" % result
     assert result.is_equal(nset.get_complement(all))
     assert result.intersection(nset).is_empty()
     assert result.union(nset).is_all()
开发者ID:mplucinski,项目名称:quex,代码行数:11,代码来源:test-NumberSet-inverse.py

示例11: the_intersection

def the_intersection(Comment, A, B):
    if B.__class__ == Interval: B = NumberSet(B)

    print "#\n#" + Comment
    print "#  A          = " + repr(A)
    print "#  B          = " + repr(B)
    result = A.intersection(B)
    result.assert_consistency()
    print "#  intersection(A,B) = " + repr(result)
    result = B.intersection(A)
    result.assert_consistency()
    print "#  intersection(B,A) = " + repr(result)
开发者ID:mplucinski,项目名称:quex,代码行数:12,代码来源:test-NumberSet-intersection.py

示例12: __wildcard_value_match

    def __wildcard_value_match(self, WildCardValue):
        result = NumberSet()

        value_list = self.get_wildcard_value_matches(WildCardValue)
        if len(value_list) == 0: 
            return None

        for value in value_list:
            result.unite_with(NumberSet(self.code_point_db[value]))

        # No decoupling, since result is computed each fresh and new
        return result
开发者ID:mplucinski,项目名称:quex,代码行数:12,代码来源:parser.py

示例13: _get_loop_map

def _get_loop_map(TheCountMap, SmList, IidLoopExit):
    """A loop map tells about the behavior of the core loop. It tells what
    needs to happen as a consequence to an incoming character. Two options:

        -- Return to loop (normal case)
        -- Enter the tail (appendix) of a parallel state machine.

    RETURNS: List of LoopMapEntry-s. 

    A LoopMapEntry consists of:

       .character_set: Character set that triggers.
       .count_action:  Count action related to the character set.
                       == None, if the character set causes 'loop exit'.
       .incidence_id:  Incidence Id of terminal that is triggered by character set.
                       -- incidence id of count action terminal, or
                       -- incidence id of couple terminal.
       .appendix_sm:   Appendix state machine
                       -- combined appendix state machines, or
                       -- None, indicating that there is none.
    """
    L = TheCountMap.loop_character_set()

    # 'couple_list': Transitions to 'couple terminals' 
    #                => connect to appendix state machines
    couple_list,     \
    appendix_sm_list = _get_LoopMapEntry_list_parallel_state_machines(TheCountMap, 
                                                                      SmList)

    L_couple = NumberSet.from_union_of_iterable(
        lei.character_set for lei in couple_list
    )

    # 'plain_list': Transitions to 'normal terminals' 
    #               => perform count action and loop.
    L_plain    = L.difference(L_couple)
    plain_list = _get_LoopMapEntry_list_plain(TheCountMap, L_plain)

    # 'L_exit': Transition to exit
    #           => remaining characters cause exit.
    L_loop = NumberSet.from_union_of_iterable(
        x.character_set for x in chain(couple_list, plain_list)
    )
    universal_set = Setup.buffer_codec.source_set
    L_exit        = L_loop.get_complement(universal_set)
    exit_list     = [ LoopMapEntry(L_exit, None, IidLoopExit, None) ]

    result = couple_list + plain_list + exit_list

    assert not any(lei is None for lei in result)
    assert not any(lei.character_set is None for lei in result)
    assert not any(lei.incidence_id is None for lei in result)
    return result, appendix_sm_list
开发者ID:xxyzzzq,项目名称:quex,代码行数:53,代码来源:loop.py

示例14: create_ALL_BUT_NEWLINE_state_machine

def create_ALL_BUT_NEWLINE_state_machine(stream):
    global Setup
    result = StateMachine()
    # NOTE: Buffer control characters are supposed to be filtered out by the code
    #       generator.
    trigger_set = NumberSet(Interval(ord("\n"))).get_complement(Setup.buffer_codec.source_set)
    if trigger_set.is_empty():
        error.log("The set of admissible characters contains only newline.\n"
                  "The '.' for 'all but newline' is an empty set.",
                  SourceRef.from_FileHandle(stream))

    result.add_transition(result.init_state_index, trigger_set, AcceptanceF=True) 
    return result
开发者ID:mplucinski,项目名称:quex,代码行数:13,代码来源:engine.py

示例15: __init__

    def __init__(self):
        drain_set = NumberSet.from_range(0, 0x100)
        EncodingTrafoBySplit.__init__(self, "utf8", CodeUnitRange=drain_set)
        self.UnchangedRange = 0x7F

        self.error_range_byte0 = NumberSet([
            Interval(0b00000000, 0b01111111+1), Interval(0b11000000, 0b11011111+1),
            Interval(0b11100000, 0b11101111+1), Interval(0b11110000, 0b11110111+1),
            Interval(0b11111000, 0b11111011+1), Interval(0b11111100, 0b11111101+1),
        ]).get_complement(NumberSet_All())

        self.error_range_byteN = NumberSet(
            Interval(0b10000000, 0b10111111+1)
        ).get_complement(NumberSet_All())
开发者ID:xxyzzzq,项目名称:quex,代码行数:14,代码来源:utf8_state_split.py


注:本文中的quex.engine.misc.interval_handling.NumberSet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。