Limn  0.1
Classes | Functions | Variables
lm Namespace Reference

The namesapce for all Limn types, functions, and variables. More...

Classes

class  action_
 Customizable parser. More...
 
class  char_
 Single character parser based on a char. More...
 
class  char_if_
 Single character parser based on a function. More...
 
class  charset_
 Single character parser for any of several characters. More...
 
class  lit_
 String literal parser. More...
 
class  opt_
 Zero or one of the match parser, in another word it is an optional item. More...
 

Functions

template<typename Left , typename Right >
constexpr auto operator>> (Left &&left, Right &&right) noexcept
 The sequence parser combinator. More...
 
template<typename Left , typename Right >
constexpr auto operator| (Left &&left, Right &&right) noexcept
 The alternate parser combinator. More...
 
template<typename Parser >
constexpr bool parse (std::string_view input, Parser const &parser, Skipper &skipper=skws) noexcept
 The parse function. More...
 
template<typename Parser >
constexpr bool parse_ref (std::string_view &input, Parser const &parser, Skipper &skipper=skws) noexcept
 The parse function that takes input by reference. More...
 

Variables

static auto alnum_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::isalnum(ch); })
 Single character parser based on std::isalnum. More...
 
static auto alpha_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::isalpha(ch); })
 Single character parser based on std::isalpha. More...
 
static auto lower_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::islower(ch); })
 Single character parser based on std::islower. More...
 
static auto upper_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::isupper(ch); })
 Single character parser based on std::isupper. More...
 
static auto digit_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::isdigit(ch); })
 Single character parser based on std::isdigit. More...
 
static auto xdigit_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::isxdigit(ch); })
 Single character parser based on std::xdigit. More...
 
static auto cntrl_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::iscntrl(ch); })
 Single character parser based on std::cntrl. More...
 
static auto graph_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::isgraph(ch); })
 Single character parser based on std::graph. More...
 
static auto space_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::isspace(ch); })
 Single character parser based on std::space. More...
 
static auto blank_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::isblank(ch); })
 Single character parser based on std::blank. More...
 
static auto print_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::isprint(ch); })
 Single character parser based on std::print. More...
 
static auto punct_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::ispunct(ch); })
 Single character parser based on std::punct. More...
 
static constexpr auto end_ = impl::endtype_()
 End of input parser. More...
 
static constexpr auto empty_ = impl::emptytype_()
 Empty parser. More...
 

Detailed Description

The namesapce for all Limn types, functions, and variables.

Function Documentation

◆ operator>>()

template<typename Left , typename Right >
constexpr auto lm::operator>> ( Left &&  left,
Right &&  right 
)
inlinenoexcept

The sequence parser combinator.

This function combines two parsers in sequence. For example, lm::lit_("Hello") >> lm::lit_("World") parses "HelloWorld" using two literal parsers combined in sequence.

If this first parser in a sequence fails, then the second parser is never evaluated.

This operator is found using ADL.

Parameters
[in]leftThe first parser to evaluate.
[in]rightThe second parser to evaluate. Only evaluated if the first parser succeeded.

◆ operator|()

template<typename Left , typename Right >
constexpr auto lm::operator| ( Left &&  left,
Right &&  right 
)
inlinenoexcept

The alternate parser combinator.

This function combines two parsers as alternatives. For example, lm::lit_("Hello") | lm::lit_("World") parses "Hello" or "World" using two literal parsers.

If this first parser in a sequence fails, then the second parser is evaluated. If the first parser succeeds, then the second parser is never evaluated. This is analogous to "short circuiting" of ||.

This operator is found using ADL.

Parameters
[in]leftThe first parser to evaluate. If true, then the combined parse succeeds.
[in]rightThe second parser to evaluate. Only evaluated if the first parser failed.

◆ parse()

template<typename Parser >
constexpr bool lm::parse ( std::string_view  input,
Parser const &  parser,
Skipper &  skipper = skws 
)
noexcept

The parse function.

This is the top level function you should call to evaluate a parser with an input.

For example:

parse(
    "Hello World",
    lm::lit_(Hello) >> lm::space_ >> lm::lit_("World") >> lm::end_
);

...would return true

Parameters
[in]inputThe input string to parse
[in]parserThe parser to evaluate on input
Returns
true if the parser matched the input or false otherwise

◆ parse_ref()

template<typename Parser >
constexpr bool lm::parse_ref ( std::string_view &  input,
Parser const &  parser,
Skipper &  skipper = skws 
)
noexcept

The parse function that takes input by reference.

This function is useful for recursive grammars. For an example, see tests.cpp or README.md.

Prefer to use lm::parse().

Parameters
[in,out]inputThe input string to parse
[in]parserThe parser to evaluate on input
Returns
true if the parser matched the input or false otherwise

Variable Documentation

◆ alnum_

lm::alnum_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::isalnum(ch); })
inlinestatic

Single character parser based on std::isalnum.

◆ alpha_

lm::alpha_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::isalpha(ch); })
inlinestatic

Single character parser based on std::isalpha.

◆ blank_

lm::blank_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::isblank(ch); })
inlinestatic

Single character parser based on std::blank.

◆ cntrl_

lm::cntrl_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::iscntrl(ch); })
inlinestatic

Single character parser based on std::cntrl.

◆ digit_

lm::digit_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::isdigit(ch); })
inlinestatic

Single character parser based on std::isdigit.

◆ empty_

lm::empty_ = impl::emptytype_()
inlinestatic

Empty parser.

This object matches anything. It does not advance the parser's position. It is occasionally useful to define optional matches with the pattern (parser | empty). For example, lm::lit_("Hello") >> (lm::lit_("World") | lm::empty_) >> lm::end_ would match "Hello" and "HelloWorld". The word "World" is optional in this parser

◆ end_

lm::end_ = impl::endtype_()
inlinestatic

End of input parser.

This object matches the end of the input. For example, lm::end_ by itself matches "". Usually this parser is used in combination with another parser to ensure that the entire input is matched. lm::lit("Prefix") matches "Prefix", but it also matches "PrefixSuffix", "PrefixSuffixSuffix", etc. lm::lit("Prefix") >> lm::end_ will only match "Prefix".

◆ graph_

lm::graph_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::isgraph(ch); })
inlinestatic

Single character parser based on std::graph.

◆ lower_

lm::lower_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::islower(ch); })
inlinestatic

Single character parser based on std::islower.

◆ print_

lm::print_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::isprint(ch); })
inlinestatic

Single character parser based on std::print.

◆ punct_

lm::punct_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::ispunct(ch); })
inlinestatic

Single character parser based on std::punct.

◆ space_

lm::space_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::isspace(ch); })
inlinestatic

Single character parser based on std::space.

◆ upper_

lm::upper_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::isupper(ch); })
inlinestatic

Single character parser based on std::isupper.

◆ xdigit_

lm::xdigit_ = char_if_([](char const ch) noexcept -> bool { return 0 != std::isxdigit(ch); })
inlinestatic

Single character parser based on std::xdigit.