Skip to content

Commit

Permalink
Plumb a pointer to the tokens_view through to the parse context; change
Browse files Browse the repository at this point in the history
seq_parser to use the tokens_view pointer from the contet to trim the cache at
an expectation point.

See #202.
  • Loading branch information
tzlaine committed Nov 29, 2024
1 parent f298bfe commit 9dbf302
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 57 deletions.
14 changes: 10 additions & 4 deletions include/boost/parser/lexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,14 +818,18 @@ namespace boost { namespace parser {
private:
// Called during parse after reaching an expectation point.
template<bool Const>
void clear_tokens_before(iterator<Const> it)
void clear_tokens_before(iterator<Const> it) const
{
size_t const erasure = it.token_offset_ - base_token_offset_;
tokens_.erase(tokens_.begin(), tokens_.begin() + erasure);
base_token_offset_ += erasure;
}
// TODO: Plumb a pointer to this view into the parse context, and call
// clear_tokens_before from seq_parser after each expectation point.

template<
typename ParserTuple,
typename BacktrackingTuple,
typename CombiningGroups>
friend struct seq_parser;

// TODO: Document that the token cache will grow without bound if the
// parser contains no sequence points.
Expand Down Expand Up @@ -996,8 +1000,10 @@ namespace boost { namespace parser {
template<bool OtherConst>
bool equal_to(iterator<OtherConst> const & x) const
{
if (x.token_offset_ != x.parent_->tokens_.size())
if (x.token_offset_ - x.parent_->base_token_offset_ !=
x.parent_->tokens_.size()) {
return false;
}
auto r = std::ranges::subrange(
x.parent_->latest_, std::ranges::end(x.parent_->base_));
auto ctre_range = Lexer::regex_range(r);
Expand Down
Loading

0 comments on commit 9dbf302

Please sign in to comment.