Header lexy/dsl/follow.hpp

The followed_by and not_followed_by literal rules.

Literal rule lexy::dsl::followed_by

lexy/dsl/follow.hpp
namespace lexy::dsl
{
    constexpr literal-rule auto followed_by(literal-rule lit,
                                          char-class-rule auto cc)
    {
        return not_followed_by(lit, -cc);
    }

    constexpr literal-rule auto followed_by(literal-rule lit,
                                          literal-char-class-rule auto cc)
    {
        return not_followed_by(lit, -cc);
    }
}

followed_by is a literal rule that ensures another literal rule is followed by a char class rule.

It is just syntax sugar for the primary form, lexy::dsl::not_followed_by .

Literal rule lexy::dsl::not_followed_by

lexy/dsl/follow.hpp
namespace lexy
{
    struct follow_restriction
    {};
}

namespace lexy::dsl
{
    constexpr literal-rule auto not_followed_by(literal-rule lit,
                                                char-class-rule auto cc);
    constexpr literal-rule auto not_followed_by(literal-rule lit,
                                                literal-char-class-rule auto cc);
}

not_followed_by is a literal rule that ensures another literal rule is not followed by a char class rule.

Requires

lit is not a lexy::dsl::keyword  rule.

Matching

Matches and consumes lit. Otherwise, tries to match cc without consuming it and fails if it does. If lit uses case folding (e.g. lexy::dsl::ascii::case_folding ), it also applies to cc.

Errors
  • All errors raised by lit when it fails.

  • lexy::follow_restriction: if cc matches; at the position where it matched. The rule then fails.

Parse tree

The single token node created by lit.

Example 1. Match = but not ==
struct production
{
    static constexpr auto rule
        // = but then not another =
        = dsl::not_followed_by(dsl::lit_c<'='>, dsl::lit_c<'='>);
};
Tip
Use lexy::dsl::keyword  for the common case of parsing a literal that is not a valid identifier.

See also