Added connection display
This commit is contained in:
1 parent
281926cb8b
commit
f11551fef6
9 files changed
+274
-38
No files matched your search
@@ -2,6 +2,7 @@
|
||||
#define AST_NODE_H
|
||||
|
||||
#include "token.h"
|
||||
#include "sourceerror.h"
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
@@ -173,6 +174,52 @@ struct DisplayItemNode: public AstNode
|
||||
{
|
||||
IdentifierNode type;
|
||||
std::vector<PropertyNode> values;
|
||||
|
||||
long long int asInt(std::vector<SourceError>* errors, const std::string& property, long long int _default = 0) {
|
||||
for(auto& prop: values) {
|
||||
if(prop.key.value == property) {
|
||||
if(prop.value.is(ValueNode::INT)) {
|
||||
return prop.value.asInt();
|
||||
} else {
|
||||
if(errors != nullptr) {
|
||||
errors->emplace_back(prop.value.span, "expected number");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return _default;
|
||||
}
|
||||
|
||||
std::string asIdentifier(std::vector<SourceError>* errors, const std::string& property, std::string _default = "") {
|
||||
for(auto& prop: values) {
|
||||
if(prop.key.value == property) {
|
||||
if(prop.value.is(ValueNode::IDENTIFIER)) {
|
||||
return prop.value.asIdentifier();
|
||||
} else {
|
||||
if(errors != nullptr) {
|
||||
errors->emplace_back(prop.value.span, "expected identifier");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return _default;
|
||||
}
|
||||
|
||||
|
||||
std::string asString(std::vector<SourceError>* errors, const std::string& property, std::string _default = "") {
|
||||
for(auto& prop: values) {
|
||||
if(prop.key.value == property) {
|
||||
if(prop.value.is(ValueNode::STRING)) {
|
||||
return prop.value.asString();
|
||||
} else {
|
||||
if(errors != nullptr) {
|
||||
errors->emplace_back(prop.value.span, "expected string");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return _default;
|
||||
}
|
||||
};
|
||||
|
||||
struct DisplayNode: public AstNode
|
||||
|
||||
Reference in new issue
Block a user