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

rieske / trans / 29698450533

19 Jul 2026 06:17PM UTC coverage: 90.744% (+0.2%) from 90.53%
29698450533

Pull #46

github

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

494 of 504 new or added lines in 17 files covered. (98.02%)

1 existing line in 1 file now uncovered.

5284 of 5823 relevant lines covered (90.74%)

309085.6 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) :
991,300✔
10
        production { &production },
991,300✔
11
        lookaheadBits { lookaheads }
991,300✔
12
{
13
}
991,300✔
14

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

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

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

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

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

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

48
int LR1Item::symbolAfterNext() const {
1,461,354✔
49
    return *(production->begin() + visitedOffset + 1);
1,461,354✔
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
64
}
×
65

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

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

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

78
std::uint64_t LR1Item::coreKey() const noexcept {
2,456,836✔
79
    return (static_cast<std::uint64_t>(static_cast<std::uint32_t>(production->getId())) << 32)
2,456,836✔
80
            | static_cast<std::uint32_t>(visitedOffset);
2,456,836✔
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