summaryrefslogtreecommitdiff
path: root/Userland/Shell/Parser.h
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2021-01-16 23:20:52 +0330
committerAndreas Kling <kling@serenityos.org>2021-01-23 08:28:58 +0100
commit2bd77bc93bece47b791a8448db0f6b70003b7831 (patch)
tree272028f98826275b10f365b38b42319941e848c1 /Userland/Shell/Parser.h
parent212c90d68f1a312cbda06a8822730bbffed9f9ec (diff)
downloadserenity-2bd77bc93bece47b791a8448db0f6b70003b7831.zip
Shell: Make the parser read consecutive sequences without recursing
This fixes (the easy) part of #4976.
Diffstat (limited to 'Userland/Shell/Parser.h')
-rw-r--r--Userland/Shell/Parser.h17
1 files changed, 16 insertions, 1 deletions
diff --git a/Userland/Shell/Parser.h b/Userland/Shell/Parser.h
index aa2a3b9e53..a3f09b944e 100644
--- a/Userland/Shell/Parser.h
+++ b/Userland/Shell/Parser.h
@@ -55,9 +55,19 @@ public:
SavedOffset save_offset() const;
private:
+ enum class ShouldReadMoreSequences {
+ Yes,
+ No,
+ };
+ struct SequenceParseResult {
+ NonnullRefPtrVector<AST::Node> entries;
+ Vector<AST::Position, 1> separator_positions;
+ ShouldReadMoreSequences decision;
+ };
+
constexpr static size_t max_allowed_nested_rule_depth = 2048;
RefPtr<AST::Node> parse_toplevel();
- RefPtr<AST::Node> parse_sequence();
+ SequenceParseResult parse_sequence();
RefPtr<AST::Node> parse_function_decl();
RefPtr<AST::Node> parse_and_logical_sequence();
RefPtr<AST::Node> parse_or_logical_sequence();
@@ -108,6 +118,10 @@ private:
StringView consume_while(Function<bool(char)>);
+ struct Offset {
+ size_t offset;
+ AST::Position::Line line;
+ };
struct ScopedOffset {
ScopedOffset(Vector<size_t>& offsets, Vector<AST::Position::Line>& lines, size_t offset, size_t lineno, size_t linecol)
: offsets(offsets)
@@ -136,6 +150,7 @@ private:
void restore_to(const ScopedOffset& offset) { restore_to(offset.offset, offset.line); }
OwnPtr<ScopedOffset> push_start();
+ Offset current_position();
StringView m_input;
size_t m_offset { 0 };