Bash++
Bash++ compiler internal documentation
StringType.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <AST/ASTNode.h>
9#include <AST/Nodes/RawText.h>
10#include <cstdint>
11
12namespace AST {
13
22class StringType : public ASTNode {
23 public:
31 void addText(const AST::Token<std::string>& text) {
32 auto lastChild = getLastChild();
33 if (lastChild && lastChild->getType() == AST::NodeType::RawText) {
34 std::dynamic_pointer_cast<AST::RawText>(lastChild)->appendText(text);
35 } else {
36 auto rawTextNode = std::make_shared<AST::RawText>();
37 rawTextNode->setText(text);
38 addChild(rawTextNode);
39 }
40 }
41
42 void addText(const std::string& text) {
43 auto lastChild = getLastChild();
44 if (lastChild && lastChild->getType() == AST::NodeType::RawText) {
45 std::dynamic_pointer_cast<AST::RawText>(lastChild)->appendText(text);
46 } else {
47 auto rawTextNode = std::make_shared<AST::RawText>();
48 AST::Token<std::string> token(text, UINT32_MAX, UINT32_MAX); // Line and column unknown
49 rawTextNode->setText(token);
50 addChild(rawTextNode);
51 }
52 }
53
54 std::ostream& prettyPrint(std::ostream& os, int indentation_level = 0) const = 0; // Pure virtual, to prevent direct instantiation
55};
56
57} // 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:127
void addChild(const std::shared_ptr< ASTNode > &child)
Add a child node to this AST node. This function also:
Definition ASTNode.cpp:20
Base class for string-type nodes in the AST.
Definition StringType.h:22
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:31
void addText(const std::string &text)
Definition StringType.h:42
A class representing a token in the Bash++ AST. Tokens store their value along with line and column i...
Definition Token.h:21
Definition AccessModifier.h:8