@@ -1643,8 +1643,6 @@ struct Ope::Visitor
1643
1643
1644
1644
struct AssignIDToDefinition : public Ope ::Visitor
1645
1645
{
1646
- using Ope::Visitor::visit;
1647
-
1648
1646
void visit (Sequence& ope) override {
1649
1647
for (auto op: ope.opes_ ) {
1650
1648
op->accept (*this );
@@ -1676,8 +1674,6 @@ struct TokenChecker : public Ope::Visitor
1676
1674
{
1677
1675
TokenChecker () : has_token_boundary_(false ), has_rule_(false ) {}
1678
1676
1679
- using Ope::Visitor::visit;
1680
-
1681
1677
void visit (Sequence& ope) override {
1682
1678
for (auto op: ope.opes_ ) {
1683
1679
op->accept (*this );
@@ -1699,8 +1695,10 @@ struct TokenChecker : public Ope::Visitor
1699
1695
void visit (Reference& ope) override ;
1700
1696
void visit (Whitespace& ope) override { ope.ope_ ->accept (*this ); }
1701
1697
1702
- bool is_token () const {
1703
- return has_token_boundary_ || !has_rule_;
1698
+ static bool is_token (Ope& ope) {
1699
+ TokenChecker vis;
1700
+ ope.accept (vis);
1701
+ return vis.has_token_boundary_ || !vis.has_rule_ ;
1704
1702
}
1705
1703
1706
1704
private:
@@ -1712,8 +1710,6 @@ struct DetectLeftRecursion : public Ope::Visitor {
1712
1710
DetectLeftRecursion (const std::string& name)
1713
1711
: error_s(nullptr ), name_(name), done_(false ) {}
1714
1712
1715
- using Ope::Visitor::visit;
1716
-
1717
1713
void visit (Sequence& ope) override {
1718
1714
for (auto op: ope.opes_ ) {
1719
1715
op->accept (*this );
@@ -1768,8 +1764,6 @@ struct ReferenceChecker : public Ope::Visitor {
1768
1764
const std::vector<std::string>& params)
1769
1765
: grammar_(grammar), params_(params) {}
1770
1766
1771
- using Ope::Visitor::visit;
1772
-
1773
1767
void visit (Sequence& ope) override {
1774
1768
for (auto op: ope.opes_ ) {
1775
1769
op->accept (*this );
@@ -1808,8 +1802,6 @@ struct LinkReferences : public Ope::Visitor {
1808
1802
const std::vector<std::string>& params)
1809
1803
: grammar_(grammar), params_(params) {}
1810
1804
1811
- using Ope::Visitor::visit;
1812
-
1813
1805
void visit (Sequence& ope) override {
1814
1806
for (auto op: ope.opes_ ) {
1815
1807
op->accept (*this );
@@ -1845,8 +1837,6 @@ struct FindReference : public Ope::Visitor {
1845
1837
const std::vector<std::string>& params)
1846
1838
: args_(args), params_(params) {}
1847
1839
1848
- using Ope::Visitor::visit;
1849
-
1850
1840
void visit (Sequence& ope) override {
1851
1841
std::vector<std::shared_ptr<Ope>> opes;
1852
1842
for (auto o: ope.opes_ ) {
@@ -1888,6 +1878,24 @@ struct FindReference : public Ope::Visitor {
1888
1878
const std::vector<std::string>& params_;
1889
1879
};
1890
1880
1881
+ struct IsPrioritizedChoice : public Ope ::Visitor
1882
+ {
1883
+ IsPrioritizedChoice () : is_prioritized_choice_(false ) {}
1884
+
1885
+ void visit (PrioritizedChoice& /* ope*/ ) override {
1886
+ is_prioritized_choice_ = true ;
1887
+ }
1888
+
1889
+ static bool is_prioritized_choice (Ope& ope) {
1890
+ IsPrioritizedChoice vis;
1891
+ ope.accept (vis);
1892
+ return vis.is_prioritized_choice_ ;
1893
+ }
1894
+
1895
+ private:
1896
+ bool is_prioritized_choice_;
1897
+ };
1898
+
1891
1899
/*
1892
1900
* Keywords
1893
1901
*/
@@ -2038,9 +2046,7 @@ class Definition
2038
2046
2039
2047
bool is_token () const {
2040
2048
std::call_once (is_token_init_, [this ]() {
2041
- TokenChecker vis;
2042
- get_core_operator ()->accept (vis);
2043
- is_token_ = vis.is_token ();
2049
+ is_token_ = TokenChecker::is_token (*get_core_operator ());
2044
2050
});
2045
2051
return is_token_;
2046
2052
}
@@ -2179,8 +2185,7 @@ inline size_t Holder::parse(const char* s, size_t n, SemanticValues& sv, Context
2179
2185
// Macro reference
2180
2186
// TODO: need packrat support
2181
2187
if (outer_->is_macro ) {
2182
- const auto & rule = *ope_;
2183
- return rule.parse (s, n, sv, c, dt);
2188
+ return ope_->parse (s, n, sv, c, dt);
2184
2189
}
2185
2190
2186
2191
size_t len;
@@ -2201,14 +2206,18 @@ inline size_t Holder::parse(const char* s, size_t n, SemanticValues& sv, Context
2201
2206
2202
2207
auto & chldsv = c.push ();
2203
2208
2204
- const auto & rule = *ope_;
2205
- len = rule.parse (s, n, chldsv, c, dt);
2209
+ len = ope_->parse (s, n, chldsv, c, dt);
2206
2210
2207
2211
// Invoke action
2208
2212
if (success (len)) {
2209
2213
chldsv.s_ = s;
2210
2214
chldsv.n_ = len;
2211
2215
2216
+ if (!IsPrioritizedChoice::is_prioritized_choice (*ope_)) {
2217
+ chldsv.choice_count_ = 0 ;
2218
+ chldsv.choice_ = 0 ;
2219
+ }
2220
+
2212
2221
try {
2213
2222
a_val = reduce (chldsv, dt);
2214
2223
} catch (const parse_error& e) {
0 commit comments