Exemplo n.º 1
0
 def exec_add_expression(self, node, local):
     # print node.prepr()
     value = None
     for i, child in enumerate(node.children):
         if i > 0:
             op = child.name
             arg = self.get_val(self.visit(child.children[0], local))
             if op == '.':
                 value = coerce.to_string(value) + coerce.to_string(arg)
             elif op == '+':
                 val_is_array = isinstance(value, phparray.PHPArray)
                 arg_is_array = isinstance(arg, phparray.PHPArray)
                 if val_is_array or arg_is_array:
                     if val_is_array and arg_is_array:
                         value = value + arg
                     else:
                         self.report_error(
                             constants.E_ERROR,
                             'Unsupported operand types in %s on line %d' %
                             (child.filename, child.line_num))
                 else:
                     value = self.coerce_numeric(
                         value) + self.coerce_numeric(arg)
             elif op == '-':
                 value = self.coerce_numeric(value) - self.coerce_numeric(
                     arg)
         else:
             value = self.get_val(self.visit(child, local))
     return value
Exemplo n.º 2
0
 def exec_primitive(self, node, local):
     subnode = node.children[0]
     if isinstance(subnode, parser.Token):
         token = subnode
         if token[0] in (parser.TOKEN_STRING, parser.TOKEN_NUMBER):
             return token[1]
         elif token[0] == parser.TOKEN_IDENTIFIER:
             lcaseid = token[1].lower()
             if lcaseid in primitives:
                 return primitives[lcaseid]
             else:
                 return VarRef(token[1], self, local)
         elif token[0] == parser.TOKEN_VARIABLE:
             # print "Var Ref %r on %r with %r"%(token[1], self, local.prepr())
             return VarRef(token[1], self, local)
         elif token[0] == parser.TOKEN_INTERPOLATED_STRING:
             text = ''.join([
                 coerce.to_string(
                     self.get_val(self.visit(x, local)) if isinstance(
                         x, compiler.TreeNode) else x) for x in token[1]
             ])
             return text
     elif isinstance(subnode, compiler.TreeNode):
         return self.visit(subnode, local)
     raise ExecuteError("invalid primitive %r" % subnode)
Exemplo n.º 3
0
	def exec_add_expression(self, node, local):
		# print node.prepr()
		value = None
		for i, child in enumerate(node.children):
			if i > 0:
				op = child.name
				arg = self.get_val(self.visit(child.children[0], local))
				if op == '.':
					value = coerce.to_string(value) + coerce.to_string(arg)
				elif op == '+':
					val_is_array = isinstance(value, phparray.PHPArray)
					arg_is_array = isinstance(arg, phparray.PHPArray)
					if val_is_array or arg_is_array:
						if val_is_array and arg_is_array:
							value = value + arg
						else:
							self.report_error(constants.E_ERROR, 'Unsupported operand types in %s on line %d'%(child.filename, child.line_num))
					else:
						value = self.coerce_numeric(value) + self.coerce_numeric(arg)
				elif op == '-':
					value = self.coerce_numeric(value) - self.coerce_numeric(arg)
			else:
				value = self.get_val(self.visit(child, local))
		return value
Exemplo n.º 4
0
	def exec_primitive(self, node, local):
		subnode = node.children[0]
		if isinstance(subnode, parser.Token):
			token = subnode
			if token[0] in (parser.TOKEN_STRING, parser.TOKEN_NUMBER):
				return token[1]
			elif token[0] == parser.TOKEN_IDENTIFIER:
				lcaseid = token[1].lower()
				if lcaseid in primitives:
					return primitives[lcaseid]
				else:
					return VarRef(token[1], self, local)
			elif token[0] == parser.TOKEN_VARIABLE:
				# print "Var Ref %r on %r with %r"%(token[1], self, local.prepr())
				return VarRef(token[1], self, local)
			elif token[0] == parser.TOKEN_INTERPOLATED_STRING:
				text = ''.join([coerce.to_string(self.get_val(self.visit(x, local)) if isinstance(x, compiler.TreeNode) else x) for x in token[1]])
				return text
		elif isinstance(subnode, compiler.TreeNode):
			return self.visit(subnode, local)
		raise ExecuteError("invalid primitive %r"%subnode)
Exemplo n.º 5
0
def strtolower(args, executer, local):
    val = executer.get_val(args[0])
    return coerce.to_string(val).lower()
Exemplo n.º 6
0
def strtolower(args, executer, local):
    val = executer.get_val(args[0])
    return coerce.to_string(val).lower()