Bash++
Bash++ compiler internal documentation
RawText.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Andrew S. Rightenburg
3 * Bash++: Bash with classes
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
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:
29 constexpr RawText() : ASTNode(AST::NodeType::RawText) {}
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, size_t 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:32
Definition RawText.h:13
std::string getEscapedText() const
Definition RawText.h:16
void appendText(const std::string &text)
Definition RawText.h:37
std::ostream & prettyPrint(std::ostream &os, size_t indentation_level=0) const override
Definition RawText.h:41
AST::Token< std::string > m_TEXT
Definition RawText.h:15
void setText(const AST::Token< std::string > &text)
Definition RawText.h:34
constexpr RawText()
Definition RawText.h:29
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:22
const T & getValue() const
Definition Token.h:37
Definition AccessModifier.h:10
NodeType
Definition NodeTypes.h:12