Skip to content

Instantly share code, notes, and snippets.

@tkqubo
Last active March 31, 2024 10:37
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tkqubo/2842772 to your computer and use it in GitHub Desktop.
Save tkqubo/2842772 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/
@tkqubo
Copy link
Author

tkqubo commented May 31, 2012

@MrOutput
Copy link

MrOutput commented Oct 9, 2017

very cool, thanks for making this

@SpineyPete
Copy link

Just what I needed! Thanks :)

@kabua
Copy link

kabua commented Aug 3, 2022

👍

@kevinarpe
Copy link

Should line 22 read? alphabets := /[a-zA-Z]/

@tkqubo
Copy link
Author

tkqubo commented Jun 16, 2023

Great, thanks! I fixed it @kevinarpe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment