diff --git a/src/selector/attribute.rs b/src/selector/attribute.rs index 685d6d1..38736b9 100644 --- a/src/selector/attribute.rs +++ b/src/selector/attribute.rs @@ -123,7 +123,7 @@ impl Attribute { let value = match peek.kind { q @ '\'' | q @ '"' => { toks.next(); - match parse_quoted_string(toks, scope, q, super_selector)?.node { + match parse_quoted_string(toks, scope, q, super_selector, span_before)?.node { Value::String(s, ..) => s, _ => unreachable!(), } diff --git a/src/stylesheet.rs b/src/stylesheet.rs index 1c778b6..afd579b 100644 --- a/src/stylesheet.rs +++ b/src/stylesheet.rs @@ -256,6 +256,7 @@ impl<'a> StyleSheetParser<'a> { &Scope::new(), q, &Selector::new(), + next.pos, )? .node .unquote() diff --git a/src/utils/strings.rs b/src/utils/strings.rs index b49d8c6..de18938 100644 --- a/src/utils/strings.rs +++ b/src/utils/strings.rs @@ -281,13 +281,13 @@ pub(crate) fn parse_quoted_string>( scope: &Scope, q: char, super_selector: &Selector, + span_before: Span, ) -> SassResult> { let mut s = String::new(); - let mut span = if let Some(tok) = toks.peek() { - tok.pos() - } else { - todo!() - }; + let mut span = toks + .peek() + .ok_or((format!("Expected {}.", q), span_before))? + .pos(); while let Some(tok) = toks.next() { span = span.merge(tok.pos()); match tok.kind { diff --git a/src/value/parse.rs b/src/value/parse.rs index 9885dc9..966f824 100644 --- a/src/value/parse.rs +++ b/src/value/parse.rs @@ -823,7 +823,7 @@ impl Value { q @ '"' | q @ '\'' => { let span_start = toks.next().unwrap().pos(); let Spanned { node, span } = - match parse_quoted_string(toks, scope, q, super_selector) { + match parse_quoted_string(toks, scope, q, super_selector, span_start) { Ok(v) => v, Err(e) => return Some(Err(e)), }; diff --git a/tests/error.rs b/tests/error.rs index 00251d8..997864c 100644 --- a/tests/error.rs +++ b/tests/error.rs @@ -224,7 +224,9 @@ error!( ident_colon_closing_brace, "r:}", "Error: Expected expression." ); +error!(dollar_sign_alone, "$", "Error: Expected identifier."); error!( - dollar_sign_alone, - "$", "Error: Expected identifier." + nothing_after_dbl_quote, + "a {color: \"", "Error: Expected \"." ); +error!(nothing_after_sgl_quote, "a {color: '", "Error: Expected '.");