(text)
return lexpr
Logic from string

           e.g.

           !a & !b | c
Logic from string
Logic from string
def fromstring(text):
        """Logic from string

           e.g.

           !a & !b | c
        """
        lexpr = None  # current logical expression
        schedop = None  # scheduled operation
        for term in text.split():
            # operation symbol
            if term in '&|':
                if schedop is not None:
                    raise ValueError(
                        'double op forbidden: "%s %s"' % (term, schedop))
                if lexpr is None:
                    raise ValueError(
                        '%s cannot be in the beginning of expression' % term)
                schedop = term
                continue
            if term[0] == '!':
                term = Not(term[1:])

            # already scheduled operation, e.g. '&'
            if schedop:
                lexpr = Logic.op_2class[schedop](lexpr, term)
                schedop = None
                continue

            # this should be atom
            if lexpr is not None:
                raise ValueError(
                    'missing op between "%s" and "%s"' % (lexpr, term))

            lexpr = term

        # let's check that we ended up in correct state
        if schedop is not None:
            raise ValueError('premature end-of-expression in "%s"' % text)
        if lexpr is None:
            raise ValueError('"%s" is empty' % text)

        # everything looks good now
        return lexpr
def fromstring ( text ) : lexpr = None # current logical expression schedop = None # scheduled operation for term in text . split ( ) : # operation symbol if term in '&|' : if schedop is not None : raise ValueError ( 'double op forbidden: "%s %s"' % ( term , schedop ) ) if lexpr is None : raise ValueError ( '%s cannot be in the beginning of expression' % term ) schedop = term continue if term [ 0 ] == '!' : term = Not ( term [ 1 : ] ) # already scheduled operation, e.g. '&' if schedop : lexpr = Logic . op_2class [ schedop ] ( lexpr , term ) schedop = None continue # this should be atom if lexpr is not None : raise ValueError ( 'missing op between "%s" and "%s"' % ( lexpr , term ) ) lexpr = term # let's check that we ended up in correct state if schedop is not None : raise ValueError ( 'premature end-of-expression in "%s"' % text ) if lexpr is None : raise ValueError ( '"%s" is empty' % text ) # everything looks good now return lexpr