Added support for direct buses
This commit is contained in:
1 parent
7fcfb8c977
commit
c65d12a2a1
7 files changed
+335
-108
No files matched your search
+37
-24
@@ -170,7 +170,7 @@ struct ConditionNode
|
||||
std::vector<ValueNode> params;
|
||||
};
|
||||
|
||||
class ActionNode: AstNode {
|
||||
class ActionNode: public AstNode {
|
||||
public:
|
||||
enum ActionType {
|
||||
ERROR,
|
||||
@@ -182,27 +182,27 @@ public:
|
||||
};
|
||||
|
||||
|
||||
struct IfStatementNode: AstNode
|
||||
struct IfStatementNode: public AstNode
|
||||
{
|
||||
ConditionNode condition;
|
||||
ActionNode action;
|
||||
};
|
||||
|
||||
|
||||
struct RuleNode: AstNode
|
||||
struct RuleNode: public AstNode
|
||||
{
|
||||
std::vector<IfStatementNode> statements;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct EnumerationNode: AstNode
|
||||
struct EnumerationNode: public AstNode
|
||||
{
|
||||
StringNode key;
|
||||
ValueNode value;
|
||||
};
|
||||
|
||||
struct PopupNode: AstNode
|
||||
struct PopupNode: public AstNode
|
||||
{
|
||||
enum PopupType {
|
||||
AUTOMATIC,
|
||||
@@ -226,20 +226,20 @@ struct PropertyNode: public AstNode
|
||||
};
|
||||
|
||||
|
||||
struct DisplayItemNode: AstNode
|
||||
struct DisplayItemNode: public AstNode
|
||||
{
|
||||
IdentifierNode type;
|
||||
std::vector<PropertyNode> values;
|
||||
};
|
||||
|
||||
|
||||
struct DisplayNode: AstNode
|
||||
struct DisplayNode: public AstNode
|
||||
{
|
||||
std::vector<DisplayItemNode> items;
|
||||
};
|
||||
|
||||
|
||||
struct PinConnectionNode: AstNode
|
||||
struct PinConnectionNode: public AstNode
|
||||
{
|
||||
enum ConnectionType {
|
||||
CHECK_ONLY,
|
||||
@@ -251,7 +251,7 @@ struct PinConnectionNode: AstNode
|
||||
};
|
||||
|
||||
|
||||
struct PinNode: AstNode
|
||||
struct PinNode: public AstNode
|
||||
{
|
||||
enum PinType {
|
||||
IN_OUT,
|
||||
@@ -287,7 +287,7 @@ struct WireNode: public AstNode
|
||||
};
|
||||
|
||||
|
||||
struct AttributeNode: AstNode
|
||||
struct AttributeNode: public AstNode
|
||||
{
|
||||
ValueNode::ValueType type;
|
||||
IdentifierNode name;
|
||||
@@ -295,17 +295,25 @@ struct AttributeNode: AstNode
|
||||
std::optional<PopupNode> popup;
|
||||
};
|
||||
|
||||
struct ConnectionNode: AstNode
|
||||
struct ConnectionComponentNode: public AstNode
|
||||
{
|
||||
IdentifierNode component;
|
||||
IdentifierNode pin;
|
||||
IdentifierNode bus;
|
||||
std::vector<AttributeNode> attributes;
|
||||
std::vector<ValueNode> wires;
|
||||
};
|
||||
|
||||
struct ConnectionNode: public AstNode
|
||||
{
|
||||
ConnectionComponentNode first;
|
||||
std::optional<ConnectionComponentNode> second;
|
||||
|
||||
struct ComponentNode: AstNode
|
||||
IdentifierNode bus;
|
||||
std::vector<AttributeNode> attributes;
|
||||
|
||||
std::vector<ValueNode> firstWires;
|
||||
std::optional<std::vector<ValueNode>> secondWires;
|
||||
};
|
||||
|
||||
struct ComponentNode: public AstNode
|
||||
{
|
||||
enum ComponentType {
|
||||
OTHER,
|
||||
@@ -326,7 +334,7 @@ struct ComponentNode: AstNode
|
||||
};
|
||||
|
||||
|
||||
struct BusNode: AstNode
|
||||
struct BusNode: public AstNode
|
||||
{
|
||||
enum BusType {
|
||||
AUTOMATIC,
|
||||
@@ -342,7 +350,7 @@ struct BusNode: AstNode
|
||||
std::vector<WireNode> wires;
|
||||
};
|
||||
|
||||
struct LibraryNode: AstNode
|
||||
struct LibraryNode: public AstNode
|
||||
{
|
||||
std::optional<StringNode> name;
|
||||
std::optional<StringNode> libraryInfo;
|
||||
@@ -361,20 +369,20 @@ struct LibraryNode: AstNode
|
||||
// SCHEMA models
|
||||
|
||||
|
||||
struct WireInstanceNode: AstNode
|
||||
struct WireInstanceNode: public AstNode
|
||||
{
|
||||
IdentifierNode name;
|
||||
std::optional<CountNode> position;
|
||||
std::optional<DisplayNode> display;
|
||||
};
|
||||
|
||||
struct InstanceAttributeNode: AstNode
|
||||
struct InstanceAttributeNode: public AstNode
|
||||
{
|
||||
IdentifierNode name;
|
||||
ValueNode value;
|
||||
};
|
||||
|
||||
struct InstanceNode: AstNode
|
||||
struct InstanceNode: public AstNode
|
||||
{
|
||||
IdentifierNode name;
|
||||
IdentifierNode component;
|
||||
@@ -385,11 +393,16 @@ struct InstanceNode: AstNode
|
||||
std::optional<NumberNode> size;
|
||||
};
|
||||
|
||||
|
||||
struct ConnectionInstanceNode: AstNode
|
||||
{
|
||||
struct ConnectionComponentInstance {
|
||||
IdentifierNode instance;
|
||||
IdentifierNode pin;
|
||||
};
|
||||
|
||||
struct ConnectionInstanceNode: public AstNode
|
||||
{
|
||||
ConnectionComponentInstance first;
|
||||
std::optional<ConnectionComponentInstance> second;
|
||||
|
||||
IdentifierNode bus;
|
||||
std::optional<IdentifierNode> wire;
|
||||
|
||||
@@ -397,7 +410,7 @@ struct ConnectionInstanceNode: AstNode
|
||||
};
|
||||
|
||||
|
||||
struct SchemaNode: AstNode
|
||||
struct SchemaNode: public AstNode
|
||||
{
|
||||
std::optional<StringNode> source;
|
||||
|
||||
|
||||
@@ -865,24 +865,44 @@ PResult<ConnectionNode> ComdelParser::parseConnection() {
|
||||
RETURN_IF_NOT_TOKEN(TokenType::KW_CONNECTION);
|
||||
|
||||
RETURN_IF_NOT_TOKEN(TokenType::LPAREN);
|
||||
ASSIGN_OR_RETURN_IF_ERR(connection.component, parseIdentifier());
|
||||
ASSIGN_OR_RETURN_IF_ERR(connection.first.component, parseIdentifier());
|
||||
RETURN_IF_NOT_TOKEN(TokenType::DOT);
|
||||
ASSIGN_OR_RETURN_IF_ERR(connection.pin, parseIdentifier());
|
||||
ASSIGN_OR_RETURN_IF_ERR(connection.first.pin, parseIdentifier());
|
||||
RETURN_IF_NOT_TOKEN(TokenType::COMMA);
|
||||
ASSIGN_OR_RETURN_IF_ERR(connection.bus, parseIdentifier());
|
||||
|
||||
if(check(TokenType::COMMA)) {
|
||||
auto conn = ConnectionComponentNode{};
|
||||
RETURN_IF_NOT_TOKEN(TokenType::COMMA);
|
||||
RETURN_IF_NOT_TOKEN(TokenType::LPAREN);
|
||||
ASSIGN_OR_RETURN_IF_ERR(conn.component, parseIdentifier());
|
||||
RETURN_IF_NOT_TOKEN(TokenType::DOT);
|
||||
ASSIGN_OR_RETURN_IF_ERR(conn.pin, parseIdentifier());
|
||||
connection.second = conn;
|
||||
}
|
||||
|
||||
RETURN_IF_NOT_TOKEN(TokenType::RPAREN);
|
||||
|
||||
RETURN_IF_NOT_TOKEN(TokenType::LBRACE);
|
||||
|
||||
int wireCount = 0;
|
||||
|
||||
while(!check(TokenType::RBRACE)) {
|
||||
if (check(TokenType::KW_ATTRIBUTE)) {
|
||||
APPEND_OR_RETURN_IF_ERR(connection.attributes, parseAttribute());
|
||||
} else if(check(TokenType::KW_WIRES)) {
|
||||
bump();
|
||||
auto wires = parseList<ValueNode>(std::optional<TokenType>(TokenType::LBRACE), TokenType::RBRACE, std::optional<TokenType>(TokenType::COMMA), false,
|
||||
auto wires = parseList<ValueNode>(TokenType::LBRACE, TokenType::RBRACE, TokenType::COMMA, false,
|
||||
[this] { return parseConnectionWire(); });
|
||||
RETURN_IF_ERR(wires);
|
||||
connection.wires = *wires;
|
||||
if(wireCount == 0) {
|
||||
connection.firstWires = *wires;
|
||||
} else if(wireCount == 1 && connection.second.has_value()) {
|
||||
connection.secondWires = *wires;
|
||||
} else {
|
||||
return unexpected();
|
||||
}
|
||||
wireCount++;
|
||||
} else {
|
||||
return unexpected();
|
||||
}
|
||||
@@ -1158,11 +1178,21 @@ PResult<ConnectionInstanceNode> ComdelParser::parseConnectionInstance() {
|
||||
ConnectionInstanceNode connection;
|
||||
|
||||
RETURN_IF_NOT_TOKEN(TokenType::LPAREN);
|
||||
ASSIGN_OR_RETURN_IF_ERR(connection.instance, parseIdentifier());
|
||||
ASSIGN_OR_RETURN_IF_ERR(connection.first.instance, parseIdentifier());
|
||||
RETURN_IF_NOT_TOKEN(TokenType::DOT);
|
||||
ASSIGN_OR_RETURN_IF_ERR(connection.pin, parseIdentifier());
|
||||
ASSIGN_OR_RETURN_IF_ERR(connection.first.pin, parseIdentifier());
|
||||
RETURN_IF_NOT_TOKEN(TokenType::COMMA);
|
||||
ASSIGN_OR_RETURN_IF_ERR(connection.bus, parseIdentifier());
|
||||
|
||||
if(check(TokenType::COMMA)) {
|
||||
bump();
|
||||
ConnectionComponentInstance second;
|
||||
ASSIGN_OR_RETURN_IF_ERR(second.instance, parseIdentifier());
|
||||
RETURN_IF_NOT_TOKEN(TokenType::DOT);
|
||||
ASSIGN_OR_RETURN_IF_ERR(second.pin, parseIdentifier());
|
||||
connection.second = second;
|
||||
}
|
||||
|
||||
RETURN_IF_NOT_TOKEN(TokenType::RPAREN);
|
||||
|
||||
RETURN_IF_NOT_TOKEN(TokenType::LBRACE);
|
||||
|
||||
Reference in new issue
Block a user