Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions trunk_lexer/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ impl Lexer {
buffer.push('?');
}
} else {
self.next();

self.col += 1;

buffer.push(char);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand Down
14 changes: 13 additions & 1 deletion trunk_parser/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down