Skip to content

Instantly share code, notes, and snippets.

@darknoon
Created October 15, 2023 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darknoon/38acc36ab3844043e1b241d77b054962 to your computer and use it in GitHub Desktop.
Save darknoon/38acc36ab3844043e1b241d77b054962 to your computer and use it in GitHub Desktop.
Minimal gbnf for jsx-ish content
## Trying to debug why this is slow
# root rule
root ::= jsxElement
# Main JSX Element
jsxElement ::=
"<" jsxElementName jsxAttributesOpt ">" jsxChildrenOpt "</" jsxElementName ">"
# JSX Self-Closing Element
jsxSelfClosingElement ::=
"<" jsxElementName jsxAttributesOpt "/>"
# JSX Element Name (simplified)
jsxElementName ::= "div" | "p" | "span" | "a" | "button" | "input" | "label" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6"
# JSX Attributes
jsxAttributesOpt ::= (" " jsxAttribute)*
jsxAttribute ::= jsxAttributeName "=" jsxAttributeValue
jsxAttributeName ::= "className"
jsxAttributeValue ::=
"\"" [^\"]* "\"" # String Literal
# JSX Children
jsxChildrenOpt ::= jsxChild+
jsxChild ::=
jsxText |
jsxElement |
jsxSelfClosingElement
# JSX Text (simplified)
jsxText ::= [^<>{]+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment