def kwatom(self): _token_ = self._peek(self.kwatom_rsts) if _token_ == '":"': pass elif _token_ == 'KWID': KWID = self._scan('KWID') return Literal(parse_bareword(KWID)) elif _token_ == 'KWNUM': KWNUM = self._scan('KWNUM') UNITS = None if self._peek(self.kwatom_rsts_) == 'UNITS': UNITS = self._scan('UNITS') return Literal(Number(float(KWNUM), unit=UNITS)) elif _token_ == 'KWSTR': KWSTR = self._scan('KWSTR') return Literal(String(dequote(KWSTR), quotes="'")) elif _token_ == 'KWQSTR': KWQSTR = self._scan('KWQSTR') return Literal(String(dequote(KWQSTR), quotes='"')) elif _token_ == 'KWCOLOR': KWCOLOR = self._scan('KWCOLOR') return Literal(Color.from_hex(KWCOLOR, literal=True)) else: # == 'KWVAR' KWVAR = self._scan('KWVAR') return Variable(KWVAR)
def _av(m): v = None n = m.group(2) try: v = self.namespace.variable(n) except KeyError: if self.undefined_variables_fatal: raise SyntaxError("Undefined variable: '%s'." % n) else: log.error("Undefined variable '%s'", n, extra={'stack': True}) return n else: if v: if not isinstance(v, Value): raise TypeError( "Somehow got a variable {0!r} " "with a non-Sass value: {1!r}".format( n, v)) v = v.render() # TODO this used to test for _dequote if m.group(1): v = dequote(v) else: v = m.group(0) return v
def _av(m): v = None n = m.group(2) try: v = self.namespace.variable(n) except KeyError: if self.undefined_variables_fatal: raise SyntaxError("Undefined variable: '%s'." % n) else: log.error("Undefined variable '%s'", n, extra={'stack': True}) return n else: if v: if not isinstance(v, Value): raise TypeError( "Somehow got a variable {0!r} " "with a non-Sass value: {1!r}" .format(n, v) ) v = v.render() # TODO this used to test for _dequote if m.group(1): v = dequote(v) else: v = m.group(0) return v
def _pound_substitute(self, result): expr = result.group(1) value = self.evaluate_expression(expr) if value is None: return self.apply_vars(expr) elif value.is_null: return "" else: return dequote(value.render())
def _av(m): v = self.namespace.variable(m.group(2)) if v: v = to_str(v) # TODO this used to test for _dequote if m.group(1): v = dequote(v) else: v = m.group(0) return v
def __init__(self, tokens): self.tokens = tokens if tokens is None: self.value = '' elif isinstance(tokens, ParserValue): self.value = dequote(tokens.value) elif isinstance(tokens, QuotedStringValue): self.value = tokens.value else: self.value = to_str(tokens)
def _calculate_expr(self, result): _group0 = result.group(1) _base_str = _group0 better_expr_str = self.evaluate_expression(_base_str) if better_expr_str is None: better_expr_str = self.apply_vars(_base_str) else: better_expr_str = dequote(str(to_str(better_expr_str))) return better_expr_str
def _av(m): v = self.namespace.variable(m.group(2)) if v: if not isinstance(v, six.string_types): v = v.render() # TODO this used to test for _dequote if m.group(1): v = dequote(v) else: v = m.group(0) return v
def _calculate_expr(self, result): _group0 = result.group(1) _base_str = _group0 better_expr_str = self.evaluate_expression(_base_str) if better_expr_str is None: better_expr_str = self.apply_vars(_base_str) else: better_expr_str = dequote(better_expr_str.render()) return better_expr_str
def _av(m): v = None n = m.group(2) try: v = self.namespace.variable(n) except KeyError: if FATAL_UNDEFINED: raise else: log.error("Undefined variable '%s'", n, extra={'stack': True}) return n else: if v: if not isinstance(v, six.string_types): v = v.render() # TODO this used to test for _dequote if m.group(1): v = dequote(v) else: v = m.group(0) return v
def _av(m): v = None n = m.group(2) try: v = self.namespace.variable(n) except KeyError: if config.FATAL_UNDEFINED: raise SyntaxError("Undefined variable: '%s'." % n) else: if config.VERBOSITY > 1: log.error("Undefined variable '%s'", n, extra={'stack': True}) return n else: if v: if not isinstance(v, six.string_types): v = v.render() # TODO this used to test for _dequote if m.group(1): v = dequote(v) else: v = m.group(0) return v
def atom(self): _token_ = self._peek(self.u_expr_chks) if _token_ == 'LPAR': LPAR = self._scan('LPAR') _token_ = self._peek(self.atom_rsts) if _token_ == 'RPAR': v = ListLiteral([], comma=False) elif _token_ not in self.argspec_item_chks: expr_map = self.expr_map() v = expr_map else: # in self.argspec_item_chks expr_lst = self.expr_lst() v = expr_lst RPAR = self._scan('RPAR') return Parentheses(v) elif _token_ == '"url"': self._scan('"url"') LPAR = self._scan('LPAR') _token_ = self._peek(self.atom_rsts_) if _token_ == 'URL': URL = self._scan('URL') quotes = None elif _token_ == '"\\""': self._scan('"\\""') URL = self._scan('URL') self._scan('"\\""') quotes = '"' else: # == '"\'"' self._scan('"\'"') URL = self._scan('URL') self._scan('"\'"') quotes = "'" RPAR = self._scan('RPAR') return Literal(Url(URL, quotes=quotes)) elif _token_ == 'FNCT': FNCT = self._scan('FNCT') LPAR = self._scan('LPAR') argspec = self.argspec() RPAR = self._scan('RPAR') return CallOp(FNCT, argspec) elif _token_ == 'BANG_IMPORTANT': BANG_IMPORTANT = self._scan('BANG_IMPORTANT') return Literal(String(BANG_IMPORTANT, quotes=None)) elif _token_ == 'ID': ID = self._scan('ID') return Literal(parse_bareword(ID)) elif _token_ == 'NUM': NUM = self._scan('NUM') UNITS = None if self._peek(self.atom_rsts__) == 'UNITS': UNITS = self._scan('UNITS') return Literal(Number(float(NUM), unit=UNITS)) elif _token_ == 'STR': STR = self._scan('STR') return Literal(String(dequote(STR), quotes="'")) elif _token_ == 'QSTR': QSTR = self._scan('QSTR') return Literal(String(dequote(QSTR), quotes='"')) elif _token_ == 'COLOR': COLOR = self._scan('COLOR') return Literal(Color.from_hex(COLOR, literal=True)) else: # == 'VAR' VAR = self._scan('VAR') return Variable(VAR)