Skip to content

Commit 7d28d64

Browse files
committed
add empty token as sentinel in front of copied token list
1 parent f2528f5 commit 7d28d64

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

messer.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,12 +1285,14 @@ class phase4_t{
12851285
std::list<token_t> copy(object_it->second.begin(), object_it->second.end());
12861286
for(auto&& x : copy)
12871287
x.annotation() = it->annotation();
1288+
copy.push_front({{"", token_type::empty}, it->annotation()});
12881289
pp_state copy_state{copy, std::move(tmp_state.replaced)};
12891290
yield(state, copy_state, copy.begin(), {output_range<std::list<token_t>::const_iterator>{copy.begin(), copy.end()}, output_range<std::list<token_t>::const_iterator>{std::next(it), end}});
12901291
for(auto it_ = std::next(copy.begin()), end_ = copy.end(); it_ != end_; ++it_)
12911292
if(it_->type() == token_type::punctuator_hashhash)
12921293
it_ = apply_cat(it_, copy_state),
12931294
yield(state, copy_state, std::next(it_), {output_range<std::list<token_t>::const_iterator>{copy.begin(), copy.end()}, output_range<std::list<token_t>::const_iterator>{std::next(it), end}});
1295+
copy.pop_front();
12941296
for(auto it_ = copy.begin(), end_ = copy.end(); it_ != end_; ++it_){
12951297
if(check_recur != tmp_state.replaced.end())
12961298
copy_state.replaced[it_] = check_recur->second;
@@ -1603,11 +1605,12 @@ class phase4_t{
16031605
}
16041606
}
16051607
}
1608+
copy.push_front({{"", token_type::empty}, it->annotation()});
16061609
std::size_t index = 0;
16071610
auto func_yield = [&](auto it_, std::size_t id){
16081611
std::vector<output_range<std::list<token_t>::const_iterator>> ret;
1609-
if(it_ != copy.begin())
1610-
ret.emplace_back(copy.begin(), it_);
1612+
if(it_ != std::next(copy.begin()))
1613+
ret.emplace_back(std::next(copy.begin()), it_);
16111614
auto b = it_;
16121615
while(it_ != copy.end() && id < f->second.arg_index.size()){
16131616
const auto ai = f->second.arg_index[id];
@@ -1629,8 +1632,8 @@ class phase4_t{
16291632
ret.emplace_back(arg_it, end);
16301633
yield(state, tmp_state, it_, ret);
16311634
};
1632-
func_yield(copy.begin(), index);
1633-
for(auto it_ = copy.begin(); it_ != copy.end();){
1635+
func_yield(std::next(copy.begin()), index);
1636+
for(auto it_ = std::next(copy.begin()); it_ != copy.end();){
16341637
if(it_->type() == token_type::punctuator_hash){
16351638
static auto search = [](const auto& it, auto sentinel){
16361639
try{
@@ -1701,6 +1704,7 @@ class phase4_t{
17011704
copy_eval_insert(copy_eval_insert, copy, it_, args[ ai-1].begin(), args[ai-1].end(), index, tmp_state);
17021705
++index;
17031706
}
1707+
copy.pop_front();
17041708
for(auto it_ = copy.begin(), end_ = copy.end(); it_ != end_; ++it_){
17051709
if(tmp_state.replaced[it_].empty())
17061710
tmp_state.replaced[it_] = recur;

0 commit comments

Comments
 (0)