summaryrefslogtreecommitdiff
path: root/Userland/Shell/PosixParser.h
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2023-02-16 09:52:13 +0330
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2023-02-18 06:55:46 +0330
commit2881bb4c3af162fb294fe54d56b7408060728a62 (patch)
tree8346d4ce02374142817138a06baac3d958a295ae /Userland/Shell/PosixParser.h
parenta5e4bc4fafc182c12384b71c724429426508777d (diff)
downloadserenity-2881bb4c3af162fb294fe54d56b7408060728a62.zip
Shell: Add support for heredocs to the POSIX parser
Diffstat (limited to 'Userland/Shell/PosixParser.h')
-rw-r--r--Userland/Shell/PosixParser.h14
1 files changed, 9 insertions, 5 deletions
diff --git a/Userland/Shell/PosixParser.h b/Userland/Shell/PosixParser.h
index 4f873128ce..3ffebaa347 100644
--- a/Userland/Shell/PosixParser.h
+++ b/Userland/Shell/PosixParser.h
@@ -13,12 +13,12 @@ namespace Shell::Posix {
class Parser {
public:
- Parser(StringView input, bool interactive = false)
+ Parser(StringView input, bool interactive = false, Optional<Reduction> starting_reduction = {})
: m_lexer(input)
, m_in_interactive_mode(interactive)
, m_eof_token(Token::eof())
{
- fill_token_buffer();
+ fill_token_buffer(starting_reduction);
}
RefPtr<AST::Node> parse();
@@ -31,20 +31,23 @@ public:
auto& errors() const { return m_errors; }
private:
- Optional<Token> next_expanded_token();
+ Optional<Token> next_expanded_token(Optional<Reduction> starting_reduction = {});
Vector<Token> perform_expansions(Vector<Token> tokens);
- void fill_token_buffer();
+ void fill_token_buffer(Optional<Reduction> starting_reduction = {});
+ void handle_heredoc_contents();
- Token const& peek() const
+ Token const& peek()
{
if (eof())
return m_eof_token;
+ handle_heredoc_contents();
return m_token_buffer[m_token_index];
}
Token const& consume()
{
if (eof())
return m_eof_token;
+ handle_heredoc_contents();
return m_token_buffer[m_token_index++];
}
void skip()
@@ -108,6 +111,7 @@ private:
Vector<Token> m_previous_token_buffer;
Vector<Error> m_errors;
+ HashMap<DeprecatedString, NonnullRefPtr<AST::Heredoc>> m_unprocessed_heredoc_entries;
Token m_eof_token;