remove unwrap in peek_ident
This commit is contained in:
parent
e5cceb60ec
commit
8d4b4bedbe
@ -105,10 +105,10 @@ pub(crate) fn parse_for<I: Iterator<Item = Token>>(
|
||||
devour_whitespace(toks);
|
||||
let mut from_toks = Vec::new();
|
||||
let mut through = 0;
|
||||
while let Some(tok) = toks.peek() {
|
||||
while let Some(tok) = toks.peek().cloned() {
|
||||
match tok.kind {
|
||||
't' | 'T' | '\\' => {
|
||||
let ident = peek_ident_no_interpolation(toks, false)?;
|
||||
let ident = peek_ident_no_interpolation(toks, false, tok.pos)?;
|
||||
match ident.node.to_ascii_lowercase().as_str() {
|
||||
"through" => {
|
||||
through = 1;
|
||||
|
@ -49,12 +49,7 @@ impl If {
|
||||
Some(t) => t.pos,
|
||||
None => return Err(("Expected expression.", span_before).into()),
|
||||
};
|
||||
let init_cond = Value::from_vec(
|
||||
init_cond_toks,
|
||||
scope,
|
||||
super_selector,
|
||||
span_before,
|
||||
)?;
|
||||
let init_cond = Value::from_vec(init_cond_toks, scope, super_selector, span_before)?;
|
||||
devour_whitespace_or_comment(toks)?;
|
||||
let mut init_toks = read_until_closing_curly_brace(toks)?;
|
||||
if let Some(tok) = toks.next() {
|
||||
@ -69,10 +64,10 @@ impl If {
|
||||
let mut else_ = Vec::new();
|
||||
|
||||
loop {
|
||||
match toks.peek() {
|
||||
Some(Token { kind: '@', .. }) => {
|
||||
match toks.peek().cloned() {
|
||||
Some(Token { kind: '@', pos }) => {
|
||||
toks.peek_forward(1);
|
||||
let mut ident = peek_ident_no_interpolation(toks, false)?;
|
||||
let mut ident = peek_ident_no_interpolation(toks, false, pos)?;
|
||||
ident.node.make_ascii_lowercase();
|
||||
if ident.as_str() != "else" {
|
||||
toks.reset_view();
|
||||
|
@ -287,7 +287,7 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
|
||||
continue;
|
||||
}
|
||||
|
||||
let name = peek_ident_no_interpolation(toks, false)?;
|
||||
let name = peek_ident_no_interpolation(toks, false, tok.pos)?;
|
||||
let whitespace = peek_whitespace(toks);
|
||||
|
||||
if toks.peek().ok_or(("expected \":\".", name.span))?.kind == ':' {
|
||||
|
@ -190,8 +190,8 @@ impl<'a> StyleSheetParser<'a> {
|
||||
continue;
|
||||
}
|
||||
'$' => {
|
||||
self.lexer.next();
|
||||
let name = peek_ident_no_interpolation(self.lexer, false)?;
|
||||
let span_before = self.lexer.next().unwrap().pos;
|
||||
let name = peek_ident_no_interpolation(self.lexer, false, span_before)?;
|
||||
let whitespace = peek_whitespace(self.lexer);
|
||||
|
||||
match self.lexer.peek() {
|
||||
@ -202,8 +202,12 @@ impl<'a> StyleSheetParser<'a> {
|
||||
.for_each(drop);
|
||||
devour_whitespace(self.lexer);
|
||||
|
||||
let VariableDecl { val, default, .. } =
|
||||
eat_variable_value(self.lexer, &Scope::new(), &Selector::new(), pos)?;
|
||||
let VariableDecl { val, default, .. } = eat_variable_value(
|
||||
self.lexer,
|
||||
&Scope::new(),
|
||||
&Selector::new(),
|
||||
pos,
|
||||
)?;
|
||||
|
||||
if !(default && global_var_exists(&name.node)) {
|
||||
insert_global_var(&name.node, val)?;
|
||||
|
@ -160,9 +160,12 @@ pub(crate) fn peek_escape<I: Iterator<Item = Token>>(
|
||||
pub(crate) fn peek_ident_no_interpolation<I: Iterator<Item = Token>>(
|
||||
toks: &mut PeekMoreIterator<I>,
|
||||
unit: bool,
|
||||
span_before: Span,
|
||||
) -> SassResult<Spanned<String>> {
|
||||
// todo: panics on "$"
|
||||
let mut span = toks.peek().unwrap().pos();
|
||||
let mut span = toks
|
||||
.peek()
|
||||
.ok_or(("Expected identifier.", span_before))?
|
||||
.pos();
|
||||
let mut text = String::new();
|
||||
if toks.peek().unwrap().kind == '-' {
|
||||
toks.peek_forward(1);
|
||||
|
@ -102,7 +102,7 @@ pub(crate) fn eat_variable_value<I: Iterator<Item = Token>>(
|
||||
return Err(("Expected identifier.", pos).into());
|
||||
}
|
||||
// todo: it should not be possible to declare the same flag more than once
|
||||
let mut ident = peek_ident_no_interpolation(toks, false)?;
|
||||
let mut ident = peek_ident_no_interpolation(toks, false, pos)?;
|
||||
ident.node.make_ascii_lowercase();
|
||||
match ident.node.as_str() {
|
||||
"global" => {
|
||||
|
@ -224,3 +224,7 @@ error!(
|
||||
ident_colon_closing_brace,
|
||||
"r:}", "Error: Expected expression."
|
||||
);
|
||||
error!(
|
||||
dollar_sign_alone,
|
||||
"$", "Error: Expected identifier."
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user