mirror of
https://github.com/danog/parser.git
synced 2024-11-27 04:14:55 +01:00
Merge pull request #38 from ryangjchandler/fix/close-tag-followed-by-content
This commit is contained in:
commit
2e450cea70
@ -134,6 +134,8 @@ impl Lexer {
|
||||
buffer.push('?');
|
||||
}
|
||||
} else {
|
||||
self.next();
|
||||
|
||||
self.col += 1;
|
||||
|
||||
buffer.push(char);
|
||||
@ -203,6 +205,7 @@ impl Lexer {
|
||||
// This is a close tag, we can enter "Initial" mode again.
|
||||
if let Some('>') = self.peek {
|
||||
self.next();
|
||||
self.next();
|
||||
|
||||
self.col += 2;
|
||||
|
||||
@ -911,6 +914,18 @@ mod tests {
|
||||
assert_tokens("<?php ?>", &[open!(), TokenKind::CloseTag]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn close_tag_followed_by_content() {
|
||||
assert_tokens(
|
||||
"<?php ?> <html>",
|
||||
&[
|
||||
open!(),
|
||||
TokenKind::CloseTag,
|
||||
TokenKind::InlineHtml(" <html>".into()),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inline_html() {
|
||||
assert_tokens(
|
||||
|
@ -5,6 +5,7 @@ use crate::{
|
||||
},
|
||||
Block, Case, Catch, Expression, Identifier, MatchArm, Program, Statement, Type,
|
||||
};
|
||||
use core::panic;
|
||||
use std::{fmt::Display, vec::IntoIter};
|
||||
use trunk_lexer::{Span, Token, TokenKind};
|
||||
|
||||
@ -89,7 +90,10 @@ impl Parser {
|
||||
let mut ast = Program::new();
|
||||
|
||||
while self.current.kind != TokenKind::Eof {
|
||||
if let TokenKind::OpenTag(_) = self.current.kind {
|
||||
if matches!(
|
||||
self.current.kind,
|
||||
TokenKind::OpenTag(_) | TokenKind::CloseTag
|
||||
) {
|
||||
self.next();
|
||||
continue;
|
||||
}
|
||||
@ -3088,6 +3092,14 @@ mod tests {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn close_tag_followed_by_content() {
|
||||
assert_ast(
|
||||
"<?php ?> <html>",
|
||||
&[Statement::InlineHtml(" <html>".into())],
|
||||
);
|
||||
}
|
||||
|
||||
fn assert_ast(source: &str, expected: &[Statement]) {
|
||||
let mut lexer = Lexer::new(None);
|
||||
let tokens = lexer.tokenize(source).unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user