mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:47:45 +00:00
Shell: Correctly track nested expansions in POSIX mode
Previously any expansion closing sequence would've caused the entire expansion chain to be terminated, fix this by keeping track of active expansions and running the parser in 'skip' mode. Fixes #19110.
This commit is contained in:
parent
d1f98108a9
commit
b6d7c5fb0e
2 changed files with 62 additions and 10 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <AK/GenericLexer.h>
|
||||
#include <AK/Queue.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/TemporaryChange.h>
|
||||
#include <AK/Variant.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <Shell/AST.h>
|
||||
|
@ -209,7 +210,7 @@ struct State {
|
|||
},
|
||||
};
|
||||
Vector<Expansion> expansions {};
|
||||
Queue<HeredocEntry> heredoc_entries {};
|
||||
Vector<HeredocEntry> heredoc_entries {};
|
||||
bool on_new_line { true };
|
||||
};
|
||||
|
||||
|
@ -313,10 +314,6 @@ struct Token {
|
|||
return Token::Type::And;
|
||||
if (name == "|"sv)
|
||||
return Token::Type::Pipe;
|
||||
if (name == "("sv)
|
||||
return Token::Type::OpenParen;
|
||||
if (name == ")"sv)
|
||||
return Token::Type::CloseParen;
|
||||
if (name == ">"sv)
|
||||
return Token::Type::Great;
|
||||
if (name == "<"sv)
|
||||
|
@ -430,6 +427,17 @@ private:
|
|||
ErrorOr<ReductionResult> reduce_extended_parameter_expansion();
|
||||
ErrorOr<ReductionResult> reduce_heredoc_contents();
|
||||
|
||||
struct SkipTokens {
|
||||
explicit SkipTokens(Lexer& lexer)
|
||||
: m_state_change(lexer.m_state, lexer.m_state)
|
||||
{
|
||||
}
|
||||
|
||||
TemporaryChange<State> m_state_change;
|
||||
};
|
||||
|
||||
SkipTokens switch_to_skip_mode() { return SkipTokens { *this }; }
|
||||
|
||||
char consume();
|
||||
bool consume_specific(char);
|
||||
void reconsume(StringView);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue