コード例 #1
0
ファイル: counter.py プロジェクト: yifsun/amplify
 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)
コード例 #2
0
 def indentation_count_character_set(self):
     """Returns the superset of all characters that are involved in
        indentation counting. That is the set of character that can
        appear between newline and the first non whitespace character.
     """
     result = NumberSet()
     for character_set in self.space_db.values():
         result.unite_with(character_set.get())
     for character_set in self.grid_db.values():
         result.unite_with(character_set.get())
     return result
コード例 #3
0
ファイル: indentation_setup.py プロジェクト: liancheng/rose
 def indentation_count_character_set(self):
     """Returns the superset of all characters that are involved in
        indentation counting. That is the set of character that can
        appear between newline and the first non whitespace character.
     """
     result = NumberSet()
     for character_set in self.space_db.values():
         result.unite_with(character_set.get())
     for character_set in self.grid_db.values():
         result.unite_with(character_set.get())
     return result
コード例 #4
0
ファイル: parser.py プロジェクト: dkopecek/amplify
    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
コード例 #5
0
    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
コード例 #6
0
ファイル: counter.py プロジェクト: yifsun/amplify
    def __whitespace_default(self):
        """Try to define default whitespace ' ' or '\t' if their positions
        are not yet occupied in the count_command_map.
        """
        cs0 = NumberSet(ord(" "))
        cs1 = NumberSet(ord("\t"))
        result = NumberSet()
        if not self.count_command_map.find_occupier(cs0, set()):
            result.unite_with(cs0)
        if not self.count_command_map.find_occupier(cs1, set()):
            result.unite_with(cs1)

        if result.is_empty():
            error_msg("Trying to implement default whitespace ' ' or '\\t' failed.\n"
                      "Characters are occupied by other elements.", self.sr)
        return result
コード例 #7
0
ファイル: target_map.py プロジェクト: dkopecek/amplify
    def is_DFA_compliant(self):
        """Checks if the current state transitions are DFA compliant, i.e. it
           investigates if trigger sets pointing to different targets intersect.
           RETURNS:  True  => OK
                    False => Same triggers point to different target. This cannot
                             be part of a deterministic finite automaton (DFA).
        """
        # DFA's do not have epsilon transitions
        if len(self.__epsilon_target_index_list) != 0: return False

        # check whether trigger sets intersect
        all_trigger_sets = NumberSet()
        for trigger_set in self.__db.itervalues():
            if all_trigger_sets.has_intersection(trigger_set): 
                return False
            else:
                all_trigger_sets.unite_with(trigger_set)

        return True
コード例 #8
0
ファイル: transition_map.py プロジェクト: liancheng/rose
    def is_DFA_compliant(self):
        """Checks if the current state transitions are DFA compliant, i.e. it
           investigates if trigger sets pointing to different targets intersect.
           RETURN:  True  => OK
                    False => Same triggers point to different target. This cannot
                             be part of a deterministic finite automaton (DFA).
        """
        # DFA's do not have epsilon transitions
        if len(self.__epsilon_target_index_list) != 0: return False

        # check whether trigger sets intersect
        all_trigger_sets = NumberSet()
        for trigger_set in self.__db.values():
            if all_trigger_sets.has_intersection(trigger_set):
                return False
            else:
                all_trigger_sets.unite_with(trigger_set)

        return True
コード例 #9
0
ファイル: parser.py プロジェクト: dkopecek/amplify
    def get_character_set(self, Value=None):
        """Returns the character set that corresponds to 'Property==Value'.
           'Value' can be a property value or a property value alias.
           For binary properties 'Value' must be None.
        """
        assert self.type != "Binary" or Value is None

        def get_value_combination(CmbAlias):
            result = []
            for alias in self.alias_to_alias_combination_db[CmbAlias]:
                name = self.alias_to_name_map.get(alias)
                if name is None:
                    return "Unicode database error: no name related to alias '%s'" % alias
                result.append(name)
            return result

        if self.type != "Binary" and Value is None:
            return "Property '%s' requires a value setting.\n" % self.name + \
                   "Possible Values: " + \
                   self.get_value_list_help()

        if self.code_point_db is None:
            self.init_code_point_db()

        if self.type == "Binary": 
            # Decouple, since we refer to an internal database
            return deepcopy(self.code_point_db)

        adapted_value = Value.replace(" ", "_")

        if   self.code_point_db.has_key(adapted_value): 
            # 'value' is present as name in the code point database
            value = adapted_value

        elif Value in self.alias_to_name_map.keys():
            # 'value' is present as alias in code pointer database
            value = self.alias_to_name_map[adapted_value]

        elif Value in self.alias_to_alias_combination_db.keys():
            # 'value' is present as a combination of aliases
            value = get_value_combination(adapted_value)

        elif self.name_to_alias_map.has_key(adapted_value):
            # The value was a combination of values
            value = get_value_combination(self.name_to_alias_map[adapted_value])

        else:
            # -- WILDCARD MATCH: Results in a list of property values  
            character_set = self.__wildcard_value_match(adapted_value)
            if character_set is None:
                return "Property '%s' cannot have a value or value alias '%s'.\n" % (self.name, Value) + \
                       "Possible Values: " + \
                       self.get_value_list_help()
            # No need to decouple, since character is not a reference to
            # internal database (for safety, do it)
            return deepcopy(character_set)

        if type(value) == list:
            result = NumberSet()
            for element in value:
                if element == "Unassigned": continue
                entry = self.code_point_db.get(element)
                if entry is None:
                    return "%s/%s is not supported by Unicode database." % (self.name, repr(element))
                result.unite_with(entry)
        else:
            result = self.code_point_db.get(value)
            if result is None:
                return "%s/%s is not supported by Unicode database." % (self.name, repr(value))

        # Reference to internal database --> decouple with 'deepcopy'
        return deepcopy(result)
