Skip to content

Instantly share code, notes, and snippets.

@LinArcX
Forked from tkqubo/html5TagSyntax.bnf
Created December 13, 2020 16:29
Show Gist options
  • Save LinArcX/b315aa5a88abccefb2ae3a9c6c2a79b9 to your computer and use it in GitHub Desktop.
Save LinArcX/b315aa5a88abccefb2ae3a9c6c2a79b9 to your computer and use it in GitHub Desktop.
EBNF notation for HTML5 tag syntax
tag-open := '<' tag-name ws* attr-list? ws* '>'
tag-empty := '<' tag-name ws* attr-list? ws* '/>'
tag-close := '</' tag-name ws* '>'
attr-list := (ws+ attr)*
attr := attr-empty | attr-unquoted | attr-single-quoted | attr-double-quoted
attr-empty := attr-name
attr-unquoted := attr-name ws* = ws* attr-unquoted-value
attr-single-quoted := attr-name ws* = ws* ' attr-single-quoted-value '
attr-double-quoted := attr-name ws* = ws* " attr-double-quoted-value "
tag-name := (alphabets | digits)+ # Can digits become first letter?
attr-name := /[^\s"'>/=\p{Control}]+/
# These three items should not contain 'ambiguous ampersand'...
attr-unquoted-value := /[^\s"'=<>`]+/
attr-single-quoted-value := /[^']*/
attr-double-quoted-value := /[^"]*/
alphabets := [a-zA-Z]
digits := /[0-9]/
ws := /\s/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment