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