def expr_slst(self): or_expr = self.or_expr() v = [or_expr] while self._peek(self.expr_slst_rsts) not in self.expr_slst_chks: or_expr = self.or_expr() v.append(or_expr) return ListLiteral(v, comma=False) if len(v) > 1 else v[0]
def expr_map_or_list(self): expr_slst = self.expr_slst() first = expr_slst _token_ = self._peek(self.expr_map_or_list_rsts) if _token_ == '":"': self._scan('":"') expr_slst = self.expr_slst() pairs = [(first, expr_slst)] while self._peek(self.expr_map_or_list_rsts_) == '","': self._scan('","') map_item = None, None if self._peek(self.expr_map_or_list_rsts__ ) not in self.expr_map_or_list_rsts_: map_item = self.map_item() pairs.append(map_item) return MapLiteral(pairs) else: # in self.expr_map_or_list_rsts_ items = [first] use_list = False while self._peek(self.expr_map_or_list_rsts_) == '","': self._scan('","') use_list = True expr_slst = self.expr_slst() items.append(expr_slst) return ListLiteral(items) if use_list else items[0]
def expr_lst(self): expr_slst = self.expr_slst() v = [expr_slst] while self._peek(self.expr_lst_rsts) == '","': self._scan('","') expr_slst = self.expr_slst() v.append(expr_slst) return ListLiteral(v) if len(v) > 1 else v[0]
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) else: # in self.argspec_item_chks expr_map_or_list = self.expr_map_or_list() v = expr_map_or_list RPAR = self._scan('RPAR') return Parentheses(v) elif _token_ == 'URL_FUNCTION': URL_FUNCTION = self._scan('URL_FUNCTION') LPAR = self._scan('LPAR') interpolated_url = self.interpolated_url() RPAR = self._scan('RPAR') return interpolated_url elif _token_ == 'ALPHA_FUNCTION': ALPHA_FUNCTION = self._scan('ALPHA_FUNCTION') LPAR = self._scan('LPAR') _token_ = self._peek(self.atom_rsts_) if _token_ == '"opacity"': self._scan('"opacity"') self._scan('"="') atom = self.atom() RPAR = self._scan('RPAR') return AlphaFunctionLiteral(atom) else: # in self.atom_chks argspec = self.argspec() RPAR = self._scan('RPAR') return CallOp("alpha", argspec) elif _token_ == 'LITERAL_FUNCTION': LITERAL_FUNCTION = self._scan('LITERAL_FUNCTION') LPAR = self._scan('LPAR') interpolated_function = self.interpolated_function() RPAR = self._scan('RPAR') return Interpolation.maybe(interpolated_function, type=Function, function_name=LITERAL_FUNCTION) 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.unquoted("!important", literal=True)) elif _token_ in self.atom_chks_: interpolated_bareword = self.interpolated_bareword() return Interpolation.maybe(interpolated_bareword) 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_ not in self.atom_chks__: interpolated_string = self.interpolated_string() return interpolated_string elif _token_ == 'COLOR': COLOR = self._scan('COLOR') return Literal(Color.from_hex(COLOR, literal=True)) else: # == 'VAR' VAR = self._scan('VAR') return Variable(VAR)