Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(parser/html): fix parsing html keyword in doctype #3776

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/biome_html_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ mod tests;

use crate::token_source::HtmlLexContext;
use biome_html_syntax::HtmlSyntaxKind::{
COMMENT, DOCTYPE_KW, EOF, ERROR_TOKEN, HTML_LITERAL, HTML_STRING_LITERAL, NEWLINE, TOMBSTONE,
UNICODE_BOM, WHITESPACE,
COMMENT, DOCTYPE_KW, EOF, ERROR_TOKEN, HTML_KW, HTML_LITERAL, HTML_STRING_LITERAL, NEWLINE,
TOMBSTONE, UNICODE_BOM, WHITESPACE,
};
use biome_html_syntax::{HtmlSyntaxKind, TextLen, TextSize, T};
use biome_parser::diagnostic::ParseDiagnostic;
Expand Down Expand Up @@ -149,6 +149,7 @@ impl<'src> HtmlLexer<'src> {

match &buffer[..len] {
b"doctype" | b"DOCTYPE" => DOCTYPE_KW,
b"html" | b"HTML" => HTML_KW,
_ => HTML_LITERAL,
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_html_parser/src/lexer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ fn doctype_with_quirk() {
BANG: 1,
DOCTYPE_KW: 7,
WHITESPACE: 1,
HTML_LITERAL: 4,
HTML_KW: 4,
R_ANGLE: 1,
}
}
Expand All @@ -170,7 +170,7 @@ fn doctype_with_quirk_and_system() {
BANG: 1,
DOCTYPE_KW: 7,
WHITESPACE: 1,
HTML_LITERAL: 4,
HTML_KW: 4,
WHITESPACE: 1,
HTML_STRING_LITERAL: 44,
R_ANGLE: 1,
Expand Down
4 changes: 4 additions & 0 deletions crates/biome_html_parser/src/syntax/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ fn parse_doc_type(p: &mut HtmlParser) -> ParsedSyntax {
p.eat(T![doctype]);
}

if p.at(T![html]) {
p.eat(T![html]);
}

p.eat(T![>]);

Present(m.complete(p, HTML_DIRECTIVE))
Expand Down
1 change: 1 addition & 0 deletions crates/biome_html_parser/tests/html_specs/ok/ok2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html>
50 changes: 50 additions & 0 deletions crates/biome_html_parser/tests/html_specs/ok/ok2.html.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
source: crates/biome_html_parser/tests/spec_test.rs
expression: snapshot
---
## Input

```css
<!doctype html>

```


## AST

```
HtmlRoot {
bom_token: missing (optional),
directive: HtmlDirective {
l_angle_token: [email protected] "<" [] [],
excl_token: [email protected] "!" [] [],
doctype_token: [email protected] "doctype" [] [Whitespace(" ")],
html_token: [email protected] "html" [] [],
quirk_token: missing (optional),
public_id_token: missing (optional),
system_id_token: missing (optional),
r_angle_token: [email protected] ">" [] [],
},
html: missing (optional),
eof_token: [email protected] "" [Newline("\n")] [],
}
```

## CST

```
0: [email protected]
0: (empty)
1: [email protected]
0: [email protected] "<" [] []
1: [email protected] "!" [] []
2: [email protected] "doctype" [] [Whitespace(" ")]
3: [email protected] "html" [] []
4: (empty)
5: (empty)
6: (empty)
7: [email protected] ">" [] []
2: (empty)
3: [email protected] "" [Newline("\n")] []

```
2 changes: 1 addition & 1 deletion xtask/codegen/html.ungram
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ HtmlAttribute =


// <a href="">
// ^^^^
// ^^^
HtmlAttributeInitializerClause =
'='
value: HtmlString
Expand Down
Loading