Limn  0.1
Public Member Functions | List of all members
lm::char_ Class Referencefinal

Single character parser based on a char. More...

#include <limn.h>

Inherits lm::impl::parser_base< Base >.

Public Member Functions

constexpr char_ (const char ch) noexcept
 Construct a char_ parser. More...
 
constexpr auto operator! () const &noexcept
 Opposite parser. More...
 
constexpr auto operator* () const noexcept
 The Kleene star or "any number of times" parser combinator. More...
 
constexpr auto operator+ () const noexcept
 The plus parser or "one or more" parser combinator. More...
 
constexpr auto operator[] (std::string_view &output) const noexcept
 The match operator. More...
 
constexpr auto operator[] (std::function< void(const std::string_view &)> callback) const noexcept
 The match callback operator. More...
 

Detailed Description

Single character parser based on a char.

An object of this type parses a single character. For example, `lm::char_('a')` will parse the string "a".

Constructor & Destructor Documentation

◆ char_()

constexpr lm::char_::char_ ( const char  ch)
inlineexplicitnoexcept

Construct a char_ parser.

Parameters
[in]chThe character to accept.

Member Function Documentation

◆ operator!()

constexpr auto lm::char_::operator! ( ) const &
inlinenoexcept

Opposite parser.

Construct a parser that accepts all characters besides the one that the base accepts. For example, `! lm::char_('a')` accepts "b", "c", etc but does not accept "a"

◆ operator*()

template<typename Base >
constexpr auto lm::impl::parser_base< Base >::operator* ( ) const
inlinenoexceptinherited

The Kleene star or "any number of times" parser combinator.

This function returns a parser that matches its input any number of times (including 0 times). For example, `* lm::char_('a')matches "", "a", "aa", etc. This is a greedy match;* lm::char_('a') >> lm::lit_("aa")` will NEVER parse an input string because the Kleene star will eat up all the 'a's.

◆ operator+()

template<typename Base >
constexpr auto lm::impl::parser_base< Base >::operator+ ( ) const
inlinenoexceptinherited

The plus parser or "one or more" parser combinator.

This function returns a parser that matches its input one or more times (not including 0 times). For example, `+ lm::char_('a')matches "a", "aa", etc. This is a greedy match;+ lm::char_('a') >> lm::lit_("aa")` will NEVER parse an input string because the plus parser will eat up all the 'a's.

◆ operator[]() [1/2]

template<typename Base >
constexpr auto lm::impl::parser_base< Base >::operator[] ( std::string_view &  ouput) const
inlinenoexceptinherited

The match operator.

This side-effect-only function copies the matched part of input to its argument output. If there is no match, then output is unchanged. For example, `(* lm::char_('a'))[output]will match any number ofacharacters in sequence, and it will copy that sequence to thestd::string_viewoutput`.

This is useful for getting the matched string out of the parser. It's also sometimes useful for printf-debugging.

See tests.cpp or README.md for an example.

Parameters
[out]outputThe argument to receive the match portion.

◆ operator[]() [2/2]

template<typename Base >
constexpr auto lm::impl::parser_base< Base >::operator[] ( std::function< void(const std::string_view &)>  callback) const
inlinenoexceptinherited

The match callback operator.

The std::function will be called when an item get matched. The std::function should have the protytype std::function<void(const std::string_view&)> where the argument is the matched string_view. If there is no match, then this function will not be called. For example, `(* lm::char_('a'))[functor]will match any number ofa` characters in sequence, and it will call the functor.

This is useful for add the user defined action in this std::function For example, adding the AST of the matched item to the parsing tree

See tests.cpp or README.md for an example.

Parameters
[in]callbackThe std::function callback function which will be called when matched portion, the functor's parameter is the matched string_view.

The documentation for this class was generated from the following file: