biome/xtask/codegen/html.ungram
Emanuele Stoppa 96f3e778a3
Some checks are pending
CI on main / Format Rust Files (push) Waiting to run
CI on main / Lint Rust Files (push) Waiting to run
CI on main / Check Dependencies (push) Waiting to run
CI on main / Test (push) Waiting to run
CI on main / Test262 Coverage (push) Waiting to run
Release / Release (push) Waiting to run
Release / Package win32-arm64 (push) Blocked by required conditions
Release / Package win32-x64 (push) Blocked by required conditions
Release / Package linux-arm64 (push) Blocked by required conditions
Release / Package linux-x64 (push) Blocked by required conditions
Release / version (push) Blocked by required conditions
Release / Package darwin-arm64 (push) Blocked by required conditions
Release / Package darwin-x64 (push) Blocked by required conditions
Release / Package linux-arm64-musl (push) Blocked by required conditions
Release / Package linux-x64-musl (push) Blocked by required conditions
Release / Build WASM (push) Blocked by required conditions
Release / Package JavaScript APIs (push) Blocked by required conditions
Release / Publish CLI (push) Blocked by required conditions
Release / Publish JS API (push) Blocked by required conditions
Repository dispatch on main / Build @biomejs/wasm-web (push) Waiting to run
Repository dispatch on main / Repository dispatch (push) Blocked by required conditions
feat(html/svelte): parsing of new blocks (#8023)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-11-06 12:44:01 +00:00

271 lines
5.4 KiB
Text

// HTML Un-Grammar.
//
// This grammar specifies the structure of Rust's concrete syntax tree.
// It does not specify parsing rules (ambiguities, precedence, etc are out of scope).
// Tokens are processed -- contextual keywords are recognised, compound operators glued.
//
// Legend:
//
// // -- comment
// Name = -- non-terminal definition
// 'ident' -- token (terminal)
// A B -- sequence
// A | B -- alternation
// A* -- zero or more repetition
// (A (',' A)* ','?) -- repetition of node A separated by ',' and allowing a trailing comma
// (A (',' A)*) -- repetition of node A separated by ',' without a trailing comma
// A? -- zero or one repetition
// (A) -- same as A
// label:A -- suggested name for field of AST node
// NOTES
//
// - SyntaxNode, SyntaxToken and SyntaxElement will be stripped from the codegen
// - Bogus nodes are special nodes used to keep track of broken code; they are
// not part of the grammar but they will appear inside the green tree
///////////////
// BOGUS NODES
///////////////
// SyntaxElement is a generic data structure that is meant to track nodes and tokens
// in cases where we care about both types
//
// As Bogus* node will need to yield both tokens and nodes without discrimination,
// and their children will need to yield nodes and tokens as well.
// For this reason, SyntaxElement = SyntaxElement
SyntaxElement = SyntaxElement
HtmlBogus = SyntaxElement*
HtmlBogusElement = SyntaxElement*
HtmlBogusAttribute = SyntaxElement*
AstroBogusFrontmatter = SyntaxElement*
HtmlBogusTextExpression = SyntaxElement*
SvelteBogusBlock = SyntaxElement*
HtmlRoot =
bom: 'UNICODE_BOM'?
frontmatter: AnyAstroFrontmatterElement?
directive: HtmlDirective?
html: HtmlElementList
eof: 'EOF'
// <!DOCTYPE html>
// ^^^^^^^^^^^^^^^
HtmlDirective =
'<'
'!'
doctype: 'doctype'
html: 'html'?
quirk: 'html_literal'?
public_id: 'html_string_literal'?
system_id: 'html_string_literal'?
'>'
// ==================================
// Elements (AKA tags)
// ==================================
HtmlElementList = AnyHtmlElement*
AnyHtmlElement =
HtmlSelfClosingElement
| HtmlElement
| AnyHtmlContent
| HtmlCdataSection
| HtmlBogusElement
AnyHtmlContent =
HtmlContent
| HtmlEmbeddedContent
| AnyHtmlTextExpression
AnyHtmlTextExpression =
HtmlDoubleTextExpression
| HtmlSingleTextExpression
| AnySvelteBlock
| HtmlBogusTextExpression
// {{ expression }}
// ^^^^^^^^^^^^^^^^
HtmlDoubleTextExpression =
'{{'
expression: HtmlTextExpression
'}}'
// {expression}
// ^^^^^^^^^^^^
HtmlSingleTextExpression =
'{'
expression: HtmlTextExpression
'}'
HtmlTextExpression = 'html_literal'
// <a />
HtmlSelfClosingElement =
'<'
name: HtmlTagName
attributes: HtmlAttributeList
'/'?
'>'
HtmlElement =
opening_element: HtmlOpeningElement
children: HtmlElementList
closing_element: HtmlClosingElement
// <a href="">
// ^^ ^
HtmlOpeningElement =
'<'
name: HtmlTagName
attributes: HtmlAttributeList
'>'
// </a>
HtmlClosingElement =
'<'
'/'
name: HtmlTagName
'>'
// <![CDATA[example]]>
// Reference: https://html.spec.whatwg.org/multipage/syntax.html#cdata-sections
HtmlCdataSection =
'<![CDATA['
content: 'html_literal'
']]>'
AnyAstroFrontmatterElement =
AstroFrontmatterElement
| AstroBogusFrontmatter
AstroFrontmatterElement =
l_fence: '---'
content: AstroEmbeddedContent
r_fence: '---'
AstroEmbeddedContent =
content: 'html_literal'?
// ==================================
// Attributes
// ==================================
HtmlAttributeList = AnyHtmlAttribute*
AnyHtmlAttribute =
HtmlAttribute
| HtmlDoubleTextExpression
| HtmlSingleTextExpression
| SvelteAttachAttribute
| HtmlBogusAttribute
// <a href="">
// ^^^^^^^
HtmlAttribute =
name: HtmlAttributeName
initializer: HtmlAttributeInitializerClause?
// <a href="">
// ^^^
HtmlAttributeInitializerClause =
'='
value: AnyHtmlAttributeInitializer
AnyHtmlAttributeInitializer =
HtmlString
| HtmlSingleTextExpression
// ==================================
// Svelte
// ==================================
AnySvelteBlock =
SvelteDebugBlock
| SvelteKeyBlock
| SvelteBogusBlock
| SvelteRenderBlock
| SvelteHtmlBlock
| SvelteConstBlock
// {@debug}
// ^^^^^^^^
SvelteDebugBlock =
'{@'
'debug'
bindings: SvelteBindingList
'}'
// {#key ...} ... {/key}
// ^^^^^^^^^^^^^^^^^^^^^
SvelteKeyBlock =
opening_block: SvelteKeyOpeningBlock
children: HtmlElementList
closing_block: SvelteKeyClosingBlock
// {#key ...} ... {/key}
// ^^^^^^^^^^
SvelteKeyOpeningBlock =
'{#'
'key'
expression: HtmlTextExpression
'}'
// {#key ...} ... {/key}
// ^^^^^^
SvelteKeyClosingBlock =
'{/'
'key'
'}'
SvelteBindingList = (SvelteName (',' SvelteName)*)
SvelteName = 'svelte_ident'
// {@render ...}
// ^^^^^^^^^^^^^
SvelteRenderBlock =
'{@'
'render'
expression: HtmlTextExpression
'}'
// {@attach ...}
// ^^^^^^^^^^^^^
SvelteAttachAttribute =
'{@'
'attach'
expression: HtmlTextExpression
'}'
// {@html ...}
// ^^^^^^^^^^^
SvelteHtmlBlock =
'{@'
'html'
expression: HtmlTextExpression
'}'
// {@const ...}
// ^^^^^^^^^^^
SvelteConstBlock =
'{@'
'const'
expression: HtmlTextExpression
'}'
HtmlString = value: 'html_string_literal'
HtmlTagName = value: 'html_literal'
HtmlAttributeName = value: 'html_literal'
HtmlContent = value: 'html_literal'
HtmlEmbeddedContent = value: 'html_literal'