Header lexy/grammar.hpp

Traits and definitions for the grammar.

Grammar traits

lexy/grammar.hpp
namespace lexy
{
    template <typename T>
    constexpr bool is_production;  (1)

    template <typename T>
    constexpr bool is_rule;        (2)
    template <typename T>
    constexpr bool is_branch_rule; (3)
    template <typename T>
    constexpr bool is_token_rule;  (4)
}
  1. Whether or not T is a production, i.e. it has a ::rule member.

  2. Whether or not T is a rule.

  3. Whether or not T is a branch rule.

  4. Whether or not T is a token rule.

Function lexy::production_name

lexy/grammar.hpp
namespace lexy
{
    template <production Production>
    consteval const char* production_name();
}

Returns the name of the production.

By default, it is the type name of Production after removing the top-level namespace. This can be overridden by Production::name() or Production::name.

Trait lexy::production_rule

lexy/grammar.hpp
namespace lexy
{
    template <production Production>
    using production_rule = std::decay_t<decltype(Production::rule)>;
}

Returns the type of the rule of production, i.e. the type of Production::rule.

Trait lexy::production_whitespace

lexy/grammar.hpp
namespace lexy
{
    template <production Production, production RootProduction>
    using production_whitespace = see-below;
}

Returns the type of the whitespace rule of Production in the context of RootProduction.

It is determined as follows:

  1. If Production inherits from lexy::token_production, the production_whitespace is void.

  2. If Production::whitespace is valid, returns the decayed type of that.

  3. If RootProduction::whitespace is valid, returns the decayed type of that.

  4. Otherwise, returns void.

This is used by lexy::dsl::whitespace during automatic whitespace skipping.

Trait lexy::production_value

lexy/grammar.hpp
namespace lexy
{
    template <production Production>
    struct production_value
    {
        static constexpr auto get = Production::value;
        using type                = std::decay_t<decltype(get)>;
    };
}

Returns the type and object of the callback/sink of the production.

Class lexy::token_production

lexy/grammar.hpp
namespace lexy
{
    struct token_production
    {};

    template <production Production>
    constexpr bool is_token_production = std::is_base_of_v<token_production, Production>;
}

Base class to indicate that a production is conceptually a token.

This inhibits whitespace skipping (directly) inside the production. In the parse tree, it will merge adjacent child tokens of the same lexy::token_kind.

Class lexy::transparent_production

lexy/grammar.hpp
namespace lexy
{
    struct transparent_production
    {};

    template <production Production>
    constexpr bool is_transparent_production = std::is_base_of_v<transparent_production, Production>;
}

Base class to indicate that this production should not show up in the parse tree.

In the parse tree, there will be no separate node for Production. Instead, all child nodes of Production are added to its parent node.

See also