fix: allow omitting semi colon before closing tag

Closes #156.
This commit is contained in:
Ryan Chandler 2022-12-05 09:38:23 +00:00
parent 23dda4d603
commit 31d9cef5aa
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA
4 changed files with 75 additions and 1 deletions

View File

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

15
tests/0236/ast.txt Normal file
View File

@ -0,0 +1,15 @@
[
InlineHtml(
"<h1>\n ",
),
Echo {
values: [
LiteralString {
value: "Hello, world!",
},
],
},
InlineHtml(
"\n</h1>",
),
]

3
tests/0236/code.php Normal file
View File

@ -0,0 +1,3 @@
<h1>
<?php echo "Hello, world!" ?>
</h1>

52
tests/0236/tokens.txt Normal file
View File

@ -0,0 +1,52 @@
[
Token {
kind: InlineHtml(
"<h1>\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</h1>",
),
span: (
2,
34,
),
},
]