EBNF


The peg.ebnf vocabulary provides a DSL that allows writing PEG parsers that look like EBNF syntax. It provides three parsing words described below. These words all accept the same EBNF syntax. The difference is in how they are used.
Image
EBNF:

Image
EBNF[[

Image
EBNF[=[

Image
EBNF[==[

Image
EBNF[===[

Image
EBNF[====[


The EBNF syntax is composed of a series of rules of the form:
rule1 = ... rule2 = ...

The last defined rule is the main rule for the EBNF. It is the first one run and it is expected that the remaining rules are used by that rule. Rules may be left recursive. Each rule can contain the following:
Image EBNF Rule: Strings
Image EBNF Rule: Any
Image EBNF Rule: Sequence
Image EBNF Rule: Group
Image EBNF Rule: Choice
Image EBNF Rule: Ignore
Image EBNF Rule: Option
Image EBNF Rule: One or more
Image EBNF Rule: Zero or more
Image EBNF Rule: And
Image EBNF Rule: Not
Image EBNF Rule: Character Class
Image EBNF Foreign Rules
Image EBNF Action
Image EBNF Semantic Action
Image EBNF Variable

Grammars defined in EBNF need to handle each character, or sequence of characters in the input. This can be tedious for dealing with whitespace in grammars that have 'tokens' separated by whitespace. You can define your own tokenizer that for an EBNF grammar, and write the grammar in terms of those tokens, allowing you to ignore the whitespace issue. The tokenizer can be changed at various parts in the grammar as needed. The JavaScript grammar does this to define the optional semicolon rule for example.
Image EBNF Tokenizers