use consume_char_if_exists
to simplify parsing
This commit is contained in:
parent
1f14bc92e3
commit
36a55e582c
@ -134,8 +134,7 @@ impl<'a> Parser<'a> {
|
|||||||
loop {
|
loop {
|
||||||
self.whitespace_or_comment();
|
self.whitespace_or_comment();
|
||||||
|
|
||||||
if matches!(self.toks.peek(), Some(Token { kind: ')', .. })) {
|
if self.consume_char_if_exists(')') {
|
||||||
self.toks.next();
|
|
||||||
return Ok(CallArgs(args, span));
|
return Ok(CallArgs(args, span));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,9 +119,8 @@ impl<'a> Parser<'a> {
|
|||||||
let content = if content_args.is_some()
|
let content = if content_args.is_some()
|
||||||
|| matches!(self.toks.peek(), Some(Token { kind: '{', .. }))
|
|| matches!(self.toks.peek(), Some(Token { kind: '{', .. }))
|
||||||
{
|
{
|
||||||
if matches!(self.toks.peek(), Some(Token { kind: '{', .. })) {
|
self.consume_char_if_exists('{');
|
||||||
self.toks.next();
|
|
||||||
}
|
|
||||||
let mut toks = read_until_closing_curly_brace(self.toks)?;
|
let mut toks = read_until_closing_curly_brace(self.toks)?;
|
||||||
if let Some(tok) = self.toks.peek() {
|
if let Some(tok) = self.toks.peek() {
|
||||||
toks.push(*tok);
|
toks.push(*tok);
|
||||||
|
@ -709,8 +709,7 @@ impl<'a> Parser<'a> {
|
|||||||
fn parse_at_root(&mut self) -> SassResult<Vec<Stmt>> {
|
fn parse_at_root(&mut self) -> SassResult<Vec<Stmt>> {
|
||||||
self.whitespace();
|
self.whitespace();
|
||||||
let mut at_root_has_selector = false;
|
let mut at_root_has_selector = false;
|
||||||
let at_rule_selector = if matches!(self.toks.peek(), Some(Token { kind: '{', .. })) {
|
let at_rule_selector = if self.consume_char_if_exists('{') {
|
||||||
self.toks.next();
|
|
||||||
self.super_selectors.last().clone()
|
self.super_selectors.last().clone()
|
||||||
} else {
|
} else {
|
||||||
at_root_has_selector = true;
|
at_root_has_selector = true;
|
||||||
|
@ -199,9 +199,8 @@ impl<'a> Parser<'a> {
|
|||||||
module: &str,
|
module: &str,
|
||||||
mut module_span: Span,
|
mut module_span: Span,
|
||||||
) -> SassResult<Spanned<IntermediateValue>> {
|
) -> SassResult<Spanned<IntermediateValue>> {
|
||||||
Ok(IntermediateValue::Value(
|
Ok(
|
||||||
if matches!(self.toks.peek(), Some(Token { kind: '$', .. })) {
|
IntermediateValue::Value(if self.consume_char_if_exists('$') {
|
||||||
self.toks.next();
|
|
||||||
let var = self
|
let var = self
|
||||||
.parse_identifier_no_interpolation(false)?
|
.parse_identifier_no_interpolation(false)?
|
||||||
.map_node(|i| i.into());
|
.map_node(|i| i.into());
|
||||||
@ -228,9 +227,9 @@ impl<'a> Parser<'a> {
|
|||||||
let call_args = self.parse_call_args()?;
|
let call_args = self.parse_call_args()?;
|
||||||
|
|
||||||
HigherIntermediateValue::Function(function, call_args)
|
HigherIntermediateValue::Function(function, call_args)
|
||||||
},
|
})
|
||||||
|
.span(module_span),
|
||||||
)
|
)
|
||||||
.span(module_span))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_ident_value(
|
fn parse_ident_value(
|
||||||
@ -243,9 +242,8 @@ impl<'a> Parser<'a> {
|
|||||||
|
|
||||||
let lower = s.to_ascii_lowercase();
|
let lower = s.to_ascii_lowercase();
|
||||||
|
|
||||||
if lower == "progid" && matches!(self.toks.peek(), Some(Token { kind: ':', .. })) {
|
if lower == "progid" && self.consume_char_if_exists(':') {
|
||||||
s = lower;
|
s = lower;
|
||||||
self.toks.next();
|
|
||||||
s.push(':');
|
s.push(':');
|
||||||
s.push_str(&self.parse_progid()?);
|
s.push_str(&self.parse_progid()?);
|
||||||
return Ok(Spanned {
|
return Ok(Spanned {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user