@@ -768,9 +768,11 @@ class Context {
768
768
769
769
std::vector<bool > cut_stack;
770
770
771
+ #ifdef CPPPEGLIB_SYMBOL_TABLE_SUPPORT
771
772
std::vector<std::map<std::string, std::unordered_set<std::string>>>
772
773
symbol_tables_stack;
773
774
size_t symbol_tables_stack_size = 0 ;
775
+ #endif
774
776
775
777
const size_t def_count;
776
778
const bool enablePackratParsing;
@@ -802,7 +804,9 @@ class Context {
802
804
push_args ({});
803
805
push_capture_scope ();
804
806
807
+ #ifdef CPPPEGLIB_SYMBOL_TABLE_SUPPORT
805
808
push_symbol_tables ();
809
+ #endif
806
810
}
807
811
808
812
~Context () {
@@ -812,8 +816,10 @@ class Context {
812
816
assert (!capture_scope_stack_size);
813
817
assert (cut_stack.empty ());
814
818
819
+ #ifdef CPPPEGLIB_SYMBOL_TABLE_SUPPORT
815
820
pop_symbol_tables ();
816
821
assert (!symbol_tables_stack_size);
822
+ #endif
817
823
}
818
824
819
825
Context (const Context &) = delete ;
@@ -854,14 +860,18 @@ class Context {
854
860
855
861
SemanticValues &push () {
856
862
push_capture_scope ();
863
+ #ifdef CPPPEGLIB_SYMBOL_TABLE_SUPPORT
857
864
push_symbol_tables ();
865
+ #endif
858
866
return push_semantic_values_scope ();
859
867
}
860
868
861
869
void pop () {
862
870
pop_capture_scope ();
863
871
pop_semantic_values_scope ();
872
+ #ifdef CPPPEGLIB_SYMBOL_TABLE_SUPPORT
864
873
pop_symbol_tables ();
874
+ #endif
865
875
}
866
876
867
877
// Semantic values
@@ -924,6 +934,7 @@ class Context {
924
934
}
925
935
}
926
936
937
+ #ifdef CPPPEGLIB_SYMBOL_TABLE_SUPPORT
927
938
// Symbol tables
928
939
void push_symbol_tables () {
929
940
assert (symbol_tables_stack_size <= symbol_tables_stack.size ());
@@ -968,6 +979,7 @@ class Context {
968
979
}
969
980
return false ;
970
981
}
982
+ #endif
971
983
972
984
// Error
973
985
void set_error_pos (const char *a_s, const char *literal = nullptr );
@@ -1060,7 +1072,9 @@ class PrioritizedChoice : public Ope {
1060
1072
vs.choice_count_ = opes_.size ();
1061
1073
vs.choice_ = id;
1062
1074
c.shift_capture_values ();
1075
+ #ifdef CPPPEGLIB_SYMBOL_TABLE_SUPPORT
1063
1076
c.shift_symbol_tables ();
1077
+ #endif
1064
1078
break ;
1065
1079
} else if (!c.cut_stack .empty () && c.cut_stack .back ()) {
1066
1080
break ;
@@ -1100,7 +1114,9 @@ class Repetition : public Ope {
1100
1114
if (success (len)) {
1101
1115
vs.append (chvs);
1102
1116
c.shift_capture_values ();
1117
+ #ifdef CPPPEGLIB_SYMBOL_TABLE_SUPPORT
1103
1118
c.shift_symbol_tables ();
1119
+ #endif
1104
1120
} else {
1105
1121
return len;
1106
1122
}
@@ -1117,7 +1133,9 @@ class Repetition : public Ope {
1117
1133
if (success (len)) {
1118
1134
vs.append (chvs);
1119
1135
c.shift_capture_values ();
1136
+ #ifdef CPPPEGLIB_SYMBOL_TABLE_SUPPORT
1120
1137
c.shift_symbol_tables ();
1138
+ #endif
1121
1139
} else {
1122
1140
break ;
1123
1141
}
@@ -2398,9 +2416,11 @@ class Definition {
2398
2416
2399
2417
bool eoi_check = true ;
2400
2418
2419
+ #ifdef CPPPEGLIB_SYMBOL_TABLE_SUPPORT
2401
2420
bool declare_symbol = false ;
2402
2421
bool check_symbol = false ;
2403
2422
std::string symbol_table_name;
2423
+ #endif
2404
2424
2405
2425
private:
2406
2426
friend class Reference ;
@@ -2775,6 +2795,7 @@ inline size_t Holder::parse_core(const char *s, size_t n, SemanticValues &vs,
2775
2795
c.error_info .message = msg;
2776
2796
}
2777
2797
len = static_cast <size_t >(-1 );
2798
+ #ifdef CPPPEGLIB_SYMBOL_TABLE_SUPPORT
2778
2799
} else if (outer_->declare_symbol ) {
2779
2800
assert (outer_->is_token ());
2780
2801
auto symbol = chvs.token_to_string ();
@@ -2791,6 +2812,7 @@ inline size_t Holder::parse_core(const char *s, size_t n, SemanticValues &vs,
2791
2812
msg = " '" + symbol + " ' doesn't exist." ;
2792
2813
len = static_cast <size_t >(-1 );
2793
2814
}
2815
+ #endif
2794
2816
}
2795
2817
2796
2818
if (success (len)) {
@@ -3443,8 +3465,10 @@ class ParserGenerator {
3443
3465
g[" EndBlacket" ]);
3444
3466
g[" InstructionItem" ] <= cho (g[" PrecedenceClimbing" ], g[" ErrorMessage" ],
3445
3467
g[" NoAstOpt" ]
3468
+ #ifdef CPPPEGLIB_SYMBOL_TABLE_SUPPORT
3446
3469
,
3447
3470
g[" DeclareSymbol" ], g[" CheckSymbol" ]
3471
+ #endif
3448
3472
);
3449
3473
~g[" InstructionItemSeparator" ] <= seq (chr (' ;' ), g[" Spacing" ]);
3450
3474
@@ -3478,11 +3502,13 @@ class ParserGenerator {
3478
3502
// No Ast node optimazation instruction
3479
3503
g[" NoAstOpt" ] <= seq (lit (" no_ast_opt" ), g[" SpacesZom" ]);
3480
3504
3505
+ #ifdef CPPPEGLIB_SYMBOL_TABLE_SUPPORT
3481
3506
// Symbol table instruction
3482
3507
g[" DeclareSymbol" ] <= seq (lit (" declare_symbol" ), g[" SpacesZom" ],
3483
3508
g[" Identifier" ], g[" SpacesZom" ]);
3484
3509
g[" CheckSymbol" ] <= seq (lit (" check_symbol" ), g[" SpacesZom" ],
3485
3510
g[" Identifier" ], g[" SpacesZom" ]);
3511
+ #endif
3486
3512
3487
3513
// Set definition names
3488
3514
for (auto &x : g) {
@@ -3886,6 +3912,7 @@ class ParserGenerator {
3886
3912
return instruction;
3887
3913
};
3888
3914
3915
+ #ifdef CPPPEGLIB_SYMBOL_TABLE_SUPPORT
3889
3916
g[" DeclareSymbol" ] = [](const SemanticValues &vs) {
3890
3917
Instruction instruction;
3891
3918
instruction.type = " declare_symbol" ;
@@ -3901,6 +3928,7 @@ class ParserGenerator {
3901
3928
instruction.sv = vs.sv ();
3902
3929
return instruction;
3903
3930
};
3931
+ #endif
3904
3932
3905
3933
g[" Instruction" ] = [](const SemanticValues &vs) {
3906
3934
return vs.transform <Instruction>();
@@ -4152,12 +4180,14 @@ class ParserGenerator {
4152
4180
rule.error_message = std::any_cast<std::string>(instruction.data );
4153
4181
} else if (instruction.type == " no_ast_opt" ) {
4154
4182
rule.no_ast_opt = true ;
4183
+ #ifdef CPPPEGLIB_SYMBOL_TABLE_SUPPORT
4155
4184
} else if (instruction.type == " declare_symbol" ) {
4156
4185
rule.declare_symbol = true ;
4157
4186
rule.symbol_table_name = std::any_cast<std::string>(instruction.data );
4158
4187
} else if (instruction.type == " check_symbol" ) {
4159
4188
rule.check_symbol = true ;
4160
4189
rule.symbol_table_name = std::any_cast<std::string>(instruction.data );
4190
+ #endif
4161
4191
}
4162
4192
}
4163
4193
}
0 commit comments