mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +00:00
Shell: Allow Syntax errors to be mutated while parsing
Some nodes (such as heredocs) cannot be validated immediately, so the entire tree will need to be revalidated if we don't allow mutating syntax errors.
This commit is contained in:
parent
39369f1da6
commit
0d742557c6
2 changed files with 41 additions and 13 deletions
|
@ -248,6 +248,25 @@ static Vector<String> resolve_slices(RefPtr<Shell> shell, Vector<String>&& value
|
||||||
return move(values);
|
return move(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Node::clear_syntax_error()
|
||||||
|
{
|
||||||
|
m_syntax_error_node->clear_syntax_error();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Node::set_is_syntax_error(const SyntaxError& error_node)
|
||||||
|
{
|
||||||
|
if (!m_syntax_error_node) {
|
||||||
|
m_syntax_error_node = error_node;
|
||||||
|
} else {
|
||||||
|
m_syntax_error_node->set_is_syntax_error(error_node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Node::is_syntax_error() const
|
||||||
|
{
|
||||||
|
return m_syntax_error_node && m_syntax_error_node->is_syntax_error();
|
||||||
|
}
|
||||||
|
|
||||||
void Node::for_each_entry(RefPtr<Shell> shell, Function<IterationDecision(NonnullRefPtr<Value>)> callback)
|
void Node::for_each_entry(RefPtr<Shell> shell, Function<IterationDecision(NonnullRefPtr<Value>)> callback)
|
||||||
{
|
{
|
||||||
auto value = run(shell)->resolve_without_cast(shell);
|
auto value = run(shell)->resolve_without_cast(shell);
|
||||||
|
@ -1884,7 +1903,7 @@ ImmediateExpression::ImmediateExpression(Position position, NameWithPosition fun
|
||||||
, m_function(move(function))
|
, m_function(move(function))
|
||||||
, m_closing_brace_position(move(closing_brace_position))
|
, m_closing_brace_position(move(closing_brace_position))
|
||||||
{
|
{
|
||||||
if (m_is_syntax_error)
|
if (is_syntax_error())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (auto& argument : m_arguments) {
|
for (auto& argument : m_arguments) {
|
||||||
|
@ -3021,7 +3040,6 @@ SyntaxError::SyntaxError(Position position, String error, bool is_continuable)
|
||||||
, m_syntax_error_text(move(error))
|
, m_syntax_error_text(move(error))
|
||||||
, m_is_continuable(is_continuable)
|
, m_is_continuable(is_continuable)
|
||||||
{
|
{
|
||||||
m_is_syntax_error = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const SyntaxError& SyntaxError::syntax_error_node() const
|
const SyntaxError& SyntaxError::syntax_error_node() const
|
||||||
|
|
|
@ -407,6 +407,9 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
class Node : public RefCounted<Node> {
|
class Node : public RefCounted<Node> {
|
||||||
|
AK_MAKE_NONCOPYABLE(Node);
|
||||||
|
AK_MAKE_NONMOVABLE(Node);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void dump(int level) const = 0;
|
virtual void dump(int level) const = 0;
|
||||||
virtual void for_each_entry(RefPtr<Shell> shell, Function<IterationDecision(NonnullRefPtr<Value>)> callback);
|
virtual void for_each_entry(RefPtr<Shell> shell, Function<IterationDecision(NonnullRefPtr<Value>)> callback);
|
||||||
|
@ -431,20 +434,15 @@ public:
|
||||||
virtual bool is_tilde() const { return false; }
|
virtual bool is_tilde() const { return false; }
|
||||||
virtual bool is_variable_decls() const { return false; }
|
virtual bool is_variable_decls() const { return false; }
|
||||||
virtual bool is_simple_variable() const { return false; }
|
virtual bool is_simple_variable() const { return false; }
|
||||||
virtual bool is_syntax_error() const { return m_is_syntax_error; }
|
virtual bool is_syntax_error() const;
|
||||||
|
|
||||||
virtual bool is_list() const { return false; }
|
virtual bool is_list() const { return false; }
|
||||||
virtual bool would_execute() const { return false; }
|
virtual bool would_execute() const { return false; }
|
||||||
virtual bool should_override_execution_in_current_process() const { return false; }
|
virtual bool should_override_execution_in_current_process() const { return false; }
|
||||||
|
|
||||||
const Position& position() const { return m_position; }
|
const Position& position() const { return m_position; }
|
||||||
void set_is_syntax_error(const SyntaxError& error_node)
|
virtual void clear_syntax_error();
|
||||||
{
|
virtual void set_is_syntax_error(const SyntaxError& error_node);
|
||||||
if (!m_is_syntax_error) {
|
|
||||||
m_is_syntax_error = true;
|
|
||||||
m_syntax_error_node = error_node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
virtual const SyntaxError& syntax_error_node() const
|
virtual const SyntaxError& syntax_error_node() const
|
||||||
{
|
{
|
||||||
VERIFY(is_syntax_error());
|
VERIFY(is_syntax_error());
|
||||||
|
@ -508,8 +506,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Position m_position;
|
Position m_position;
|
||||||
bool m_is_syntax_error { false };
|
RefPtr<SyntaxError> m_syntax_error_node;
|
||||||
RefPtr<const SyntaxError> m_syntax_error_node;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NODE(name) \
|
#define NODE(name) \
|
||||||
|
@ -1363,17 +1360,30 @@ public:
|
||||||
const String& error_text() const { return m_syntax_error_text; }
|
const String& error_text() const { return m_syntax_error_text; }
|
||||||
bool is_continuable() const { return m_is_continuable; }
|
bool is_continuable() const { return m_is_continuable; }
|
||||||
|
|
||||||
|
virtual void clear_syntax_error() override
|
||||||
|
{
|
||||||
|
m_is_cleared = true;
|
||||||
|
}
|
||||||
|
virtual void set_is_syntax_error(const SyntaxError& error) override
|
||||||
|
{
|
||||||
|
m_is_cleared = error.m_is_cleared;
|
||||||
|
m_is_continuable = error.m_is_continuable;
|
||||||
|
m_syntax_error_text = error.error_text();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool is_syntax_error() const override { return !m_is_cleared; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NODE(SyntaxError);
|
NODE(SyntaxError);
|
||||||
virtual void dump(int level) const override;
|
virtual void dump(int level) const override;
|
||||||
virtual RefPtr<Value> run(RefPtr<Shell>) override;
|
virtual RefPtr<Value> run(RefPtr<Shell>) override;
|
||||||
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
|
virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
|
||||||
virtual HitTestResult hit_test_position(size_t) const override { return { nullptr, nullptr, nullptr }; }
|
virtual HitTestResult hit_test_position(size_t) const override { return { nullptr, nullptr, nullptr }; }
|
||||||
virtual bool is_syntax_error() const override { return true; }
|
|
||||||
virtual const SyntaxError& syntax_error_node() const override;
|
virtual const SyntaxError& syntax_error_node() const override;
|
||||||
|
|
||||||
String m_syntax_error_text;
|
String m_syntax_error_text;
|
||||||
bool m_is_continuable { false };
|
bool m_is_continuable { false };
|
||||||
|
bool m_is_cleared { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
class SyntheticNode final : public Node {
|
class SyntheticNode final : public Node {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue