From 7fcfb8c977eedfe35beb31fff84f803a747ab190 Mon Sep 17 00:00:00 2001 From: Borna Rajkovic Date: Sat, 9 Apr 2022 14:10:40 +0200 Subject: [PATCH] Added default pin connection rule --- SchemeEditor.pro.user | 2 +- comdel/domain/comdelgenerator.cpp | 18 +++++++++++++++++- comdel/domain/pin.cpp | 7 +++++-- comdel/domain/pin.h | 6 +++++- comdel/parser/astnode.h | 1 + comdel/parser/comdelparser.cpp | 6 ++++++ 6 files changed, 35 insertions(+), 5 deletions(-) diff --git a/SchemeEditor.pro.user b/SchemeEditor.pro.user index bbef054..1b72d71 100644 --- a/SchemeEditor.pro.user +++ b/SchemeEditor.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/comdel/domain/comdelgenerator.cpp b/comdel/domain/comdelgenerator.cpp index 8c57d06..f42d95b 100644 --- a/comdel/domain/comdelgenerator.cpp +++ b/comdel/domain/comdelgenerator.cpp @@ -402,7 +402,23 @@ optional ComdelGenerator::loadPin(PinNode node) } auto connection = loadPinConnection(*node.connection); - return Pin(name, type, tooltip, connection, *display); + std::optional> wiresOpt = std::nullopt; + if(node.wires.has_value()) { + auto nodeWires = node.wires.value(); + std::vector 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) { diff --git a/comdel/domain/pin.cpp b/comdel/domain/pin.cpp index 15046e1..e27e692 100644 --- a/comdel/domain/pin.cpp +++ b/comdel/domain/pin.cpp @@ -14,8 +14,8 @@ std::string PinConnection::getMessage() { } -Pin::Pin(std::string name, PinType type, std::string tooltip, PinConnection connection, Display display) - : name(name), type(type), tooltip(tooltip), connection(connection), display(display) +Pin::Pin(std::string name, PinType type, std::string tooltip, PinConnection connection, Display display, std::optional> wires) + : name(name), type(type), tooltip(tooltip), connection(connection), display(display), wires(wires) {} std::string Pin::getName() { @@ -33,6 +33,9 @@ Display &Pin::getDisplay() { PinConnection &Pin::getConnection() { return connection; } +std::optional> &Pin::getWires() { + return wires; +} } // namespace domain diff --git a/comdel/domain/pin.h b/comdel/domain/pin.h index 4c28245..2f86449 100644 --- a/comdel/domain/pin.h +++ b/comdel/domain/pin.h @@ -2,6 +2,7 @@ #define DOMAIN_PIN_H #include "display.h" +#include "value.h" #include @@ -44,14 +45,17 @@ private: PinConnection connection; Display display; + std::optional> wires; + 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> wires); std::string getName(); PinType getType(); std::string getTooltip(); Display &getDisplay(); PinConnection &getConnection(); + std::optional> &getWires(); }; } // namespace domain diff --git a/comdel/parser/astnode.h b/comdel/parser/astnode.h index 48950bf..619fb9f 100644 --- a/comdel/parser/astnode.h +++ b/comdel/parser/astnode.h @@ -264,6 +264,7 @@ struct PinNode: AstNode std::optional tooltip; std::optional connection; std::optional display; + std::optional> wires; }; diff --git a/comdel/parser/comdelparser.cpp b/comdel/parser/comdelparser.cpp index 23129b9..8ac38be 100644 --- a/comdel/parser/comdelparser.cpp +++ b/comdel/parser/comdelparser.cpp @@ -634,6 +634,12 @@ PResult ComdelParser::parsePin() { ASSIGN_OR_RETURN_IF_ERR(pin.display, parseDisplay()); } else if (check(TokenType::KW_CONNECTION)) { ASSIGN_OR_RETURN_IF_ERR(pin.connection, parsePinConnection()); + } else if (check(TokenType::KW_WIRES)){ + bump(); + auto wires = parseList(std::optional(TokenType::LBRACE), TokenType::RBRACE, std::optional(TokenType::COMMA), false, + [this] { return parseConnectionWire(); }); + RETURN_IF_ERR(wires); + pin.wires = *wires; } else { return unexpected(); }