Defined in header <cparse/Parser.hh>
enum class TermRequirementDeclaration
{
DISALLOWED,
OPTIONAL,
MANDATORY
};
A shared vocabulary for grammars that classify whether a construct's terminator is DISALLOWED, OPTIONAL or MANDATORY — for example, whether a statement list must end with a semicolon (MANDATORY), may end with one (OPTIONAL), or must not (DISALLOWED).
Declared inside Parser for name-scoping and to give consuming subclasses a common enum they can name via Parser::TermRequirementDeclaration::MANDATORY rather than defining their own three-valued enum from scratch.
Enumerators
| Enumerator | Meaning |
|---|---|
DISALLOWED | The construct must not end with the terminator. Consuming one is an error. |
OPTIONAL | The construct may or may not end with the terminator. Either form is accepted. |
MANDATORY | The construct must end with the terminator. Absence is an error. |
Notes
The base Parser class does not reference this enum in any of its methods. Its value is entirely in giving derived grammars a shared name for the concept. If your grammar has no terminator-optionality distinction, ignore the enum.
Example
A grammar that reads a list of statements and classifies the semicolon requirement per statement kind:
using TRD = fedem::parser::Parser::TermRequirementDeclaration;
TRD terminatorFor(StatementKind k)
{
switch (k)
{
case StatementKind::Expression: return TRD::MANDATORY;
case StatementKind::Block: return TRD::DISALLOWED;
case StatementKind::If: return TRD::OPTIONAL;
}
return TRD::MANDATORY;
}
See also
- Parser — the enclosing class.

