|
Limn
0.1
|
Customizable parser. More...
#include <limn.h>
Inherits lm::impl::parser_base< Base >.
Public Member Functions | |
| constexpr | action_ (Func &&func) noexcept |
| Construct an action_ 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... | |
Customizable parser.
An object of this type uses a callback to determine a match. This enables recursive grammars and interaction with other parsers. For an example, look at tests.cpp:validParentheses (which can also be found in README.md).
|
inlineexplicitnoexcept |
Construct an action_ parser.
This function receives a string_view by reference and returns a bool. The string_view argument starts at the current parse position and ends at the end of the input string. To indicate a match, return true and adjust the string_view's start position to the end of the matched section. If there is no match, the function must return false and not modify the input.
For example, suppose you have a callback that parses "ABC". You could have used lm::lit_("ABC"), but you like making things complicated I guess.
Your function could be called with "ABCDEFG". In that case, you would set the input to "DEFG" and return true.
If your function was invoked with "QWERTY", then you would return false without modifying the input.
| [in] | func | The function to call. |
|
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