// the type checker. The state remains valid.
template<typename A>
class FailParser {
- public:
+public:
using resultType = A;
constexpr FailParser(const FailParser &) = default;
constexpr explicit FailParser(const char *str) : str_{str} {}
state->messages()->Add(Message{state->position(), str_, state->context()});
return {};
}
- private:
+private:
const char *const str_;
};
// parse, and returns a captured value whose type must be copy-constructible.
template<typename A>
class PureParser {
- public:
+public:
using resultType = A;
constexpr PureParser(const PureParser &) = default;
constexpr explicit PureParser(A &&x) : value_(std::move(x)) {}
std::optional<A> Parse(ParseState *) const { return {value_}; }
- private:
+private:
const A value_;
};
// the ParseState is guaranteed to have been restored to its initial value.
template<typename A>
class BacktrackingParser {
- public:
+public:
using resultType = typename A::resultType;
constexpr BacktrackingParser(const BacktrackingParser &) = default;
constexpr BacktrackingParser(const A &parser) : parser_{parser} {}
}
return result;
}
- private:
+private:
const A parser_;
};
// x fails, returning a useless (but present) result. !x fails when x succeeds.
template<typename PA>
class NegatedParser {
- public:
+public:
using resultType = Success;
constexpr NegatedParser(const NegatedParser &) = default;
constexpr NegatedParser(const PA &p) : parser_{p} {}
}
return {Success{}};
}
- private:
+private:
const PA parser_;
};
// or fails if x does, but the state is not modified.
template<typename PA>
class LookAheadParser {
- public:
+public:
using resultType = Success;
constexpr LookAheadParser(const LookAheadParser &) = default;
constexpr LookAheadParser(const PA &p) : parser_{p} {}
state->messages()->swap(messages);
return parser_.Parse(&forked);
}
- private:
+private:
const PA parser_;
};
// If a is a parser, inContext("...", a) runs it in a nested message context.
template<typename PA>
class MessageContextParser {
- public:
+public:
using resultType = typename PA::resultType;
constexpr MessageContextParser(const MessageContextParser &) = default;
constexpr MessageContextParser(const char *str, const PA &p)
state->PopContext();
return result;
}
- private:
+private:
const char *str_;
const PA parser_;
};
// do so, but the result is that returned by a.
template<typename PA, typename PB>
class SequenceParser {
- public:
+public:
using resultType = typename PB::resultType;
constexpr SequenceParser(const SequenceParser &) = default;
constexpr SequenceParser(const PA &pa, const PB &pb) : pa_{pa}, pb_{pb} {}
}
return {};
}
- private:
+private:
const PA pa_;
const PB pb_;
};
template<typename PA, typename PB>
class InvertedSequenceParser {
- public:
+public:
using resultType = typename PA::resultType;
constexpr InvertedSequenceParser(const InvertedSequenceParser &) = default;
constexpr InvertedSequenceParser(const PA &pa, const PB &pb)
}
return {};
}
- private:
+private:
const PA pa_;
const PB pb_;
};
// must be the same type. If a succeeds, b is not attempted.
template<typename PA, typename PB>
class AlternativeParser {
- public:
+public:
using resultType = typename PA::resultType;
constexpr AlternativeParser(const AlternativeParser &) = default;
constexpr AlternativeParser(const PA &pa, const PB &pb) : pa_{pa}, pb_{pb} {}
state->messages()->swap(messages);
return {};
}
- private:
+private:
const PA pa_;
const PB pb_;
};
// All messages from the first parse are retained.
template<typename PA, typename PB>
class RecoveryParser {
- public:
+public:
using resultType = typename PA::resultType;
constexpr RecoveryParser(const RecoveryParser &) = default;
constexpr RecoveryParser(const PA &pa, const PB &pb) : pa_{pa}, pb_{pb} {}
}
return bx;
}
- private:
+private:
const PA pa_;
const PB pb_;
};
template<typename PA>
class ManyParser {
using paType = typename PA::resultType;
- public:
+public:
using resultType = std::list<paType>;
constexpr ManyParser(const ManyParser &) = default;
constexpr ManyParser(const PA &parser) : parser_{parser} {}
}
return {std::move(result)};
}
- private:
+private:
const BacktrackingParser<PA> parser_;
};
template<typename PA>
class SomeParser {
using paType = typename PA::resultType;
- public:
+public:
using resultType = std::list<paType>;
constexpr SomeParser(const SomeParser &) = default;
constexpr SomeParser(const PA &parser) : parser_{parser} {}
}
return {};
}
- private:
+private:
const PA parser_;
};
// If x is a parser, skipMany(x) is equivalent to many(x) but with no result.
template<typename PA>
class SkipManyParser {
- public:
+public:
using resultType = Success;
constexpr SkipManyParser(const SkipManyParser &) = default;
constexpr SkipManyParser(const PA &parser) : parser_{parser} {}
}
return {Success{}};
}
- private:
+private:
const BacktrackingParser<PA> parser_;
};
// state on failure.
template<typename PA>
class SkipManyFastParser {
- public:
+public:
using resultType = Success;
constexpr SkipManyFastParser(const SkipManyFastParser &) = default;
constexpr SkipManyFastParser(const PA &parser) : parser_{parser} {}
}
return {Success{}};
}
- private:
+private:
const PA parser_;
};
template<typename PA>
class MaybeParser {
using paType = typename PA::resultType;
- public:
+public:
using resultType = std::optional<paType>;
constexpr MaybeParser(const MaybeParser &) = default;
constexpr MaybeParser(const PA &parser) : parser_{parser} {}
}
return {resultType{}};
}
- private:
+private:
const BacktrackingParser<PA> parser_;
};
// result is a default-constructed value of x's result type.
template<typename PA>
class DefaultedParser {
- public:
+public:
using resultType = typename PA::resultType;
constexpr DefaultedParser(const DefaultedParser &) = default;
constexpr DefaultedParser(const PA &p) : parser_{p} {}
}
return {resultType{}};
}
- private:
+private:
const BacktrackingParser<PA> parser_;
};
class Apply1 {
using paType = typename PA::resultType;
using funcType = T (*)(paType &&);
- public:
+public:
using resultType = T;
constexpr Apply1(const Apply1 &) = default;
constexpr Apply1(funcType function, const PA &parser)
}
return {};
}
- private:
+private:
const funcType function_;
const PA parser_;
};
class Apply1Functor {
using paType = typename PA::resultType;
using funcType = std::function<T(paType &&)>;
- public:
+public:
using resultType = T;
Apply1Functor(const Apply1Functor &) = default;
Apply1Functor(const funcType &functor, const PA &parser)
}
return {};
}
- private:
+private:
const funcType &functor_;
const PA parser_;
};
template<typename PA>
class Apply1Mem {
- public:
+public:
using resultType = typename PA::resultType;
using funcType = void (resultType::*)();
constexpr Apply1Mem(const Apply1Mem &) = default;
}
return result;
}
- private:
+private:
const funcType function_;
const PA pa_;
};
using paType = typename PA::resultType;
using pbType = typename PB::resultType;
using funcType = T (*)(paType &&, pbType &&);
- public:
+public:
using resultType = T;
constexpr Apply2(const Apply2 &) = default;
constexpr Apply2(funcType function, const PA &pa, const PB &pb)
}
return {};
}
- private:
+private:
const funcType function_;
const PA pa_;
const PB pb_;
using paType = typename PA::resultType;
using pbType = typename PB::resultType;
using funcType = std::function<T(paType &&, pbType &&)>;
- public:
+public:
using resultType = T;
Apply2Functor(const Apply2Functor &) = default;
Apply2Functor(const funcType &function, const PA &pa, const PB &pb)
}
return {};
}
- private:
+private:
const funcType &function_;
const PA pa_;
const PB pb_;
template<typename PA, typename PB>
class Apply2Mem {
using pbType = typename PB::resultType;
- public:
+public:
using resultType = typename PA::resultType;
using funcType = void (resultType::*)(pbType &&);
constexpr Apply2Mem(const Apply2Mem &) = default;
}
return {};
}
- private:
+private:
const funcType function_;
const PA pa_;
const PB pb_;
using pbType = typename PB::resultType;
using pcType = typename PC::resultType;
using funcType = T (*) (paType &&, pbType &&, pcType &&);
- public:
+public:
using resultType = T;
constexpr Apply3(const Apply3 &) = default;
constexpr Apply3(funcType function, const PA &pa, const PB &pb, const PC &pc)
}
return {};
}
- private:
+private:
const funcType function_;
const PA pa_;
const PB pb_;
class Apply3Mem {
using pbType = typename PB::resultType;
using pcType = typename PC::resultType;
- public:
+public:
using resultType = typename PA::resultType;
using funcType = void (resultType::*)(pbType &&, pcType &&);
constexpr Apply3Mem(const Apply3Mem &) = default;
}
return {};
}
- private:
+private:
const funcType function_;
const PA pa_;
const PB pb_;
using pcType = typename PC::resultType;
using pdType = typename PD::resultType;
using funcType = T (*) (paType &&, pbType &&, pcType &&, pdType &&);
- public:
+public:
using resultType = T;
constexpr Apply4(const Apply4 &) = default;
constexpr Apply4(funcType function, const PA &pa, const PB &pb, const PC &pc,
}
return {};
}
- private:
+private:
const funcType function_;
const PA pa_;
const PB pb_;
using pbType = typename PB::resultType;
using pcType = typename PC::resultType;
using pdType = typename PD::resultType;
- public:
+public:
using resultType = typename PA::resultType;
using funcType = void (resultType::*) (pbType &&, pcType &&, pdType &&);
constexpr Apply4Mem(const Apply4Mem &) = default;
}
return {};
}
- private:
+private:
const funcType function_;
const PA pa_;
const PB pb_;
template<typename PA>
class Construct1 {
- public:
+ public:
using resultType = T;
constexpr Construct1(const Construct1 &) = default;
constexpr explicit Construct1(const PA &parser) : parser_{parser} {}
}
return {};
}
- private:
+ private:
const PA parser_;
};
template<typename PA, typename PB>
class Construct2 {
- public:
+ public:
using resultType = T;
constexpr Construct2(const Construct2 &) = default;
constexpr Construct2(const PA &pa, const PB &pb) : pa_{pa}, pb_{pb} {}
}
return {};
}
- private:
+ private:
const PA pa_;
const PB pb_;
};
template<typename PA, typename PB, typename PC>
class Construct3 {
- public:
+ public:
using resultType = T;
constexpr Construct3(const Construct3 &) = default;
constexpr Construct3(const PA &pa, const PB &pb, const PC &pc)
}
return {};
}
- private:
+ private:
const PA pa_;
const PB pb_;
const PC pc_;
template<typename PA, typename PB, typename PC, typename PD>
class Construct4 {
- public:
+ public:
using resultType = T;
constexpr Construct4(const Construct4 &) = default;
constexpr Construct4(const PA &pa, const PB &pb,
}
return {};
}
- private:
+ private:
const PA pa_;
const PB pb_;
const PC pc_;
template<typename PA, typename PB, typename PC, typename PD, typename PE>
class Construct5 {
- public:
+ public:
using resultType = T;
constexpr Construct5(const Construct5 &) = default;
constexpr Construct5(const PA &pa, const PB &pb,
}
return {};
}
- private:
+ private:
const PA pa_;
const PB pb_;
const PC pc_;
template<typename PA, typename PB, typename PC, typename PD, typename PE,
typename PF>
class Construct6 {
- public:
+ public:
using resultType = T;
constexpr Construct6(const Construct6 &) = default;
constexpr Construct6(const PA &pa, const PB &pb,
}
return {};
}
- private:
+ private:
const PA pa_;
const PB pb_;
const PC pc_;
// StatePredicateGuardParser{f} is a parser that succeeds when f() is true
// and fails otherwise. The state is preserved.
class StatePredicateGuardParser {
- public:
+public:
using resultType = Success;
constexpr StatePredicateGuardParser(const StatePredicateGuardParser &)
= default;
}
return {};
}
- private:
+private:
bool (*const predicate_)(const ParseState &);
};
template<typename PA, typename PB>
class NonemptySeparated {
- private:
+private:
using paType = typename PA::resultType;
- public:
+public:
using resultType = std::list<paType>;
constexpr NonemptySeparated(const NonemptySeparated &) = default;
constexpr NonemptySeparated(const PA &p, const PB &sep)
parser_,
many(separator_ >> parser_)).Parse(state);
}
- private:
+private:
const PA parser_;
const PB separator_;
};
// StateUpdateParser{f} is a parser that always succeeds, possibly with
// side effects on the parsing state.
class StateUpdateParser {
- public:
+public:
using resultType = Success;
constexpr StateUpdateParser(const StateUpdateParser &) = default;
constexpr StateUpdateParser(void (*function)(ParseState *))
function_(state);
return {Success{}};
}
- private:
+private:
void (*const function_)(ParseState *);
};
class BoundMoveParser {
using paType = typename PA::resultType;
using funcType = T (*)(paType &&);
- public:
+public:
using resultType = T;
constexpr BoundMoveParser(const BoundMoveParser &) = default;
constexpr BoundMoveParser(const PA &pa, funcType f) : pa_{pa}, f_{f} {}
}
return {};
}
- private:
+private:
const PA pa_;
const funcType f_;
};
// guard(bool) returns a parser that succeeds iff its dynamic argument
// value is true. The state is preserved.
class GuardParser {
- public:
+public:
using resultType = Success;
constexpr GuardParser(const GuardParser &) = default;
constexpr GuardParser(bool ok) : ok_{ok} {}
}
return {};
}
- private:
+private:
const bool ok_;
};
// signify that the parse is within quotes or Hollerith.
template<typename PA>
class WithinCharLiteral {
- public:
+public:
using resultType = typename PA::resultType;
constexpr WithinCharLiteral(const WithinCharLiteral &) = default;
constexpr WithinCharLiteral(const PA &parser) : parser_{parser} {}
state->set_inCharLiteral(was);
return result;
}
- private:
+private:
const PA parser_;
};
// a warning if such a warning is enabled.
template<typename PA>
class NonstandardParser {
- public:
+public:
using resultType = typename PA::resultType;
constexpr NonstandardParser(const NonstandardParser &) = default;
constexpr NonstandardParser(const PA &parser) : parser_{parser} {}
}
return result;
}
- private:
+private:
const PA parser_;
};
// a warning if such a warning is enabled.
template<typename PA>
class DeprecatedParser {
- public:
+public:
using resultType = typename PA::resultType;
constexpr DeprecatedParser(const DeprecatedParser &) = default;
constexpr DeprecatedParser(const PA &parser) : parser_{parser} {}
}
return result;
}
- private:
+private:
const PA parser_;
};