View Source Grammar.RulesChecker (Grammar v0.4.0)

This module exports functions to check the correctness of the grammar rules.

Summary

Functions

Check if all rules exist in the grammar, i.e. a rule referred to in a substitution list is actually defined.

Check if the rules are non-left-recursive.

Check if the rules are not ambiguous, i.e. a given token drives only to one reduction.

Express an error returned by a checker function in a human-readable form.

Types

@type ambiguity() :: {atom(), term()}
@type miss() :: {atom(), atom()}
@type path() :: [atom()]

Functions

Link to this function

check_all_rules_exist(grammar)

View Source
@spec check_all_rules_exist(Grammar.t()) :: :ok | {:error, :missing_rules, [miss()]}

Check if all rules exist in the grammar, i.e. a rule referred to in a substitution list is actually defined.

Link to this function

check_rules_are_non_left_recursive(grammar)

View Source
@spec check_rules_are_non_left_recursive(Grammar.t()) ::
  :ok | {:error, :cycles_found, [path()]}

Check if the rules are non-left-recursive.

Link to this function

check_rules_are_not_ambiguous(grammar)

View Source
@spec check_rules_are_not_ambiguous(Grammar.t()) ::
  :ok | {:error, :ambiguities_found, [String.t()]}

Check if the rules are not ambiguous, i.e. a given token drives only to one reduction.

Link to this function

stringify_error(atom, misses)

View Source
@spec stringify_error(:missing_rules, [miss()]) :: String.t()
@spec stringify_error(:cycles_found, [path()]) :: String.t()
@spec stringify_error(:ambiguities_found, [ambiguity()]) :: String.t()

Express an error returned by a checker function in a human-readable form.