Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane committed Jun 4, 2024
1 parent 68ec8c7 commit 77d427f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions markup_fmt/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,25 +354,32 @@ impl<'s> Parser<'s> {
}

let start = match self.chars.peek() {
Some((i, c)) if is_unquoted_attr_value_char(*c) => { *i },
_ => return Err(self.emit_error(SyntaxErrorKind::ExpectAttrValue))
Some((i, c)) if is_unquoted_attr_value_char(*c) => *i,
_ => return Err(self.emit_error(SyntaxErrorKind::ExpectAttrValue)),
};

let mut end = start;
loop {
match self.chars.peek() {
Some((_, '{')) => {
self.parse_mustache_interpolation()?;
match self.chars.peek() {
Some((i, _)) => end = i - 1,
None => break
Some((i, '{'))
if matches!(self.language, Language::Jinja | Language::Vento) =>
{
end = *i;
let mut chars = self.chars.clone();
chars.next();
if chars.next_if(|(_, c)| *c == '{').is_some() {
// We use inclusive range when returning string,
// so we need to substract 1 here.
end += self.parse_mustache_interpolation()?.len() + "{{}}".len() - 1;
} else {
self.chars.next();
}
}
Some((i, c)) if is_unquoted_attr_value_char(*c) => {
end = *i;
self.chars.next();
},
_ => break
}
_ => break,
};
}

Expand Down

0 comments on commit 77d427f

Please sign in to comment.