• R/O
  • SSH
  • HTTPS

eircompile: Commit


Commit MetaInfo

Revision62 (tree)
Time2021-12-18 03:59:30
Authorquiret

Log Message

- 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

Change Summary

Incremental Difference

--- eircompile/include/eircompile/lexing_compile.h (revision 61)
+++ eircompile/include/eircompile/lexing_compile.h (revision 62)
@@ -170,6 +170,8 @@
170170 typename cenv_t::SerializedStep cctoken_rep = &cenv;
171171 typename cenv_t::StepAttribution cctoken_single = &cenv;
172172
173+ typename cenv_t::StepToken disabledprod = &cenv;
174+
173175 typename cenv_t::StepProgrammableToken prodtoken = &cenv;
174176 typename cenv_t::StepToken tokinline = &cenv;
175177 typename cenv_t::StepToken tokextended = &cenv;
@@ -1191,6 +1193,23 @@
11911193
11921194 safe_enclosed_prod.AddConnection( &cctoken_single );
11931195
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+
11941213 // *** CALL PRODUCTION TOKEN ***
11951214
11961215 prodtoken.callback = []( LexingPoint& pt ) -> std::optional <eir::FixedString <charType>>
@@ -2025,6 +2044,31 @@
20252044 }
20262045
20272046 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>
20282072 static AINLINE const charType* _Token_Comma( void ) noexcept
20292073 {
20302074 if constexpr ( std::same_as <charType, char> )
--- eircompile/include/eircompile/lexing_env.h (revision 61)
+++ eircompile/include/eircompile/lexing_env.h (revision 62)
@@ -2701,6 +2701,39 @@
27012701 }
27022702 };
27032703
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+
27042737 struct EnvironmentAllocator
27052738 {
27062739 inline EnvironmentAllocator( LexingEnvironment *env ) noexcept : env( env )
@@ -4506,6 +4539,11 @@
45064539 is_op_successful = false;
45074540 }
45084541 }
4542+ else if ( StepDisabled *denystep = dynamic_cast <StepDisabled*> ( current_step ) )
4543+ {
4544+ has_op_finished = true;
4545+ is_op_successful = false;
4546+ }
45094547 else
45104548 {
45114549 FATAL_ABORT();
@@ -5038,6 +5076,7 @@
50385076 // StepProceduralSequence
50395077 // StepCustomIndirection
50405078 // StepReplacementPoint
5079+ // StepDisabled (moot)
50415080
50425081 // This opcode has no further special handling.
50435082 has_op_finished = true;
--- testcompiler/src/lexingcomp_tests.cpp (revision 61)
+++ testcompiler/src/lexingcomp_tests.cpp (revision 62)
@@ -607,7 +607,7 @@
607607 }
608608 printf( "ok.\n" );
609609
610- printf( "testing LexingCompiler replacement-point-step..." );
610+ printf( "testing LexingCompiler compiling replacement-point-step..." );
611611 {
612612 LexingEnvironment <char, LexNodeType> env;
613613 LexingCompiler <char, decltype(env)> compiler;
@@ -626,6 +626,20 @@
626626 }
627627 printf( "ok.\n" );
628628
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+
629643 printf( "testing LexingCompiler construction with object allocator..." );
630644 {
631645 LexingEnvironment <char, LexNodeType, EirHeapLinkAllocator> env( eir::constr_with_alloc::DEFAULT, &globalHeapAlloc );
--- testcompiler/src/lexingenv_tests.cpp (revision 61)
+++ testcompiler/src/lexingenv_tests.cpp (revision 62)
@@ -6286,6 +6286,22 @@
62866286 }
62876287 printf( "ok.\n" );
62886288
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+
62896305 printf( "testing ProductionMachine mintwo-specialized-selector (simple list)..." );
62906306 {
62916307 struct Node
Show on old repository browser