Merge pull request #38 from ryangjchandler/fix/close-tag-followed-by-content

This commit is contained in:
Ryan Chandler 2022-09-12 12:39:04 +01:00 committed by GitHub
commit 2e450cea70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -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(

View File

@ -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();