1 #ifndef MYPARSER_RULE_HPP
2 #define MYPARSER_RULE_HPP
19 template <
size_t L,
size_t M>
23 static const size_t most = M;
49 static std::pair<Node *, Node *>
parse(
59 template <
class N,
class... RL>
62 template <
size_t I,
class R,
class... Rx>
68 ::template Helper<N, I>;
70 Input input_rev = input;
72 auto current = Member::parse(input, end);
79 auto next =
runRule<I + 1, Rx...>(input, end);
82 return {next.first, current.second};
86 next.second->challengeLonger(current.second)
110 static std::pair<Node *, Node *>
parse(
113 return runRule<0, RL...>(input, end);
117 template <
class N,
class RX>
123 #if defined(MYPARSER_BOOST_XPRESSIVE)
124 static const regex_lib::basic_regex<Input> re =
125 regex_lib::basic_regex<Input>::compile<
Input>(
126 RX::getStr().cbegin(),
130 static const regex_lib::regex re(
135 regex_lib::match_results<Input> mdata;
138 regex_lib::regex_search(
139 input, end, mdata, re,
140 regex_lib::regex_constants::match_continuous
143 std::string str = mdata.str();
149 if (result->accepted()) {
150 return {result,
nullptr};
173 static std::pair<Node *, Node *>
parse(
176 return runRegex(input, end);
182 template <
class N = BuiltinSpace,
class TAG = TagNormal>
192 template <
class KW,
class N = BuiltinKeyword,
class TAG = TagNormal>
203 current.first->getFullText() == KW::getStr()
208 current.first->free();
214 ->challengeLonger(current.second)
220 template <
class N,
class TAG = TagNormal>
230 template <
class E,
class TAG = TagNormal>
247 template <
class... RL>
250 template <
class N,
size_t I>
253 template <
class R,
class... Rx>
258 for (
size_t i = 0; i < R::most; ++i) {
259 auto current = R::parse(input, end);
261 if (current.second) {
265 if (err == current.second) {
266 errpos = result->getChildren().size();
270 if (!current.first) {
277 result->putChild(current.first);
281 return runRule<Rx...>(result, err, errpos, input, end);
284 template <std::
nullptr_t P =
nullptr>
307 bool succeed =
runRule<RL...>(result, err, errpos, input, end);
309 result->bind(result_err, errpos);
310 result_err->bind(result, errpos);
313 for (
size_t i = 0; i < errpos; ++i) {
314 result_err->putChild(result->getChildren()[i]);
316 result_err->putChild(err);
319 result_err =
nullptr;
327 return {result, result_err};
332 template <
class N = BuiltinRoot>
339 if (current.second) {
340 current.second->free();
343 return current.first;
345 return current.second;
350 Input iter = input.cbegin();
352 return parse(iter, input.cend());
356 Input iter = input.cbegin();
358 return parse(iter, input.cend());
static MYPARSER_INLINE std::pair< Node *, Node * > parse(Input &input, const Input &end)
Definition: myparser_rule.hpp:299
Definition: myparser_rule.hpp:60
Definition: myparser_rule.hpp:231
Definition: myparser_ast.hpp:229
Definition: myparser_rule.hpp:248
Definition: myparser_rule.hpp:221
static Node * parse(std::string &&input)
Definition: myparser_rule.hpp:355
MP_STR("Match not accepted", 18) ErrorChecking
Definition: myparser_rule.hpp:16
static const size_t least
Definition: myparser_rule.hpp:22
Definition: myparser_ast.hpp:10
Definition: myparser_rule.hpp:183
static const size_t most
Definition: myparser_rule.hpp:23
MYPARSER_INLINE RuleList()
Definition: myparser_rule.hpp:105
static MYPARSER_INLINE std::pair< Node *, Node * > runRule(Input &input, const Input &end)
Definition: myparser_rule.hpp:63
Definition: myparser_rule.hpp:118
static MYPARSER_INLINE std::pair< Node *, Node * > parse(Input &input, const Input &end)
Definition: myparser_rule.hpp:223
RuleNamed()
Definition: myparser_rule.hpp:40
Rule()
Definition: myparser_rule.hpp:32
MP_STR("error", 5) BuiltinError
Definition: myparser_rule.hpp:12
Node * challengeLonger(Node *target)
Definition: myparser_ast.hpp:52
static MYPARSER_INLINE std::pair< Node *, Node * > parse(Input &input, const Input &end)
Definition: myparser_rule.hpp:185
static MYPARSER_INLINE std::pair< Node *, Node * > parse(Input &input, const Input &end)
Definition: myparser_rule.hpp:233
static MYPARSER_INLINE bool runRule(NodeListTyped< N, I > *&result, Node *&err, size_t &errpos, Input &input, const Input &end)
Definition: myparser_rule.hpp:254
#define MP_STR(str, len)
Definition: myparser_str.hpp:9
static MYPARSER_INLINE bool runRule(NodeListTyped< N, I > *&result, Node *&err, size_t &errpos, Input &input, const Input &end)
Definition: myparser_rule.hpp:285
static std::pair< Node *, Node * > parse(Input &input, const Input &end)
Definition: myparser_rule.hpp:173
MYPARSER_INLINE RuleRegex()
Definition: myparser_rule.hpp:168
static MYPARSER_INLINE std::pair< Node *, Node * > runRegex(Input &input, const Input &end)
Definition: myparser_rule.hpp:120
Definition: myparser_rule.hpp:251
MP_STR("space", 5) BuiltinSpace
Definition: myparser_rule.hpp:10
static MYPARSER_INLINE std::pair< Node *, Node * > parse(Input &input, const Input &end)
Definition: myparser_rule.hpp:195
MP_STR("Nothing matched", 15) ErrorList
Definition: myparser_rule.hpp:14
static std::pair< Node *, Node * > parse(Input &input, const Input &end)
Definition: myparser_rule.hpp:193
MP_STR("Regex not matched", 17) ErrorRegex
Definition: myparser_rule.hpp:15
static std::pair< Node *, Node * > parse(Input &input, const Input &end)
Definition: myparser_rule.hpp:110
static MYPARSER_INLINE std::pair< Node *, Node * > runRule(Input &input, const Input &end)
Definition: myparser_rule.hpp:93
MP_STR("root", 4) BuiltinRoot
Definition: myparser_rule.hpp:9
MP_STR("Bad keyword", 11) ErrorKeyword
Definition: myparser_rule.hpp:17
Definition: myparser_rule.hpp:30
static Node * parse(Input &input, const Input &end)
Definition: myparser_rule.hpp:335
Definition: myparser_rule.hpp:20
std::string::const_iterator Input
Definition: myparser_ast.hpp:8
static Node * parse(const std::string input)
Definition: myparser_rule.hpp:349
MP_STR("keyword", 7) BuiltinKeyword
Definition: myparser_rule.hpp:11
#define MYPARSER_INLINE
Definition: myparser_common.hpp:50
Definition: myparser_rule.hpp:333
Definition: myparser_rule.hpp:47
Definition: myparser_rule.hpp:38