def _convert_rules_bubble(self, srules=''):
        """srules, a string containing the rules in bubble format will be
        converted to the internal list of dictonary based rules.
        '>>>': seperator  : a rule has only certain amount of seperators
        a rule is built like: >>>input>>>function>>>output>>>
        for example:
        >>>i>>>adder>>>o>>>>
        >>>42>>>is_it_the_answer>>>the_answer>>>

        is converted to:
        [{'in':'i','fun':'adder','out':'o'},
         {'in':'42','fun':'is_it_the_answer','out':'the_answer'}]

        a rule withhout a name, but with a depency on rule_one
        >>>panic>>>is_there_an_answer>>>dont_panic>>>rule_one>>>

        a rule without depencies and a name
        >>>42>>>is_it_the_answer>>>the_answer>>>nodeps>>rule_one>>>
        """

        if not isinstance(srules, str):
            self.cry('convert_rules_bubble: cannot convert srules of type,' +
                     'list of rules ==> [] :' + str(type(srules)),
                     stuff=srules,
                     verbosity=10)
            return []

        if not srules:
            self.say('convert_rules_bubble: cannot convert empty srules',
                     verbosity=10)
            return []  # no rules

        lines = srules.splitlines()
        self.say('convert_rules_bubble:lines', stuff=lines, verbosity=10)

        line_number = 0
        rules = []
        for r in lines:
            line_number += 1
            # todo: do we wan't this in a configuration, yes! add magic!
            # in util.escaped it's defined as an escape
            # but for rules it is best to define a magic value something like
            # BMGC.TRANSFORMER.RULES_SEPERATOR  #seems better option for
            # or
            # BMGC.TRANSFORMER_RULES_SEPERATOR  #seems simpler
            # BMGC should implement a sane default magic for undefined values.

            r = r.strip()
            if not r.endswith('>>>'):
                continue
            if not r.startswith('>>>'):
                continue

            parts = [p.strip() for p in r.split('>>>')]

            rule = None
            lp = len(parts)
            if lp == 3:
                rule = Rule(input=parts[1],
                            src_nr=line_number)
            if lp == 4:
                rule = Rule(input=parts[1],
                            fun=parts[2],
                            src_nr=line_number)
            if lp == 5:
                rule = Rule(input=parts[1],
                            fun=parts[2],
                            output=parts[3],
                            src_nr=line_number)
            if lp == 6:
                rule = Rule(input=parts[1],
                            fun=parts[2],
                            output=parts[3],
                            depend=parts[4],
                            src_nr=line_number)
            if lp == 7:
                rule = Rule(input=parts[1],
                            fun=parts[2],
                            output=parts[3],
                            depend=parts[4],
                            name=parts[5],
                            src_nr=line_number)

            if rule:
                rules.append(rule)
            else:
                self.cry(
                    'parts not 3..7 rule with parts[' + str(lp) +
                    '] from line:[' + str(line_number) + ']\n\'' + r + '\'',
                    verbosity=10)

        for r in rules:
            r.set_parent(self)
        self._rules = rules
        self.say('convert_rules_bubble:res:rules', stuff=rules, verbosity=10)
        return rules
def _convert_rules_bubble ( self , srules = '' ) : if not isinstance ( srules , str ) : self . cry ( 'convert_rules_bubble: cannot convert srules of type,' + 'list of rules ==> [] :' + str ( type ( srules ) ) , stuff = srules , verbosity = 10 ) return [ ] if not srules : self . say ( 'convert_rules_bubble: cannot convert empty srules' , verbosity = 10 ) return [ ] lines = srules . splitlines ( ) self . say ( 'convert_rules_bubble:lines' , stuff = lines , verbosity = 10 ) line_number = 0 rules = [ ] for r in lines : line_number += 1 r = r . strip ( ) if not r . endswith ( '>>>' ) : continue if not r . startswith ( '>>>' ) : continue parts = [ p . strip ( ) for p in r . split ( '>>>' ) ] rule = None lp = len ( parts ) if lp == 3 : rule = Rule ( input = parts [ 1 ] , src_nr = line_number ) if lp == 4 : rule = Rule ( input = parts [ 1 ] , fun = parts [ 2 ] , src_nr = line_number ) if lp == 5 : rule = Rule ( input = parts [ 1 ] , fun = parts [ 2 ] , output = parts [ 3 ] , src_nr = line_number ) if lp == 6 : rule = Rule ( input = parts [ 1 ] , fun = parts [ 2 ] , output = parts [ 3 ] , depend = parts [ 4 ] , src_nr = line_number ) if lp == 7 : rule = Rule ( input = parts [ 1 ] , fun = parts [ 2 ] , output = parts [ 3 ] , depend = parts [ 4 ] , name = parts [ 5 ] , src_nr = line_number ) if rule : rules . append ( rule ) else : self . cry ( 'parts not 3..7 rule with parts[' + str ( lp ) + '] from line:[' + str ( line_number ) + ']\n\'' + r + '\'' , verbosity = 10 ) for r in rules : r . set_parent ( self ) self . _rules = rules self . say ( 'convert_rules_bubble:res:rules' , stuff = rules , verbosity = 10 ) return rules
srules, a string containing the rules in bubble format will be
        converted to the internal list of dictonary based rules.
        '>>>': seperator  : a rule has only certain amount of seperators
        a rule is built like: >>>input>>>function>>>output>>>
        for example:
        >>>i>>>adder>>>o>>>>
        >>>42>>>is_it_the_answer>>>the_answer>>>

        is converted to:
        [{'in':'i','fun':'adder','out':'o'},
         {'in':'42','fun':'is_it_the_answer','out':'the_answer'}]

        a rule withhout a name, but with a depency on rule_one
        >>>panic>>>is_there_an_answer>>>dont_panic>>>rule_one>>>

        a rule without depencies and a name
        >>>42>>>is_it_the_answer>>>the_answer>>>nodeps>>rule_one>>>