コード例 #10
0
 def do(DB):
     combined = NumberSet()
     for number_set in DB.itervalues():
         assert not number_set.has_intersection(combined)
         combined.unite_with(number_set)
コード例 #11
0
ファイル: target_map.py プロジェクト: dkopecek/amplify
 def get_trigger_set_union(self):
     result = NumberSet()
     for trigger_set in self.__db.itervalues():
         result.unite_with(trigger_set)
     return result
コード例 #12
0
ファイル: blackboard.py プロジェクト: coderjames/pascal
 def do(DB):
     combined = NumberSet()
     for number_set in DB.itervalues():
         assert not number_set.has_intersection(combined)
         combined.unite_with(number_set)
コード例 #13
0
    def get_character_set(self, Value=None):
        """Returns the character set that corresponds to 'Property==Value'.
           'Value' can be a property value or a property value alias.
           For binary properties 'Value' must be None.
        """
        assert self.type != "Binary" or Value is None

        def get_value_combination(CmbAlias):
            result = []
            for alias in self.alias_to_alias_combination_db[CmbAlias]:
                name = self.alias_to_name_map.get(alias)
                if name is None:
                    return "Unicode database error: no name related to alias '%s'" % alias
                result.append(name)
            return result

        if self.type != "Binary" and Value is None:
            return "Property '%s' requires a value setting.\n" % self.name + \
                   "Possible Values: " + \
                   self.get_value_list_help()

        if self.code_point_db is None:
            self.init_code_point_db()

        if self.type == "Binary":
            # Decouple, since we refer to an internal database
            return deepcopy(self.code_point_db)

        adapted_value = Value.replace(" ", "_")

        if self.code_point_db.has_key(adapted_value):
            # 'value' is present as name in the code point database
            value = adapted_value

        elif Value in self.alias_to_name_map.keys():
            # 'value' is present as alias in code pointer database
            value = self.alias_to_name_map[adapted_value]

        elif Value in self.alias_to_alias_combination_db.keys():
            # 'value' is present as a combination of aliases
            value = get_value_combination(adapted_value)

        elif self.name_to_alias_map.has_key(adapted_value):
            # The value was a combination of values
            value = get_value_combination(
                self.name_to_alias_map[adapted_value])

        else:
            # -- WILDCARD MATCH: Results in a list of property values
            character_set = self.__wildcard_value_match(adapted_value)
            if character_set is None:
                return "Property '%s' cannot have a value or value alias '%s'.\n" % (self.name, Value) + \
                       "Possible Values: " + \
                       self.get_value_list_help()
            # No need to decouple, since character is not a reference to
            # internal database (for safety, do it)
            return deepcopy(character_set)

        if type(value) == list:
            result = NumberSet()
            for element in value:
                if element == "Unassigned": continue
                entry = self.code_point_db.get(element)
                if entry is None:
                    return "%s/%s is not supported by Unicode database." % (
                        self.name, repr(element))
                result.unite_with(entry)
        else:
            result = self.code_point_db.get(value)
            if result is None:
                return "%s/%s is not supported by Unicode database." % (
                    self.name, repr(value))

        # Reference to internal database --> decouple with 'deepcopy'
        return deepcopy(result)
コード例 #14
0
ファイル: transition_map.py プロジェクト: liancheng/rose
    def get_trigger_set_union(self):
        result = NumberSet()
        for trigger_set in self.__db.values():
            result.unite_with(trigger_set)

        return result
コード例 #15
0
def _get_all_character_set(*DbList):
    result = NumberSet()
    for db in DbList:
        for character_set in db.itervalues():
            result.unite_with(character_set)
    return result
コード例 #16
0
    def covers(self, Min, Max):
        result = NumberSet()

        for info in self.__map:
            result.unite_with(info.character_set)
        return result.covers_range(Min, Max)