|
Limn
0.1
|
Zero or one of the match parser, in another word it is an optional item. More...
#include <limn.h>
Inherits lm::impl::parser_base< Base >.
Public Member Functions | |
| 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... | |
Zero or one of the match parser, in another word it is an optional item.
An object of this type happens for one match of the item or empty For example, opt_( lm::lit_("hello") ) can parse the string "hello" or the empty string, so it is a simplied form of lm::lit_("hello") | empty_.
|
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.
|
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.
|
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.
| [out] | output | The argument to receive the match portion. |
|
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.
| [in] | callback | The std::function callback function which will be called when matched portion, the functor's parameter is the matched string_view. |
1.8.13