|
Limn
0.1
|
String literal parser. More...
#include <limn.h>
Inherits lm::impl::parser_base< Base >.
Public Member Functions | |
| constexpr | lit_ (std::string_view str) noexcept |
| Construct a lit_ 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... | |
String literal parser.
An object of this type matches a character sequence (AKA a string literal). For example, lm::lit_("tautological") would parse the string "tautological".
|
inlinenoexcept |
Construct a lit_ parser.
| [in] | str | The string literal to parse. |
|
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