@@ -1674,6 +1674,33 @@ struct AssignIDToDefinition : public Ope::Visitor
1674
1674
std::unordered_map<void *, size_t > ids;
1675
1675
};
1676
1676
1677
+ struct IsLiteralToken : public Ope ::Visitor
1678
+ {
1679
+ IsLiteralToken () : result_(false ) {}
1680
+
1681
+ void visit (PrioritizedChoice& ope) override {
1682
+ for (auto op: ope.opes_ ) {
1683
+ if (!IsLiteralToken::check (*op)) {
1684
+ return ;
1685
+ }
1686
+ }
1687
+ result_ = true ;
1688
+ }
1689
+
1690
+ void visit (LiteralString& /* ope*/ ) override {
1691
+ result_ = true ;
1692
+ }
1693
+
1694
+ static bool check (Ope& ope) {
1695
+ IsLiteralToken vis;
1696
+ ope.accept (vis);
1697
+ return vis.result_ ;
1698
+ }
1699
+
1700
+ private:
1701
+ bool result_;
1702
+ };
1703
+
1677
1704
struct TokenChecker : public Ope ::Visitor
1678
1705
{
1679
1706
TokenChecker () : has_token_boundary_(false ), has_rule_(false ) {}
@@ -1700,6 +1727,10 @@ struct TokenChecker : public Ope::Visitor
1700
1727
void visit (Whitespace& ope) override { ope.ope_ ->accept (*this ); }
1701
1728
1702
1729
static bool is_token (Ope& ope) {
1730
+ if (IsLiteralToken::check (ope)) {
1731
+ return true ;
1732
+ }
1733
+
1703
1734
TokenChecker vis;
1704
1735
ope.accept (vis);
1705
1736
return vis.has_token_boundary_ || !vis.has_rule_ ;
@@ -1884,20 +1915,20 @@ struct FindReference : public Ope::Visitor {
1884
1915
1885
1916
struct IsPrioritizedChoice : public Ope ::Visitor
1886
1917
{
1887
- IsPrioritizedChoice () : is_prioritized_choice_ (false ) {}
1918
+ IsPrioritizedChoice () : result_ (false ) {}
1888
1919
1889
1920
void visit (PrioritizedChoice& /* ope*/ ) override {
1890
- is_prioritized_choice_ = true ;
1921
+ result_ = true ;
1891
1922
}
1892
1923
1893
- static bool is_prioritized_choice (Ope& ope) {
1924
+ static bool check (Ope& ope) {
1894
1925
IsPrioritizedChoice vis;
1895
1926
ope.accept (vis);
1896
- return vis.is_prioritized_choice_ ;
1927
+ return vis.result_ ;
1897
1928
}
1898
1929
1899
1930
private:
1900
- bool is_prioritized_choice_ ;
1931
+ bool result_ ;
1901
1932
};
1902
1933
1903
1934
/*
@@ -2218,7 +2249,7 @@ inline size_t Holder::parse(const char* s, size_t n, SemanticValues& sv, Context
2218
2249
chldsv.n_ = len;
2219
2250
chldsv.name_ = outer_->name ;
2220
2251
2221
- if (!IsPrioritizedChoice::is_prioritized_choice (*ope_)) {
2252
+ if (!IsPrioritizedChoice::check (*ope_)) {
2222
2253
chldsv.choice_count_ = 0 ;
2223
2254
chldsv.choice_ = 0 ;
2224
2255
}
@@ -2885,6 +2916,14 @@ class ParserGenerator
2885
2916
2886
2917
// Automatic whitespace skipping
2887
2918
if (grammar.count (WHITESPACE_DEFINITION_NAME)) {
2919
+ for (auto & x: grammar) {
2920
+ auto & rule = x.second ;
2921
+ auto ope = rule.get_core_operator ();
2922
+ if (IsLiteralToken::check (*ope)) {
2923
+ rule <= tok (ope);
2924
+ }
2925
+ }
2926
+
2888
2927
auto & rule = (*data.grammar )[start];
2889
2928
rule.whitespaceOpe = wsp ((*data.grammar )[WHITESPACE_DEFINITION_NAME].get_core_operator ());
2890
2929
}
0 commit comments