View Source Grammar.Rule (Grammar v0.3.0)

A Rule entity represents a single rule in the grammar.

It has a name, a list of mutually exclusive clauses and epsilon flag indicating if the rule is mandatory or not.

Summary

Functions

Append a clause to the rule.

Return true is the rule is not mandatory.

Create a new empty rule with a given name and epsilon flag.

Types

@type name() :: atom()
@type t() :: %Grammar.Rule{
  clauses: [Grammar.Clause.t()],
  epsilon?: boolean(),
  name: name()
}

Functions

Link to this function

add_clause(rule, clause)

View Source
@spec add_clause(t(), Grammar.Clause.t()) :: t()

Append a clause to the rule.

Clauses must be mutually exclusive, and must added in the order of their priority if ambiguity during token extraction is possible (which must be avoided as much as possible).

@spec epsilon?(t()) :: boolean()

Return true is the rule is not mandatory.

If a Rule is optional, and so epsilon is true, it is reduced to nil during the parsing if not entered.

Link to this function

new(name, epsilon? \\ false)

View Source
@spec new(atom(), boolean()) :: t()

Create a new empty rule with a given name and epsilon flag.