Ejemplo n.º 1
0
 def _parse_arg(self, var, arg, scope):
     """
     """
     if type(var) is Variable:
         # kwarg
         if arg:
             if utility.is_variable(arg[0]):
                 tmp = scope.variables(arg[0])
                 if not tmp: return None
                 val = tmp.value
             else:
                 val = arg
             var = Variable(var.tokens[:-1] + [val])
     else:
         #arg
         if utility.is_variable(var):
             if arg is None:
                 raise SyntaxError('Missing argument to mixin')
             elif utility.is_variable(arg[0]):
                 tmp = scope.variables(arg[0])
                 if not tmp: return None
                 val = tmp.value
             else:
                 val = arg
             var = Variable([var, None, val])
         else:
             return None
     return var
Ejemplo n.º 2
0
 def _parse_arg(self, var, arg, scope):
     """ Parse a single argument to mixin.
     args:
         var (Variable object): variable
         arg (mixed): argument
         scope (Scope object): current scope
     returns:
         Variable object or None
     """
     if type(var) is Variable:
         # kwarg
         if arg:
             if utility.is_variable(arg[0]):
                 tmp = scope.variables(arg[0])
                 if not tmp: return None
                 val = tmp.value
             else:
                 val = arg
             var = Variable(var.tokens[:-1] + [val])
     else:
         #arg
         if utility.is_variable(var):
             if arg is None:
                 raise SyntaxError('Missing argument to mixin')
             elif utility.is_variable(arg[0]):
                 tmp = scope.variables(arg[0])
                 if not tmp: return None
                 val = tmp.value
             else:
                 val = arg
             var = Variable([var, None, val])
         else:
             return None
     return var
Ejemplo n.º 3
0
 def process(self, tokens, scope):
     """ Process tokenslist, flattening and parsing it
     args:
         tokens (list): tokenlist
         scope (Scope): Current scope
     returns:
         list
     """
     while True:
         tokens = list(utility.flatten(tokens))
         done = True
         if any(t for t in tokens if hasattr(t, 'parse')):
             tokens = [
                 t.parse(scope) if hasattr(t, 'parse') else t
                 for t in tokens
             ]
             done = False
         if any(
                 t for t in tokens
                 if (utility.is_variable(t)) or str(type(t)) ==
                 "<class 'lesscpy.plib.variable.Variable'>"):
             tokens = self.replace_variables(tokens, scope)
             done = False
         if done:
             break
     return tokens
Ejemplo n.º 4
0
 def replace_variables(self, tokens, scope):
     """ Replace variables in tokenlist
     args:
         tokens (list): tokenlist
         scope (Scope): Current scope
     returns:
         list
     """
     return [scope.swap(t)
             if utility.is_variable(t)
             else t 
             for t in tokens]
Ejemplo n.º 5
0
 def _parse_arg(self, var, arg, scope):
     """ Parse a single argument to mixin.
     args:
         var (Variable object): variable
         arg (mixed): argument
         scope (Scope object): current scope
     returns:
         Variable object or None
     """
     if isinstance(var, Variable):
         # kwarg
         if arg:
             if utility.is_variable(arg[0]):
                 tmp = scope.variables(arg[0])
                 if not tmp:
                     return None
                 val = tmp.value
             else:
                 val = arg
             var = Variable(var.tokens[:-1] + [val])
     else:
         # arg
         if utility.is_variable(var):
             if arg is None:
                 raise SyntaxError('Missing argument to mixin')
             elif utility.is_variable(arg[0]):
                 tmp = scope.variables(arg[0])
                 if not tmp:
                     return None
                 val = tmp.value
             else:
                 val = arg
             var = Variable([var, None, val])
         else:
             return None
     return var
Ejemplo n.º 6
0
 def replace_variables(self, tokens, scope):
     """ Replace variables in tokenlist
     args:
         tokens (list): tokenlist
         scope (Scope): Current scope
     returns:
         list
     """
     list = []
     for t in tokens:
         if utility.is_variable(t):
             list.append(scope.swap(t))
         elif str(type(t)) == "<class 'lesscpy.plib.variable.Variable'>":
             list.append(scope.swap(t.name))
         else:
             list.append(t)
     return list
Ejemplo n.º 7
0
 def replace_variables(self, tokens, scope):
     """ Replace variables in tokenlist
     args:
         tokens (list): tokenlist
         scope (Scope): Current scope
     returns:
         list
     """
     list = []
     for t in tokens:
         if utility.is_variable(t):
             list.append(scope.swap(t))
         elif str(type(t)) == "<class 'lesscpy.plib.variable.Variable'>":
             list.append(scope.swap(t.name))
         else:
             list.append(t)
     return list
Ejemplo n.º 8
0
 def process(self, tokens, scope):
     """ Process tokenslist, flattening and parsing it
     args:
         tokens (list): tokenlist
         scope (Scope): Current scope
     returns:
         list
     """
     while True:
         tokens = list(utility.flatten(tokens))
         done = True
         if any(t for t in tokens if hasattr(t, 'parse')):
             tokens = [
                 t.parse(scope) if hasattr(t, 'parse') else t
                 for t in tokens
             ]
             done = False
         if any(t for t in tokens if (utility.is_variable(t)) or str(type(
                 t)) == "<class 'lesscpy.plib.variable.Variable'>"):
             tokens = self.replace_variables(tokens, scope)
             done = False
         if done:
             break
     return tokens
Ejemplo n.º 9
0
 def replace_variables(tokens, scope):
     return [scope.swap(t)
             if (utility.is_variable(t) and not t in reserved.tokens)
             else t
             for t in tokens]
 def replace_variables(tokens, scope):
     return [
         scope.swap(t) if
         (utility.is_variable(t) and not t in reserved.tokens) else t
         for t in tokens
     ]