Skip to content

Commit

Permalink
Initial sketch of a lexer for Boost.Parser, based on using CTRE as an…
Browse files Browse the repository at this point in the history
… external

dependency.  Lots of TODOs, somewhat thin testing, but the basics work.

See #202.
  • Loading branch information
tzlaine committed Nov 5, 2024
1 parent bb0fb88 commit eaa53d5
Show file tree
Hide file tree
Showing 5 changed files with 1,453 additions and 1 deletion.
14 changes: 14 additions & 0 deletions include/boost/parser/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,18 @@
# define BOOST_PARSER_TRACE_OSTREAM std::cout
#endif

#if defined(_MSC_VER)
# define BOOST_PARSER_DIAGNOSTIC_PUSH __pragma(warning(push))
# define BOOST_PARSER_DIAGNOSTIC_POP __pragma(warning(pop))
#elif defined(__clang_major__)
# define BOOST_PARSER_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
# define BOOST_PARSER_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
#elif defined(__GNUC__)
# define BOOST_PARSER_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
# define BOOST_PARSER_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
#else
# define BOOST_PARSER_DIAGNOSTIC_PUSH
# define BOOST_PARSER_DIAGNOSTIC_POP
#endif

#endif
25 changes: 25 additions & 0 deletions include/boost/parser/detail/hl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,31 @@ namespace boost { namespace parser { namespace detail::hl {
}


// fold_n

template<std::size_t I, std::size_t N>
struct fold_n_dispatch
{
template<typename F, typename State>
constexpr static auto call(State && s, F const & f)
{
if constexpr (I + 1 == N) {
return f((State &&)s, llong<I>{});
} else {
return fold_n_dispatch<I + 1, N>::call(
f((State &&)s, llong<I>{}), f);
}
}
};

template<std::size_t N, typename F, typename State>
constexpr auto fold_n(State && s, F const & f)
{
static_assert(0 < N, "fold_n must operate on sequences of length >= 1");
return hl::fold_n_dispatch<0, N>::call((State &&)s, (F &&)f);
}


// size

template<typename... Args>
Expand Down
Loading

0 comments on commit eaa53d5

Please sign in to comment.