예제 #1
0
파일: python.py 프로젝트: mathjazz/silme
    def transform_value(self, l20nval):
        val = None
        breaks_static = False

        if is_string(l20nval):
            if isinstance(l20nval, l20n.ComplexStringValue):
                s = self.transform_complex_string(l20nval)
                if not isinstance(s, py.Idref):
                    s = py.Str(s)
                breaks_static = True
            else:
                s = py.Str(l20nval)
            val = s
        return (val, breaks_static)
예제 #2
0
파일: python.py 프로젝트: mathjazz/silme
 def transform_expression(self, exp):
     if isinstance(exp, l20n.Expander):
         return self.transform_expression(exp.expression)
     if isinstance(exp, l20n.ConditionalExpression):
         jsexp = py.ConditionalExpression()
         jsexp.append(self.transform_expression(exp[0]))
         jsexp.append(self.transform_expression(exp[1]))
         jsexp.append(self.transform_expression(exp[2]))
         return jsexp
     if isinstance(exp, l20n.EqualityExpression):
         jsexp = py.EqualityExpression()
     if isinstance(exp, l20n.RelationalExpression):
         jsexp = py.RelationalExpression()
     if isinstance(exp, l20n.OrExpression):
         jsexp = py.OrExpression()
     if isinstance(exp, l20n.AndExpression):
         jsexp = py.AndExpression()
     if isinstance(exp, l20n.MultiplicativeExpression):
         jsexp = py.MultiplicativeExpression()
     if isinstance(exp, l20n.UnaryExpression):
         jsexp = py.UnaryExpression()
     if isinstance(exp, l20n.OperatorExpression):
         for n,i in enumerate(exp):
             if n%2==1:
                 jsexp.append(i)
             else:
                 jsexp.append(self.transform_expression(i))
         return jsexp
     if isinstance(exp, l20n.BraceExpression):
         jsexp = py.BraceExpression()
         jsexp.append(self.transform_expression(exp[0]))
         return jsexp 
     if isinstance(exp, l20n.Idref):
         if len(exp)==1:
             index = py.Index(py.Idref('env'), py.Str(exp[0]))
             index.idref = py.Idref('env')
         return index
     if is_string(exp):
         return py.Str(unicode(exp))
     if isinstance(exp, int):
         return py.Int(exp)
     if isinstance(exp, l20n.MacroCall):
         args = map(self.transform_expression, exp.args)
         args2 = [py.Idref('env'), py.Array(args)]
         return py.Call(self.transform_expression(exp.idref), args2)
     if isinstance(exp, l20n.ObjectIndex):
         return py.Index(self.transform_expression(exp.idref),
                         self.transform_expression(exp.arg))
예제 #3
0
    def add(self, item, pos=None):
        """adds an element (string, entity or comment) to the Structure
        pos - if given addes an element at given position

        returns a number representing how many new elements have been added
          Usually one, but if a new string gets added and is concatanated
          to previous/next one the value will be 0.
        """
        if is_string(item):  # string
            return self.add_string(item, pos)
        elif is_entity(item):  # Entity
            return self.add_entity(item, pos)
        elif isinstance(item, Comment):  # Comment
            return self.add_comment(item, pos)
        elif item is None:
            return 0
        else:
            raise Exception('Cannot add element of type "' +
                            type(item).__name__ +
                            '" to the Structure')