Skip to content

Commit

Permalink
Sketch in operator() on token_spec_t.
Browse files Browse the repository at this point in the history
See #202.
  • Loading branch information
tzlaine committed Nov 29, 2024
1 parent fbc21ef commit 1a405f8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 11 deletions.
10 changes: 10 additions & 0 deletions include/boost/parser/lexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,16 @@ namespace boost { namespace parser {
static constexpr id_type id = ID;
static constexpr int base = Base < 0 ? 10 : Base;
static constexpr bool is_character_token = Base < 0;

/** TODO */
template<typename ID2>
constexpr auto operator()(ID2 id) const noexcept;

/** TODO */
template<typename ID2, typename Value>
constexpr auto operator()(ID2 id, Value value) const noexcept;

// implementations in token_parser.hpp
};

/** TODO */
Expand Down
52 changes: 41 additions & 11 deletions include/boost/parser/token_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,21 @@ namespace boost { namespace parser {
++first;
}

// TODO: token_spec_t needs these same operator() overloads, each of
// which will return a token_parser.

// TODO: Constrain both ID params below only to accept type
// convertible to int.
// TODO: Constrain all ID params below (incl. the ones from
// token_spec_t) only to accept type convertible to int.

/** TODO */
template<typename ID>
constexpr auto operator()(ID id) const noexcept
{
BOOST_PARSER_ASSERT(
(detail::is_nope_v<Expected> &&
"If you're seeing this, you tried to chain calls on tok or "
"tok_t, like 'tok(id1)(id2)'. Quit it!'"));
return parser_interface(detail::token_with_id((int)id));
"If you're seeing this, you tried to chain calls on tok, "
"tok_t, or one of your token_spec_t's, like 'tok(id1)(id2)'. "
"Quit it!'"));
return parser_interface(
token_parser<AttributeType, detail::token_with_id>(
detail::token_with_id((int)id)));
}

/** TODO */
Expand All @@ -185,15 +185,45 @@ namespace boost { namespace parser {
{
BOOST_PARSER_ASSERT(
(detail::is_nope_v<Expected> &&
"If you're seeing this, you tried to chain calls on tok or "
"tok_t, like 'tok(id1)(id2)'. Quit it!'"));
"If you're seeing this, you tried to chain calls on tok, "
"tok_t, or one of your token_spec_t's, like 'tok(id1)(id2)'. "
"Quit it!'"));
return parser_interface(
detail::token_with_id_and_value((int)id, value));
token_parser<
AttributeType,
detail::token_with_id_and_value<expected_value_type>>(
detail::token_with_id_and_value((int)id, value)));
}

Expected expected_;
};

template<ctll::fixed_string Regex, auto ID, typename ValueType, int Base>
template<typename ID2>
constexpr auto
token_spec_t<Regex, ID, ValueType, Base>::operator()(ID2 id) const noexcept
{
using attribute_type = std::
conditional_t<std::same_as<ValueType, none>, token_tag, ValueType>;
return parser_interface(
token_parser<attribute_type, detail::token_with_id>(
detail::token_with_id((int)id)));
}

template<ctll::fixed_string Regex, auto ID, typename ValueType, int Base>
template<typename ID2, typename Value>
constexpr auto token_spec_t<Regex, ID, ValueType, Base>::operator()(
ID2 id, Value value) const noexcept
{
using attribute_type = std::
conditional_t<std::same_as<ValueType, none>, token_tag, ValueType>;
return parser_interface(token_parser<
attribute_type,
detail::token_with_id_and_value<Value>>(
detail::token_with_id_and_value((int)id, value)));
}


#endif

/** TODO */
Expand Down

0 comments on commit 1a405f8

Please sign in to comment.