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.
EBNF:

EBNF[[

EBNF[=[

EBNF[==[

EBNF[===[

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:
EBNF Rule: Strings
EBNF Rule: Any
EBNF Rule: Sequence
EBNF Rule: Group
EBNF Rule: Choice
EBNF Rule: Ignore
EBNF Rule: Option
EBNF Rule: One or more
EBNF Rule: Zero or more
EBNF Rule: And
EBNF Rule: Not
EBNF Rule: Character Class
EBNF Foreign Rules
EBNF Action
EBNF Semantic Action
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.
EBNF Tokenizers