ladybird/Userland/Shell/NodeVisitor.h
Ali Mohammad Pur 3048274f5e Shell: Add support for heredocs
Closes #4283.
Heredocs are implemented in a way that makes them feel more like a
string (and not a weird redirection, a la bash).
There are two tunables, whether the string is dedented (`<<-` vs `<<~`)
and whether it allows interpolation (quoted key vs not).
To the familiar people, this is how Ruby handles them, and I feel is the
most elegant heredoc syntax.
Unlike the oddjob that is bash, heredocs are treated exactly as normal
strings, and can be used _anywhere_ where a string can be used.
They are *required* to appear in the same order as used after a newline
is seen when parsing the sequence that the heredoc is used in.
For instance:
```sh
echo <<-doc1 <<-doc2 | blah blah
contents for doc1
doc1
contents for doc2
doc2
```
The typical nice errors are also implemented :^)
2021-04-29 20:25:56 +02:00

65 lines
2.4 KiB
C++

/*
* Copyright (c) 2020, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include "Forward.h"
namespace Shell::AST {
class NodeVisitor {
public:
virtual void visit(const AST::PathRedirectionNode*);
virtual void visit(const AST::And*);
virtual void visit(const AST::ListConcatenate*);
virtual void visit(const AST::Background*);
virtual void visit(const AST::BarewordLiteral*);
virtual void visit(const AST::BraceExpansion*);
virtual void visit(const AST::CastToCommand*);
virtual void visit(const AST::CastToList*);
virtual void visit(const AST::CloseFdRedirection*);
virtual void visit(const AST::CommandLiteral*);
virtual void visit(const AST::Comment*);
virtual void visit(const AST::ContinuationControl*);
virtual void visit(const AST::DynamicEvaluate*);
virtual void visit(const AST::DoubleQuotedString*);
virtual void visit(const AST::Fd2FdRedirection*);
virtual void visit(const AST::FunctionDeclaration*);
virtual void visit(const AST::ForLoop*);
virtual void visit(const AST::Glob*);
virtual void visit(const AST::Heredoc*);
virtual void visit(const AST::HistoryEvent*);
virtual void visit(const AST::Execute*);
virtual void visit(const AST::IfCond*);
virtual void visit(const AST::ImmediateExpression*);
virtual void visit(const AST::Join*);
virtual void visit(const AST::MatchExpr*);
virtual void visit(const AST::Or*);
virtual void visit(const AST::Pipe*);
virtual void visit(const AST::Range*);
virtual void visit(const AST::ReadRedirection*);
virtual void visit(const AST::ReadWriteRedirection*);
virtual void visit(const AST::Sequence*);
virtual void visit(const AST::Subshell*);
virtual void visit(const AST::Slice*);
virtual void visit(const AST::SimpleVariable*);
virtual void visit(const AST::SpecialVariable*);
virtual void visit(const AST::Juxtaposition*);
virtual void visit(const AST::StringLiteral*);
virtual void visit(const AST::StringPartCompose*);
virtual void visit(const AST::SyntaxError*);
virtual void visit(const AST::SyntheticNode*);
virtual void visit(const AST::Tilde*);
virtual void visit(const AST::VariableDeclarations*);
virtual void visit(const AST::WriteAppendRedirection*);
virtual void visit(const AST::WriteRedirection*);
protected:
virtual ~NodeVisitor() = default;
};
}