Bash++
Bash++ compiler internal documentation
StringType.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#include <AST/Nodes/RawText.h>
11#include <cstdint>
12
13namespace AST {
14
23class StringType : public ASTNode {
24 public:
25 constexpr explicit StringType(AST::NodeType type) : ASTNode(type) {}
33 void addText(const AST::Token<std::string>& text) {
34 auto lastChild = getLastChild();
35 if (lastChild && lastChild->getType() == AST::NodeType::RawText) {
36 std::static_pointer_cast<AST::RawText>(lastChild)->appendText(text);
37 } else {
38 auto rawTextNode = std::make_shared<AST::RawText>();
39 rawTextNode->setText(text);
40 addChild(rawTextNode);
41 }
42 }
43
44 void addText(const std::string& text) {
45 auto lastChild = getLastChild();
46 if (lastChild && lastChild->getType() == AST::NodeType::RawText) {
47 std::static_pointer_cast<AST::RawText>(lastChild)->appendText(text);
48 } else {
49 auto rawTextNode = std::make_shared<AST::RawText>();
50 AST::Token<std::string> token(text, UINT32_MAX, UINT32_MAX); // Line and column unknown
51 rawTextNode->setText(token);
52 addChild(rawTextNode);
53 }
54 }
55
56 std::ostream& prettyPrint(std::ostream& os, size_t indentation_level = 0) const override = 0; // Pure virtual, to prevent direct instantiation
57};
58
59} // namespace AST
The base class for all non-terminal nodes in the Bash++ AST. Each ASTNode contains information about ...
Definition ASTNode.h:28
std::shared_ptr< ASTNode > getLastChild() const
Definition ASTNode.cpp:128
void addChild(const std::shared_ptr< ASTNode > &child)
Add a child node to this AST node. This function also:
Definition ASTNode.cpp:21
Base class for string-type nodes in the AST.
Definition StringType.h:23
void addText(const AST::Token< std::string > &text)
Adds text to the string, either by appending to the last RawText child or creating a new one....
Definition StringType.h:33
void addText(const std::string &text)
Definition StringType.h:44
std::ostream & prettyPrint(std::ostream &os, size_t indentation_level=0) const override=0
constexpr StringType(AST::NodeType type)
Definition StringType.h:25
A class representing a token in the Bash++ AST. Tokens store their value along with line and column i...
Definition Token.h:22
Definition AccessModifier.h:10
NodeType
Definition NodeTypes.h:12