예제 #1
0
 def parse(self, scope):
     """ Parse Node
     args:
         scope (Scope): Scope object
     raises:
         SyntaxError
     returns:
         str
     """
     assert(len(self.tokens) == 3)
     expr = self.process(self.tokens, scope)
     expr = [self.neg(t, scope) for t in expr]
     A, O, B = [e[0]
                if isinstance(e, tuple)
                else e
                for e in expr
                if str(e).strip()]
     try:
         a, ua = utility.analyze_number(A, 'Illegal element in expression')
         b, ub = utility.analyze_number(B, 'Illegal element in expression')
     except SyntaxError:
         return ' '.join([str(A), str(O), str(B)])
     if(a is False or b is False):
         return ' '.join([str(A), str(O), str(B)])
     if ua == 'color' or ub == 'color':
         return color.Color().process((A, O, B))
     if a == 0 and O == '/':
         # NOTE(saschpe): The ugliest but valid CSS since sliced bread: 'font: 0/1 a;'
         return ''.join([str(A), str(O), str(B), ' '])
     out = self.operate(a, b, O)
     if isinstance(out, bool):
         return out
     return self.with_units(out, ua, ub)
예제 #2
0
 def parse(self, scope):
     """ Parse Node
     args:
         scope (Scope): Scope object
     raises:
         SyntaxError
     returns:
         str
     """
     assert(len(self.tokens) == 3)
     expr = self.process(self.tokens, scope)
     expr = [self.neg(t, scope) for t in expr]
     A, O, B = [e[0] 
                if type(e) is tuple 
                else e 
                for e in expr
                if str(e).strip()]
     try:
         a, ua = utility.analyze_number(A, 'Illegal element in expression')
         b, ub = utility.analyze_number(B, 'Illegal element in expression')
     except SyntaxError:
         return ' '.join([str(A), str(O), str(B)])
     if(a is False or b is False):
         return ' '.join([str(A), str(O), str(B)])
     if ua == 'color' or ub == 'color':
         return color.Color().process((A, O, B))
     out = self.operate(a, b, O)
     if type(out) is bool:
         return out
     return self.with_units(out, ua, ub)
예제 #3
0
 def floor(self, value, *args):
     """ Floor number
     args:
         value (str): target
     returns:
         str
     """
     n, u = utility.analyze_number(value)
     return utility.with_unit(int(math.floor(n)), u)
예제 #4
0
 def ceil(self, value, *args):
     """ Ceil number
     args:
         value (str): target
     returns:
         str
     """
     n, u = utility.analyze_number(value)
     return utility.with_unit(int(math.ceil(n)), u)
예제 #5
0
 def round(self, value, *args):
     """ Round number
     args:
         value (str): target
     returns:
         str
     """
     n, u = utility.analyze_number(value)
     return utility.with_unit(int(utility.away_from_zero_round(float(n))), u)
예제 #6
0
 def decrement(self, value, *args):
     """ Decrement function
     args:
         value (str): target
     returns:
         str
     """
     n, u = utility.analyze_number(value)
     return utility.with_unit(n - 1, u)
예제 #7
0
 def floor(self, value, *args):
     """ Floor number
     args:
         value (str): target
     returns:
         str
     """
     n, u = utility.analyze_number(value)
     return utility.with_unit(int(math.floor(n)), u)
예제 #8
0
 def ceil(self, value, *args):
     """ Ceil number
     args:
         value (str): target
     returns:
         str
     """
     n, u = utility.analyze_number(value)
     return utility.with_unit(int(math.ceil(n)), u)
예제 #9
0
 def decrement(self, value, *args):
     """ Decrement function
     args:
         value (str): target
     returns:
         str
     """
     n, u = utility.analyze_number(value)
     return utility.with_unit(n - 1, u)
예제 #10
0
 def round(self, value, *args):
     """ Round number
     args:
         value (str): target
     returns:
         str
     """
     n, u = utility.analyze_number(value)
     return utility.with_unit(int(utility.away_from_zero_round(float(n))),
                              u)
예제 #11
0
 def percentage(self, value, *args):
     """ Return percentage value
     args:
         value (str): target
     returns:
         str
     """
     n, u = utility.analyze_number(value)
     n = int(n * 100.0)
     u = '%'
     return utility.with_unit(n, u)
예제 #12
0
 def percentage(self, value, *args):
     """ Return percentage value
     args:
         value (str): target
     returns:
         str
     """
     n, u = utility.analyze_number(value)
     n = int(n * 100.0)
     u = '%'
     return utility.with_unit(n, u)
예제 #13
0
 def isnumber(self, string, *args):
     """Is number
     args:
         string (str): match
     returns:
         bool
     """
     try:
         n, u = utility.analyze_number(string)
     except SyntaxError:
         return False
     return True
예제 #14
0
 def isnumber(self, string, *args):
     """Is number
     args:
         string (str): match
     returns:
         bool
     """
     try:
         n, u = utility.analyze_number(string)
     except SyntaxError:
         return False
     return True