Skip to content

Commit

Permalink
Unify the implementations of the non-callback parse() API, to make it…
Browse files Browse the repository at this point in the history
… posible

for the new token parsingcode path to use that one unified implementation too.
The previous implementation dispatched like parse() -> prefix_parse(), the
latter of which is incompatible with token parsing.
  • Loading branch information
tzlaine committed Nov 29, 2024
1 parent 542bdb0 commit f69d7ac
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 185 deletions.
7 changes: 5 additions & 2 deletions include/boost/parser/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#if defined(BOOST_PARSER_DOXYGEN) || BOOST_PARSER_USE_CONCEPTS

#include <boost/parser/lexer_fwd.hpp>

#include <ranges>


Expand All @@ -33,8 +35,9 @@ namespace boost { namespace parser {
//[ parsable_range_like_concept
//[ parsable_range_concept
template<typename T>
concept parsable_range = std::ranges::forward_range<T> &&
code_unit<std::ranges::range_value_t<T>>;
concept parsable_range = (std::ranges::forward_range<T> &&
code_unit<std::ranges::range_value_t<T>>) ||
detail::is_tokens_view_v<T>;
//]

template<typename T>
Expand Down
3 changes: 2 additions & 1 deletion include/boost/parser/lexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#error "lexer.hpp must be included before parser.hpp."
#endif

#include <boost/parser/lexer_fwd.hpp>
#include <boost/parser/parser_fwd.hpp>
#include <boost/parser/concepts.hpp>
#include <boost/parser/detail/debug_assert.hpp>
Expand Down Expand Up @@ -750,7 +751,7 @@ namespace boost { namespace parser {
template<
std::ranges::contiguous_range V,
typename Lexer,
typename TokenCache = std::vector<typename Lexer::token_type>>
typename TokenCache>
requires std::ranges::view<V>
struct tokens_view
: public std::ranges::view_interface<tokens_view<V, Lexer, TokenCache>>
Expand Down
32 changes: 32 additions & 0 deletions include/boost/parser/lexer_fwd.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (C) 2024 T. Zachary Laine
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_PARSER_LEXER_FWD_HPP
#define BOOST_PARSER_LEXER_FWD_HPP

#include <ranges>
#include <vector>

namespace boost { namespace parser {

/** TODO */
template<
std::ranges::contiguous_range V,
typename Lexer,
typename TokenCache = std::vector<typename Lexer::token_type>>
requires std::ranges::view<V>
struct tokens_view;

namespace detail {
template<typename T>
constexpr bool is_tokens_view_v = false;
template<typename V, typename Lexer, typename TokenCache>
constexpr bool is_tokens_view_v<tokens_view<V, Lexer, TokenCache>> =
true;
}

}}

#endif
Loading

0 comments on commit f69d7ac

Please sign in to comment.