Skip to content

Instantly share code, notes, and snippets.

@irskep
Last active February 3, 2016 18:58
Show Gist options
  • Save irskep/a155703d3caf2ef3bb43 to your computer and use it in GitHub Desktop.
Save irskep/a155703d3caf2ef3bb43 to your computer and use it in GitHub Desktop.
// BB_WORD: a valid tag name; essentially a string literal terminated by whitespace or a reserved character
// TEXT: non-BBCode text (i.e. string literal)
// BB_VAL: A string literal inside a BBCode tag
// e.g. [img src="foo"] matches [BB_WORD BB_WORD=BB_VAL]
Stmts -> Stmt Stmts
| ε
Stmt -> TEXT
| Tag
Tag -> OpenTag Stmts CloseTag
| SelfClosingTag
OpenTag -> [ TagContents ]
CloseTag -> [ / BB_WORD ]
SelfClosingTag -> [ TagContents / ]
TagContents -> BB_WORD TagArgs
| BB_WORD
TagArgs -> TagArg TagArgs
| ε
TagArg -> BB_WORD = ArgValue
ArgValue -> BB_WORD
| NUMBER
| STRING
@timtadh
Copy link

timtadh commented Feb 3, 2016

// BB_WORD: a valid tag name
// TEXT: non-BBCode text (i.e. string literal)
// BB_VAL: A string literal inside a BBCode tag
// e.g. [img src="foo"] matches [BB_WORD BB_WORD=BB_VAL]
// Note: this grammar is not suitable for top down parsing
//       it needs to be right recursive and be left factored

Stmts -> Stmts Stmt
       | Stmt

Stmt -> TEXT
      | Tag

Tag -> OpenTag Stmts CloseTag
     | SelfClosingTag

OpenTag -> [ TagContents ]

CloseTag -> [ / BB_WORD ]

SelfClosingTag -> [ TagContents / ]

TagContents -> BB_WORD TagArgs
             | BB_WORD

TagArgs -> TagArgs TagArg
         | TagArg

TagArg -> BB_WORD = ArgValue

ArgValue -> BB_WORD
          | NUMBER
          | STRING

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