- added StepDisabled to the lexer, an useful utility for graph modification for reusage in connection with StepReplacementPoint + unit tests
- added compilation syntax for the new step type
@@ -170,6 +170,8 @@ | ||
170 | 170 | typename cenv_t::SerializedStep cctoken_rep = &cenv; |
171 | 171 | typename cenv_t::StepAttribution cctoken_single = &cenv; |
172 | 172 | |
173 | + typename cenv_t::StepToken disabledprod = &cenv; | |
174 | + | |
173 | 175 | typename cenv_t::StepProgrammableToken prodtoken = &cenv; |
174 | 176 | typename cenv_t::StepToken tokinline = &cenv; |
175 | 177 | typename cenv_t::StepToken tokextended = &cenv; |
@@ -1191,6 +1193,23 @@ | ||
1191 | 1193 | |
1192 | 1194 | safe_enclosed_prod.AddConnection( &cctoken_single ); |
1193 | 1195 | |
1196 | + // *** DISABLED PRODUCTION *** | |
1197 | + | |
1198 | + disabledprod.token_str = _Token_DollarSign <charType> (); | |
1199 | + disabledprod.token_str += _Token_Disabled <charType> (); | |
1200 | + disabledprod.setConstructor( | |
1201 | + [this]( void ) -> ExecStep* | |
1202 | + { | |
1203 | + if ( auto *runtime_env = this->runtime_env ) | |
1204 | + { | |
1205 | + return runtime_env->CreateStep <typename compileForEnvType::StepDisabled> (); | |
1206 | + } | |
1207 | + return nullptr; | |
1208 | + } | |
1209 | + ); | |
1210 | + | |
1211 | + safe_enclosed_prod.AddConnection( &disabledprod ); | |
1212 | + | |
1194 | 1213 | // *** CALL PRODUCTION TOKEN *** |
1195 | 1214 | |
1196 | 1215 | prodtoken.callback = []( LexingPoint& pt ) -> std::optional <eir::FixedString <charType>> |
@@ -2025,6 +2044,31 @@ | ||
2025 | 2044 | } |
2026 | 2045 | |
2027 | 2046 | template <eir::CharacterType charType> |
2047 | + static AINLINE const charType* _Token_Disabled( void ) noexcept | |
2048 | + { | |
2049 | + if constexpr ( std::same_as <charType, char> ) | |
2050 | + { | |
2051 | + return "disabled"; | |
2052 | + } | |
2053 | + if constexpr ( std::same_as <charType, wchar_t> ) | |
2054 | + { | |
2055 | + return L"disabled"; | |
2056 | + } | |
2057 | + if constexpr ( std::same_as <charType, char8_t> ) | |
2058 | + { | |
2059 | + return u8"disabled"; | |
2060 | + } | |
2061 | + if constexpr ( std::same_as <charType, char16_t> ) | |
2062 | + { | |
2063 | + return u"disabled"; | |
2064 | + } | |
2065 | + if constexpr ( std::same_as <charType, char32_t> ) | |
2066 | + { | |
2067 | + return U"disabled"; | |
2068 | + } | |
2069 | + } | |
2070 | + | |
2071 | + template <eir::CharacterType charType> | |
2028 | 2072 | static AINLINE const charType* _Token_Comma( void ) noexcept |
2029 | 2073 | { |
2030 | 2074 | if constexpr ( std::same_as <charType, char> ) |
@@ -2701,6 +2701,39 @@ | ||
2701 | 2701 | } |
2702 | 2702 | }; |
2703 | 2703 | |
2704 | + // Step which just denies all input. | |
2705 | + // Good toolkit for selective modification of grammar graphs in connection with replacement-point-step. | |
2706 | + struct StepDisabled : public Step | |
2707 | + { | |
2708 | + using Step::Step; | |
2709 | + | |
2710 | + Step* Clone( void ) override | |
2711 | + { | |
2712 | + return this->env->CloneStep <StepDisabled> ( this ); | |
2713 | + } | |
2714 | + | |
2715 | + bool IsUnambiguousCall( void ) const noexcept override | |
2716 | + { | |
2717 | + return true; | |
2718 | + } | |
2719 | + | |
2720 | + bool IsUndeniableChange( void ) const noexcept override | |
2721 | + { | |
2722 | + // We cannot have any change in the first place, so yes. | |
2723 | + return true; | |
2724 | + } | |
2725 | + | |
2726 | + bool DoesInheritSubStepDenial( size_t cur_proc_idx ) const noexcept override | |
2727 | + { | |
2728 | + return true; | |
2729 | + } | |
2730 | + | |
2731 | + size_t GetChoiceCount( void ) const noexcept override | |
2732 | + { | |
2733 | + return 1; | |
2734 | + } | |
2735 | + }; | |
2736 | + | |
2704 | 2737 | struct EnvironmentAllocator |
2705 | 2738 | { |
2706 | 2739 | inline EnvironmentAllocator( LexingEnvironment *env ) noexcept : env( env ) |
@@ -4506,6 +4539,11 @@ | ||
4506 | 4539 | is_op_successful = false; |
4507 | 4540 | } |
4508 | 4541 | } |
4542 | + else if ( StepDisabled *denystep = dynamic_cast <StepDisabled*> ( current_step ) ) | |
4543 | + { | |
4544 | + has_op_finished = true; | |
4545 | + is_op_successful = false; | |
4546 | + } | |
4509 | 4547 | else |
4510 | 4548 | { |
4511 | 4549 | FATAL_ABORT(); |
@@ -5038,6 +5076,7 @@ | ||
5038 | 5076 | // StepProceduralSequence |
5039 | 5077 | // StepCustomIndirection |
5040 | 5078 | // StepReplacementPoint |
5079 | + // StepDisabled (moot) | |
5041 | 5080 | |
5042 | 5081 | // This opcode has no further special handling. |
5043 | 5082 | has_op_finished = true; |
@@ -607,7 +607,7 @@ | ||
607 | 607 | } |
608 | 608 | printf( "ok.\n" ); |
609 | 609 | |
610 | - printf( "testing LexingCompiler replacement-point-step..." ); | |
610 | + printf( "testing LexingCompiler compiling replacement-point-step..." ); | |
611 | 611 | { |
612 | 612 | LexingEnvironment <char, LexNodeType> env; |
613 | 613 | LexingCompiler <char, decltype(env)> compiler; |
@@ -626,6 +626,20 @@ | ||
626 | 626 | } |
627 | 627 | printf( "ok.\n" ); |
628 | 628 | |
629 | + printf( "testing LexingCompiler compiling disabled-step..." ); | |
630 | + { | |
631 | + LexingEnvironment <char, LexNodeType> env; | |
632 | + LexingCompiler <char, decltype(env)> compiler; | |
633 | + | |
634 | + auto *step = compiler.CompileProduction( &env, "$disabled" ); | |
635 | + | |
636 | + assert( step != nullptr ); | |
637 | + assert( dynamic_cast <decltype(env)::StepDisabled*> ( step ) != nullptr ); | |
638 | + | |
639 | + step->Delete(); | |
640 | + } | |
641 | + printf( "ok.\n" ); | |
642 | + | |
629 | 643 | printf( "testing LexingCompiler construction with object allocator..." ); |
630 | 644 | { |
631 | 645 | LexingEnvironment <char, LexNodeType, EirHeapLinkAllocator> env( eir::constr_with_alloc::DEFAULT, &globalHeapAlloc ); |
@@ -6286,6 +6286,22 @@ | ||
6286 | 6286 | } |
6287 | 6287 | printf( "ok.\n" ); |
6288 | 6288 | |
6289 | + printf( "testing ProductionMachine StepDisabled..." ); | |
6290 | + { | |
6291 | + // There is not really much to test other than the machine does process it. | |
6292 | + | |
6293 | + TestAllocEnv env( eir::constr_with_alloc::DEFAULT, &globalHeapAlloc ); | |
6294 | + | |
6295 | + decltype(env)::StepDisabled disabled( &env ); | |
6296 | + | |
6297 | + decltype(env)::ProductionMachine machine( &env ); | |
6298 | + | |
6299 | + machine.Execute( "", &disabled ); | |
6300 | + | |
6301 | + assert( machine.successful == false ); | |
6302 | + } | |
6303 | + printf( "ok.\n" ); | |
6304 | + | |
6289 | 6305 | printf( "testing ProductionMachine mintwo-specialized-selector (simple list)..." ); |
6290 | 6306 | { |
6291 | 6307 | struct Node |