mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:47:34 +00:00
Shell: Add runtime errors and implement break/continue
Such errors are raised when SyntaxError nodes are executed, and are also used for internal control flow. The 'break' and 'continue' commands are currently only allowed inside for loops, and outside function bodies. This also adds a 'loop' keyword for infinite loops.
This commit is contained in:
parent
9bd81f34a5
commit
5e5eb615ec
14 changed files with 384 additions and 62 deletions
|
@ -201,6 +201,31 @@ public:
|
|||
ReadLine,
|
||||
};
|
||||
|
||||
enum class ShellError {
|
||||
None,
|
||||
InternalControlFlowBreak,
|
||||
InternalControlFlowContinue,
|
||||
EvaluatedSyntaxError,
|
||||
NonExhaustiveMatchRules,
|
||||
InvalidGlobError,
|
||||
};
|
||||
|
||||
void raise_error(ShellError kind, String description)
|
||||
{
|
||||
m_error = kind;
|
||||
m_error_description = move(description);
|
||||
}
|
||||
bool has_error(ShellError err) const { return m_error == err; }
|
||||
const String& error_description() const { return m_error_description; }
|
||||
ShellError take_error()
|
||||
{
|
||||
auto err = m_error;
|
||||
m_error = ShellError::None;
|
||||
m_error_description = {};
|
||||
return err;
|
||||
}
|
||||
void possibly_print_error() const;
|
||||
|
||||
#define __ENUMERATE_SHELL_OPTION(name, default_, description) \
|
||||
bool name { default_ };
|
||||
|
||||
|
@ -263,6 +288,9 @@ private:
|
|||
bool m_is_subshell { false };
|
||||
bool m_should_reinstall_signal_handlers { true };
|
||||
|
||||
ShellError m_error { ShellError::None };
|
||||
String m_error_description;
|
||||
|
||||
bool m_should_format_live { false };
|
||||
|
||||
RefPtr<Line::Editor> m_editor;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue