Prev Next

Grammar Rules

Rules are run to break up text into structure. A rule is made up of one or more definitions, each of which is made up of one or more terms.

Types of Rule

Rule

Description

Named rules

A name, followed by a definition list. For example:

     <rule> ::= <term1> <term2> | "-" <term1>;

Inline Rules

Inside a definition, a rule defined within parentheses. These act in exactly the same way as if they were a named rule being called by a term. For example:

     <rule> ::= (<inline>);

Optional Rules

Inside a definition, a rule defined within square brackets. This rule succeeds even if the contents fail. For example:

     <rule> ::= [<inline>];

Repeating Rules

Inside a definition, a term followed by a plus sign. This rule matches the inner rule once or more than once. For example:

     <rule> ::= <inline>+;

     rule ::= (<term1> <term2>)+;

Optional Repeating Rules

Inside a definition, a rule followed by a star. This rule matches the inner rule zero or more times, meaning it succeeds even if the inner rule never succeeds. For example:

     <rule> ::= <inline>*;

     rule ::= (<term1> <term2>)*;

Learn more