From 31d9cef5aac8e0d8af5d316db8476fcb54434884 Mon Sep 17 00:00:00 2001 From: Ryan Chandler Date: Mon, 5 Dec 2022 09:38:23 +0000 Subject: [PATCH] fix: allow omitting semi colon before closing tag Closes #156. --- src/parser/internal/punc.rs | 6 ++++- tests/0236/ast.txt | 15 +++++++++++ tests/0236/code.php | 3 +++ tests/0236/tokens.txt | 52 +++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 tests/0236/ast.txt create mode 100644 tests/0236/code.php create mode 100644 tests/0236/tokens.txt diff --git a/src/parser/internal/punc.rs b/src/parser/internal/punc.rs index ecf6b85..3614eec 100644 --- a/src/parser/internal/punc.rs +++ b/src/parser/internal/punc.rs @@ -7,7 +7,11 @@ use crate::expect_token; impl Parser { pub(in crate::parser) fn semi(&self, state: &mut State) -> ParseResult<()> { - expect_token!([TokenKind::SemiColon => Ok(())], state, "`;`") + if state.current.kind != TokenKind::CloseTag { + expect_token!([TokenKind::SemiColon => Ok(())], state, "`;`") + } else { + Ok(()) + } } pub(in crate::parser) fn lbrace(&self, state: &mut State) -> ParseResult<()> { diff --git a/tests/0236/ast.txt b/tests/0236/ast.txt new file mode 100644 index 0000000..b12f684 --- /dev/null +++ b/tests/0236/ast.txt @@ -0,0 +1,15 @@ +[ + InlineHtml( + "

\n ", + ), + Echo { + values: [ + LiteralString { + value: "Hello, world!", + }, + ], + }, + InlineHtml( + "\n

", + ), +] diff --git a/tests/0236/code.php b/tests/0236/code.php new file mode 100644 index 0000000..7b24ae5 --- /dev/null +++ b/tests/0236/code.php @@ -0,0 +1,3 @@ +

+ +

\ No newline at end of file diff --git a/tests/0236/tokens.txt b/tests/0236/tokens.txt new file mode 100644 index 0000000..c244a5f --- /dev/null +++ b/tests/0236/tokens.txt @@ -0,0 +1,52 @@ +[ + Token { + kind: InlineHtml( + "

\n ", + ), + span: ( + 1, + 1, + ), + }, + Token { + kind: OpenTag( + Full, + ), + span: ( + 2, + 5, + ), + }, + Token { + kind: Echo, + span: ( + 2, + 11, + ), + }, + Token { + kind: LiteralString( + "Hello, world!", + ), + span: ( + 2, + 16, + ), + }, + Token { + kind: CloseTag, + span: ( + 2, + 32, + ), + }, + Token { + kind: InlineHtml( + "\n

", + ), + span: ( + 2, + 34, + ), + }, +]