Skip to content

Commit

Permalink
refactor: re-order code
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane committed Oct 25, 2024
1 parent a65df95 commit 07848be
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions markup_fmt/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2116,30 +2116,6 @@ impl<'s> Parser<'s> {
}
}

fn parse_svelte_snippet_block(&mut self) -> PResult<SvelteSnippetBlock<'s>> {
if self
.chars
.next_if(|(_, c)| *c == '{')
.and_then(|_| self.chars.next_if(|(_, c)| *c == '#'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 's'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 'n'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 'i'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 'p'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 'p'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 'e'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 't'))
.and_then(|_| self.chars.next_if(|(_, c)| c.is_ascii_whitespace()))
.is_none()
{
return Err(self.emit_error(SyntaxErrorKind::ExpectSvelteIfBlock));
};

let expr = self.parse_svelte_or_astro_expr()?;
let children = self.parse_svelte_block_children()?;

Ok(SvelteSnippetBlock { expr, children })
}

/// This will consume `}`.
fn parse_svelte_or_astro_expr(&mut self) -> PResult<(&'s str, usize)> {
self.skip_ws();
Expand Down Expand Up @@ -2170,6 +2146,30 @@ impl<'s> Parser<'s> {
Ok((unsafe { self.source.get_unchecked(start..end) }, start))
}

fn parse_svelte_snippet_block(&mut self) -> PResult<SvelteSnippetBlock<'s>> {
if self
.chars
.next_if(|(_, c)| *c == '{')
.and_then(|_| self.chars.next_if(|(_, c)| *c == '#'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 's'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 'n'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 'i'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 'p'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 'p'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 'e'))
.and_then(|_| self.chars.next_if(|(_, c)| *c == 't'))
.and_then(|_| self.chars.next_if(|(_, c)| c.is_ascii_whitespace()))
.is_none()
{
return Err(self.emit_error(SyntaxErrorKind::ExpectSvelteIfBlock));
};

let expr = self.parse_svelte_or_astro_expr()?;
let children = self.parse_svelte_block_children()?;

Ok(SvelteSnippetBlock { expr, children })
}

fn parse_tag_name(&mut self) -> PResult<&'s str> {
let start = match self.chars.peek() {
Some((i, c)) if is_tag_name_char(*c) => {
Expand Down

0 comments on commit 07848be

Please sign in to comment.