Bash++
Bash++ compiler internal documentation
StringType.h
Go to the documentation of this file.
1
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:
32 void addText(const AST::Token<std::string>& text) {
33 auto lastChild = getLastChild();
34 if (lastChild && lastChild->getType() == AST::NodeType::RawText) {
35 std::dynamic_pointer_cast<AST::RawText>(lastChild)->appendText(text);
36 } else {
37 auto rawTextNode = std::make_shared<AST::RawText>();
38 rawTextNode->setText(text);
39 addChild(rawTextNode);
40 }
41 }
42
43 void addText(const std::string& text) {
44 auto lastChild = getLastChild();
45 if (lastChild && lastChild->getType() == AST::NodeType::RawText) {
46 std::dynamic_pointer_cast<AST::RawText>(lastChild)->appendText(text);
47 } else {
48 auto rawTextNode = std::make_shared<AST::RawText>();
49 AST::Token<std::string> token(text, UINT32_MAX, UINT32_MAX); // Line and column unknown
50 rawTextNode->setText(token);
51 addChild(rawTextNode);
52 }
53 }
54
55 std::ostream& prettyPrint(std::ostream& os, int indentation_level = 0) const = 0; // Pure virtual, to prevent direct instantiation
56};
57
58} // namespace AST
The base class for all non-terminal nodes in the Bash++ AST. Each ASTNode contains information about ...
Definition ASTNode.h:29
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
std::ostream & prettyPrint(std::ostream &os, int indentation_level=0) const =0
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:32
void addText(const std::string &text)
Definition StringType.h:43
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:9