Bash++
Bash++ compiler internal documentation
RawText.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <AST/ASTNode.h>
9
10namespace AST {
11
12class RawText : public ASTNode {
13 protected:
15 std::string getEscapedText() const {
16 std::string escaped;
17 for (char c : m_TEXT.getValue()) {
18 switch (c) {
19 case '\n': escaped += "\\n"; break;
20 case '\t': escaped += "\\t"; break;
21 case '\r': escaped += "\\r"; break;
22 default: escaped += c; break;
23 }
24 }
25 return escaped;
26 }
27 public:
29 constexpr AST::NodeType getType() const override { return static_type; }
30
32 return m_TEXT;
33 }
34 void setText(const AST::Token<std::string>& text) {
35 m_TEXT = text;
36 }
37 void appendText(const std::string& text) {
38 m_TEXT += text;
39 }
40
41 std::ostream& prettyPrint(std::ostream& os, int indentation_level = 0) const override {
42 std::string indent(indentation_level * PRETTYPRINT_INDENTATION_AMOUNT, ' ');
43 os << indent << "(RawText " << getEscapedText();
44 for (const auto& child : children) {
45 os << std::endl;
46 child->prettyPrint(os, indentation_level + 1);
47 }
48 os << ")" << std::flush;
49 return os;
50 }
51};
52
53} // namespace AST
#define PRETTYPRINT_INDENTATION_AMOUNT
Definition ASTNode.h:18
The base class for all non-terminal nodes in the Bash++ AST. Each ASTNode contains information about ...
Definition ASTNode.h:28
std::vector< std::shared_ptr< ASTNode > > children
Definition ASTNode.h:30
Definition RawText.h:12
std::string getEscapedText() const
Definition RawText.h:15
void appendText(const std::string &text)
Definition RawText.h:37
static constexpr AST::NodeType static_type
Definition RawText.h:28
std::ostream & prettyPrint(std::ostream &os, int indentation_level=0) const override
Definition RawText.h:41
constexpr AST::NodeType getType() const override
Definition RawText.h:29
AST::Token< std::string > m_TEXT
Definition RawText.h:14
void setText(const AST::Token< std::string > &text)
Definition RawText.h:34
const AST::Token< std::string > & TEXT() const
Definition RawText.h:31
A class representing a token in the Bash++ AST. Tokens store their value along with line and column i...
Definition Token.h:21
const T & getValue() const
Definition Token.h:29
Definition AccessModifier.h:8
NodeType
Definition NodeTypes.h:9