21 std::optional<std::string>
label;
33 label = std::move(n.label);
43 if(label.has_value()) {
58 std::string out =
"[";
60 for(
const auto& c : this->
children) {
61 out += c.string() +
" ";
65 out.erase(out.length()-1);
77 if (c ==
'(') nopen++;
78 else if(c ==
')') nopen--;
82 CERR "*** Bad parentheses in " << s
ENDL;
87 std::string
trim(std::string x) {
94 while(x[x.size()-1] ==
' ') {
95 x.erase(x.size()-1, 1);
103 std::vector<std::string> out;
107 if(c ==
'(' or c ==
')' or c ==
' ') {
111 if(x !=
"" and x !=
" ") {
118 out.push_back(std::string(1,c));
127 out.push_back(
trim(x));
152 assert(tok.size() > 0);
155 while(not tok.empty()) {
158 if(x ==
"(") out.push_back(
__parse(tok));
159 else if(x ==
")")
break;
174 if(tok.size() == 1) {
178 if(tok.front() ==
"(") {
void assert_check_parens(const std::string &s)
Definition: SExpression.h:74
SExpNode()
Definition: SExpression.h:23
std::vector< SExpNode > children
Definition: BaseNode.h:23
This is a general tree class, which we are adding because there are currently at least 3 different tr...
virtual std::string string() const
Definition: SExpression.h:51
Definition: SExpression.h:20
SExpNode __parse(std::vector< std::string > &tok)
Recursive parsing of S-expressions. Not high qualtiy. Basically, if we get ((A...) B...
Definition: SExpression.h:150
Definition: BaseNode.h:20
SExpNode(const std::string &s)
Definition: SExpression.h:24
std::string get_label()
Definition: SExpression.h:42
#define CERR
Definition: IO.h:23
SExpNode parse(std::vector< std::string > &tok)
Wrapper to parse to remove outer (...)
Definition: SExpression.h:172
std::vector< std::string > tokenize(std::string s)
Definition: SExpression.h:101
std::optional< std::string > label
Definition: SExpression.h:21
SExpNode(const SExpNode &s)
Definition: SExpression.h:25
#define ENDL
Definition: IO.h:21
virtual bool operator==(const SExpNode &n) const override
Definition: SExpression.h:38
Definition: SExpression.h:10
SExpNode & operator=(const SExpNode &n)
Definition: SExpression.h:27
std::string trim(std::string x)
Definition: SExpression.h:87
SExpNode & operator=(const SExpNode &&n)
Definition: SExpression.h:32
std::string pop_front(std::vector< std::string > &q)
Definition: SExpression.h:134
size_t nchildren() const
Definition: BaseNode.h:208