mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:27:44 +00:00
Shell: Make the parser read consecutive sequences without recursing
This fixes (the easy) part of #4976.
This commit is contained in:
parent
212c90d68f
commit
2bd77bc93b
7 changed files with 130 additions and 100 deletions
|
@ -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 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue