Added default pin connection rule

This commit is contained in:
Borna Rajkovic 2022-04-09 14:10:40 +02:00
parent dfc7bf48dc
commit 7fcfb8c977
6 changed files with 35 additions and 5 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 6.0.2, 2022-04-08T00:30:41. --> <!-- Written by QtCreator 6.0.2, 2022-04-08T23:43:55. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>

View File

@ -402,7 +402,23 @@ optional<Pin> ComdelGenerator::loadPin(PinNode node)
} }
auto connection = loadPinConnection(*node.connection); auto connection = loadPinConnection(*node.connection);
return Pin(name, type, tooltip, connection, *display); std::optional<std::vector<Value>> wiresOpt = std::nullopt;
if(node.wires.has_value()) {
auto nodeWires = node.wires.value();
std::vector<Value> wires;
for(auto &nodeWire : nodeWires) {
if(nodeWire.is(ValueNode::NIL)) {
wires.push_back(Value::fromNull());
} else if(nodeWire.is(ValueNode::INT)) {
wires.push_back(Value::fromInt(nodeWire.asInt()));
} else {
errors.emplace_back(node.span, "unknown value type");
}
}
wiresOpt = wires;
}
return Pin(name, type, tooltip, connection, *display, wiresOpt);
} }
int getIntProperty(DisplayItemNode &node, std::string property) { int getIntProperty(DisplayItemNode &node, std::string property) {

View File

@ -14,8 +14,8 @@ std::string PinConnection::getMessage() {
} }
Pin::Pin(std::string name, PinType type, std::string tooltip, PinConnection connection, Display display) Pin::Pin(std::string name, PinType type, std::string tooltip, PinConnection connection, Display display, std::optional<std::vector<Value>> wires)
: name(name), type(type), tooltip(tooltip), connection(connection), display(display) : name(name), type(type), tooltip(tooltip), connection(connection), display(display), wires(wires)
{} {}
std::string Pin::getName() { std::string Pin::getName() {
@ -33,6 +33,9 @@ Display &Pin::getDisplay() {
PinConnection &Pin::getConnection() { PinConnection &Pin::getConnection() {
return connection; return connection;
} }
std::optional<std::vector<Value>> &Pin::getWires() {
return wires;
}
} // namespace domain } // namespace domain

View File

@ -2,6 +2,7 @@
#define DOMAIN_PIN_H #define DOMAIN_PIN_H
#include "display.h" #include "display.h"
#include "value.h"
#include <string> #include <string>
@ -44,14 +45,17 @@ private:
PinConnection connection; PinConnection connection;
Display display; Display display;
std::optional<std::vector<Value>> wires;
public: public:
Pin(std::string name, PinType type, std::string tooltip, PinConnection connection, Display display); Pin(std::string name, PinType type, std::string tooltip, PinConnection connection, Display display, std::optional<std::vector<Value>> wires);
std::string getName(); std::string getName();
PinType getType(); PinType getType();
std::string getTooltip(); std::string getTooltip();
Display &getDisplay(); Display &getDisplay();
PinConnection &getConnection(); PinConnection &getConnection();
std::optional<std::vector<Value>> &getWires();
}; };
} // namespace domain } // namespace domain

View File

@ -264,6 +264,7 @@ struct PinNode: AstNode
std::optional<StringNode> tooltip; std::optional<StringNode> tooltip;
std::optional<PinConnectionNode> connection; std::optional<PinConnectionNode> connection;
std::optional<DisplayNode> display; std::optional<DisplayNode> display;
std::optional<std::vector<ValueNode>> wires;
}; };

View File

@ -634,6 +634,12 @@ PResult<PinNode> ComdelParser::parsePin() {
ASSIGN_OR_RETURN_IF_ERR(pin.display, parseDisplay()); ASSIGN_OR_RETURN_IF_ERR(pin.display, parseDisplay());
} else if (check(TokenType::KW_CONNECTION)) { } else if (check(TokenType::KW_CONNECTION)) {
ASSIGN_OR_RETURN_IF_ERR(pin.connection, parsePinConnection()); ASSIGN_OR_RETURN_IF_ERR(pin.connection, parsePinConnection());
} else if (check(TokenType::KW_WIRES)){
bump();
auto wires = parseList<ValueNode>(std::optional<TokenType>(TokenType::LBRACE), TokenType::RBRACE, std::optional<TokenType>(TokenType::COMMA), false,
[this] { return parseConnectionWire(); });
RETURN_IF_ERR(wires);
pin.wires = *wires;
} else { } else {
return unexpected(); return unexpected();
} }