LPeter1997 / CppCmb

A generic C++17 parser-combinator library with a natural grammar notation.
MIT License
123 stars 8 forks source link

Simplify the lazy rule_set fetching #9

Closed QuarticCat closed 3 years ago

QuarticCat commented 3 years ago

Originally, the code uses a metafunction second to delay the time when rule_set<T> executes, because this metafunction needs an undetermined argument Src. However, if the compiler is smart enough (IDK whether this case exists), it can find that Src is actually not used and evaluate it immediately.

What I have done is to put the type to a template parameter, so that the value of rule_set<T> must be delayed until cppcmb_parse_rule being invoked. It also simplifies the code. It is still IFNDR though.

Apart from that, I doubt the use of cppcmb_parse_rule inside rule_t::apply is also IFNDR.

QuarticCat commented 3 years ago

I tested your code with GCC 10.2 and Clang 11.1 and it passed all tests.

LPeter1997 commented 3 years ago

Thank you for your contribution! It is indeed a bit more elegant this way.