Updated support for single automatic bus

This commit is contained in:
Borna Rajković committed 2022-05-08 14:50:56 +02:00
1 parent 9ff6633777
commit fb8aafb2a9
9 files changed
+152 -39

No files matched your search

+4 -3
View File
@@ -181,8 +181,8 @@ struct DisplayNode: public AstNode
struct PinConnectionNode: public AstNode
{
enum ConnectionType {
CHECK_ONLY,
AUTOMATICALLY
REQUIRED,
OPTIONAL
};
StringNode message;
@@ -273,7 +273,8 @@ struct BusNode: public AstNode
{
enum BusType {
AUTOMATIC,
REGULAR
REGULAR,
SINGLE_AUTOMATIC
};
EnumNode<BusType> type;
+23 -13
View File
@@ -465,6 +465,7 @@ PResult<ComponentNode> ComdelParser::parseComponent()
APPEND_OR_SET_ERR(component.rules, parseRule());
} else {
err = unexpected();
bump();
}
if(!err.has_value()) {
errors.push_back(err.error());
@@ -583,6 +584,7 @@ PResult<BusNode> ComdelParser::parseBus() {
RETURN_IF_NOT_TOKEN(TokenType::RBRACE);
} else {
err = unexpected();
bump();
}
if(!err.has_value()) {
errors.push_back(err.error());
@@ -607,11 +609,13 @@ PResult<EnumNode<BusNode::BusType>> ComdelParser::parseBusType() {
type = EnumNode(BusNode::AUTOMATIC);
} else if(tokenType.value().value == "regular") {
type = EnumNode(BusNode::REGULAR);
} else if(tokenType.value().value == "singleAutomatic") {
type = EnumNode(BusNode::SINGLE_AUTOMATIC);
} else {
type = PError(SourceError{current().span, "expected 'automatic' or 'regular'"});
type = PError(SourceError{current().span, "expected 'automatic', 'singleAutomatic' or 'regular'"});
}
} else {
type = PError(SourceError{current().span, "expected 'automatic' or 'regular'"});
type = PError(SourceError{current().span, "expected 'automatic', 'singleAutomatic' or 'regular'"});
}
return type;
}
@@ -728,6 +732,7 @@ PResult<PinNode> ComdelParser::parsePin() {
pin.wires = *wires;
} else {
err = unexpected();
bump();
}
if(!err.has_value()) {
errors.push_back(err.error());
@@ -771,15 +776,15 @@ PResult<EnumNode<PinConnectionNode::ConnectionType>> ComdelParser::parseConnecti
if(check(TokenType::IDENTIFIER)) {
auto identifier = parseIdentifier();
if(identifier.value().value == "check_only") {
type = EnumNode(PinConnectionNode::CHECK_ONLY);
} else if(identifier.value().value == "automatically") {
type = EnumNode(PinConnectionNode::AUTOMATICALLY);
if(identifier.value().value == "required") {
type = EnumNode(PinConnectionNode::REQUIRED);
} else if(identifier.value().value == "optional") {
type = EnumNode(PinConnectionNode::OPTIONAL);
} else {
return PError(SourceError{current().span, "expected identifiers 'check_only' or 'automatically'"});
return PError(SourceError{current().span, "expected connection type 'required' or 'optional'"});
}
} else {
return PError(SourceError{current().span, "expected identifiers 'check_only' or 'automatically'"});
return PError(SourceError{current().span, "expected connection type 'required' or 'optional'"});
}
return spanner(type);
@@ -948,6 +953,7 @@ PResult<PopupNode> ComdelParser::parsePopup() {
);
} else {
err = unexpected();
bump();
}
if(!err.has_value()) {
errors.push_back(err.error());
@@ -965,7 +971,7 @@ PResult<PopupNode> ComdelParser::parsePopup() {
/****************************************************************************
*
* ConnectionNode := "@connection (" + COMPONENT + "." + PIN + "," + BUS) {" + CONNECTION + "}"
* ConnectionNode := "@connection (" + COMPONENT + "." + PIN + "," + BUS [ + "," + COMPONENT2 + "." + "PIN2"] + ") {" + CONNECTION + "}"
*
****************************************************************************/
PResult<ConnectionNode> ComdelParser::parseConnection() {
@@ -984,7 +990,6 @@ PResult<ConnectionNode> ComdelParser::parseConnection() {
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());
@@ -1016,6 +1021,7 @@ PResult<ConnectionNode> ComdelParser::parseConnection() {
wireCount++;
} else {
err = unexpected();
bump();
}
if(!err.has_value()) {
errors.push_back(err.error());
@@ -1251,6 +1257,7 @@ PResult<InstanceNode> ComdelParser::parseInstance() {
instance.size = *number;
} else {
err = unexpected();
bump();
}
if(!err.has_value()) {
errors.push_back(err.error());
@@ -1324,13 +1331,16 @@ PResult<ConnectionInstanceNode> ComdelParser::parseConnectionInstance() {
}
PResult<ValueNode> ComdelParser::parseConnectionWire() {
auto spanner = getSpanner();
if(check(TokenType::NUMBER)) {
return ValueNode::ofInt(parseNumber()->value);
return spanner(ValueNode::ofInt(parseNumber()->value));
} else if(check(TokenType::NIL)) {
bump();
return ValueNode::ofNull();
return spanner(ValueNode::ofNull());
} else if(check(TokenType::STRING)) {
return spanner(ValueNode::ofString(parseString()->value));
} else if(check(TokenType::IDENTIFIER)) {
return ValueNode::ofIdentifier(parseIdentifier()->value);
return spanner(ValueNode::ofIdentifier(parseIdentifier()->value));
} else {
return unexpected();
}