@@ -134,14 +134,17 @@ __get_cxx_version ()
134
134
135
135
auto input_guard = input_redirection (config.allow_stdin );
136
136
137
- // Check for magics
138
- for (auto & pre : preamble_manager.preamble )
137
+ if (code.find (" %undo" ) != 0 )
139
138
{
140
- if (pre.second .is_match (code))
139
+ // Check for magics
140
+ for (auto & pre : preamble_manager.preamble )
141
141
{
142
- pre.second .apply (code, kernel_res);
143
- cb (kernel_res);
144
- return ;
142
+ if (pre.second .is_match (code))
143
+ {
144
+ pre.second .apply (code, kernel_res);
145
+ cb (kernel_res);
146
+ return ;
147
+ }
145
148
}
146
149
}
147
150
@@ -169,7 +172,32 @@ __get_cxx_version ()
169
172
try
170
173
{
171
174
StreamRedirectRAII R (err);
172
- compilation_result = Cpp::Process (code.c_str ());
175
+ if (code.rfind (" %undo" , 0 ) == 0 )
176
+ {
177
+ int n = 1 ; // Default value
178
+ if (code.length () > 5 )
179
+ {
180
+ try
181
+ {
182
+ n = std::stoi (code.substr (6 ));
183
+ }
184
+ catch (const std::invalid_argument&)
185
+ {
186
+ throw std::runtime_error (
187
+ " Invalid format for %undo. Expected '%undo n' where n is an integer."
188
+ );
189
+ }
190
+ catch (const std::out_of_range&)
191
+ {
192
+ throw std::runtime_error (" Number out of range for %undo." );
193
+ }
194
+ }
195
+ compilation_result = Cpp::Undo (n) ? true : false ;
196
+ }
197
+ else
198
+ {
199
+ compilation_result = Cpp::Process (code.c_str ());
200
+ }
173
201
}
174
202
catch (std::exception& e)
175
203
{
0 commit comments