parser: skip open tags if found after an InlineHtml statement

This commit is contained in:
Ryan Chandler 2022-12-09 23:08:24 +00:00
parent 81af31bf62
commit fa19d0eb8d
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA
4 changed files with 24 additions and 0 deletions

View File

@ -114,6 +114,7 @@ pub fn switch_statement(state: &mut State) -> ParseResult<Statement> {
let condition = expressions::lowest_precedence(state)?; let condition = expressions::lowest_precedence(state)?;
utils::skip_any_of(state, &[TokenKind::Colon, TokenKind::SemiColon])?; utils::skip_any_of(state, &[TokenKind::Colon, TokenKind::SemiColon])?;
utils::skip_close_tag(state)?;
let mut body = Block::new(); let mut body = Block::new();

View File

@ -149,3 +149,19 @@ pub fn at_least_one_comma_separated<T>(
Ok(result) Ok(result)
} }
pub fn skip_close_tag(state: &mut State) -> ParseResult<()> {
if state.current.kind == TokenKind::CloseTag {
state.next();
}
Ok(())
}
pub fn skip_open_tag(state: &mut State) -> ParseResult<()> {
if let TokenKind::OpenTag(_) = state.current.kind {
state.next();
}
Ok(())
}

View File

@ -286,6 +286,7 @@ fn statement(state: &mut State) -> ParseResult<Statement> {
TokenKind::InlineHtml(html) => { TokenKind::InlineHtml(html) => {
let s = Statement::InlineHtml(html.clone()); let s = Statement::InlineHtml(html.clone());
state.next(); state.next();
utils::skip_open_tag(state)?;
s s
} }
TokenKind::SingleLineComment(comment) => { TokenKind::SingleLineComment(comment) => {

View File

@ -141,6 +141,12 @@ impl State {
self.update_scope(); self.update_scope();
} }
pub fn skip_close_tag(&mut self) {
if matches!(self.current.kind, TokenKind::CloseTag) {
self.next();
}
}
pub fn skip_comments(&mut self) { pub fn skip_comments(&mut self) {
while matches!( while matches!(
self.current.kind, self.current.kind,