• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rieske / trans / 29700705556

19 Jul 2026 07:29PM UTC coverage: 90.76% (+0.2%) from 90.53%
29700705556

Pull #46

github

rieske
Experimental parser generator optimization
Pull Request #46: Experimental parser generator optimization

485 of 494 new or added lines in 16 files covered. (98.18%)

17 existing lines in 6 files now uncovered.

5275 of 5812 relevant lines covered (90.76%)

352127.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.36
/src/parser/LR1Item.cpp
1
#include "LR1Item.h"
2

3
#include <algorithm>
4
#include <sstream>
5
#include <stdexcept>
6

7
namespace parser {
8

9
LR1Item::LR1Item(const Production& production, LookaheadSet lookaheads) :
1,101,408✔
10
        production { &production },
1,101,408✔
11
        lookaheadBits { lookaheads }
1,101,408✔
12
{
13
}
1,101,408✔
14

15
LR1Item::LR1Item(const Production& production, const std::vector<int>& lookaheadSymbolIds, const Grammar& grammar) :
30✔
16
        production { &production },
30✔
17
        lookaheadBits { grammar.toLookaheadBits(lookaheadSymbolIds) }
30✔
18
{
19
}
30✔
20

21
LR1Item LR1Item::advance() const {
206,316✔
22
    LR1Item next { *this };
206,316✔
23
    ++next.visitedOffset;
206,316✔
24
    if (next.visitedOffset > static_cast<int>(production->size())) {
206,316✔
25
        throw std::out_of_range { "attempted to advance LR1Item past production size" };
2✔
26
    }
27
    return next;
206,314✔
28
}
29

30
bool LR1Item::mergeLookaheads(const LookaheadSet& more) {
12,817,258✔
31
    const LookaheadSet before = lookaheadBits;
12,817,258✔
32
    lookaheadBits |= more;
12,817,258✔
33
    return lookaheadBits != before;
12,817,258✔
34
}
35

36
bool LR1Item::hasUnvisitedSymbols() const {
3,795,898✔
37
    return visitedOffset < static_cast<int>(production->size());
3,795,898✔
38
}
39

40
int LR1Item::nextUnvisitedSymbol() const {
6,139,290✔
41
    return *(production->begin() + visitedOffset);
6,139,290✔
42
}
43

44
bool LR1Item::hasSymbolsAfterNext() const {
2,441,132✔
45
    return visitedOffset + 1 < static_cast<int>(production->size());
2,441,132✔
46
}
47

48
int LR1Item::symbolAfterNext() const {
1,777,532✔
49
    return *(production->begin() + visitedOffset + 1);
1,777,532✔
50
}
51

52
std::vector<int> LR1Item::getVisited() const {
124✔
53
    return { production->begin(), production->begin() + visitedOffset };
372✔
54
}
55

56
std::vector<int> LR1Item::getExpectedSymbols() const {
124✔
57
    return { production->begin() + visitedOffset, production->end() };
372✔
58
}
59

60
std::vector<int> LR1Item::getLookaheads(const Grammar& grammar) const {
120✔
61
    auto ids = grammar.toTerminalIds(lookaheadBits);
120✔
62
    std::sort(ids.begin(), ids.end());
120✔
63
    return ids;
120✔
NEW
UNCOV
64
}
×
65

66
const LR1Item::LookaheadSet& LR1Item::lookaheads() const noexcept {
1,932,044✔
67
    return lookaheadBits;
1,932,044✔
68
}
69

70
bool LR1Item::hasLookahead(int symbolId, const Grammar& grammar) const {
6✔
71
    return lookaheadBits.test(static_cast<std::size_t>(grammar.terminalBit(symbolId)));
6✔
72
}
73

74
const Production& LR1Item::getProduction() const {
5,952✔
75
    return *production;
5,952✔
76
}
77

78
std::uint64_t LR1Item::coreKey() const noexcept {
18,223,900✔
79
    return (static_cast<std::uint64_t>(static_cast<std::uint32_t>(production->getId())) << 32)
18,223,900✔
80
            | static_cast<std::uint32_t>(visitedOffset);
18,223,900✔
81
}
82

83
std::string LR1Item::str(const Grammar& grammar) const {
118✔
84
    std::stringstream out;
118✔
85
    out << "[ " << grammar.str(production->getDefiningSymbol()) << " -> ";
118✔
86
    for (const auto& s : getVisited()) {
174✔
87
        out << grammar.str(s) << " ";
56✔
88
    }
118✔
89
    out << ". ";
118✔
90
    for (const auto& s : getExpectedSymbols()) {
246✔
91
        out << grammar.str(s) << " ";
128✔
92
    }
118✔
93
    out << ", ";
118✔
94
    for (const auto& s : getLookaheads(grammar)) {
306✔
95
        out << grammar.str(s) << " ";
188✔
96
    }
118✔
97
    out << "]\n";
118✔
98
    return out.str();
236✔
99
}
118✔
100

101
} // namespace parser
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc