Added support for integers and null to connections
This commit is contained in:
1 parent
9bd68ecf23
commit
dfc7bf48dc
10 files changed
+95
-39
No files matched your search
@@ -74,7 +74,8 @@ public:
|
||||
STRING,
|
||||
BOOL,
|
||||
WIRE,
|
||||
IDENTIFIER
|
||||
IDENTIFIER,
|
||||
NIL,
|
||||
};
|
||||
|
||||
|
||||
@@ -148,6 +149,12 @@ public:
|
||||
return value;
|
||||
}
|
||||
|
||||
static ValueNode ofNull() {
|
||||
ValueNode value;
|
||||
value.type = NIL;
|
||||
return value;
|
||||
}
|
||||
|
||||
static ValueNode ofWire(std::string _value) {
|
||||
ValueNode value;
|
||||
value.type = WIRE;
|
||||
@@ -293,7 +300,7 @@ struct ConnectionNode: AstNode
|
||||
IdentifierNode pin;
|
||||
IdentifierNode bus;
|
||||
std::vector<AttributeNode> attributes;
|
||||
std::vector<IdentifierNode> wires;
|
||||
std::vector<ValueNode> wires;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ inline bool identifierContinue(char ch) {
|
||||
}
|
||||
|
||||
inline bool numberStart(char ch) {
|
||||
return isdigit(ch);
|
||||
return isdigit(ch) || ch == '-';
|
||||
}
|
||||
|
||||
inline bool isWhitespace(char ch) {
|
||||
@@ -64,10 +64,10 @@ LexerResult ComdelLexer::tokenize() {
|
||||
|
||||
tokenType = from_token(text, tokenType.value());
|
||||
|
||||
tokens.push_back(Token(*tokenType, Span(tokenBegin, position), text));
|
||||
tokens.emplace_back(*tokenType, Span(tokenBegin, position), text);
|
||||
}
|
||||
|
||||
tokens.push_back(Token( TokenType::END_OF_FILE, Span(position), ""));
|
||||
tokens.emplace_back( TokenType::END_OF_FILE, Span(position), "");
|
||||
|
||||
return LexerResult { tokens, errors };
|
||||
}
|
||||
@@ -251,6 +251,9 @@ PResult<TokenType> ComdelLexer::nextTokenType() {
|
||||
}
|
||||
else if (numberStart(ch))
|
||||
{
|
||||
if(ch == '-') {
|
||||
bump();
|
||||
}
|
||||
unsigned takenDigits;
|
||||
Radix radix = takeRadix();
|
||||
takenDigits = takeNumberInRadix(radix);
|
||||
@@ -393,15 +396,6 @@ PResult<TokenType> ComdelLexer::nextTokenType() {
|
||||
bump();
|
||||
return TokenType::EQUALS;
|
||||
}
|
||||
else if (ch == '<')
|
||||
{
|
||||
bump();
|
||||
return TokenType::LT;
|
||||
}
|
||||
else if (ch == '>')
|
||||
{
|
||||
return TokenType::GT;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream message;
|
||||
|
||||
@@ -711,8 +711,10 @@ PResult<AttributeNode> ComdelParser::parseAttribute() {
|
||||
|
||||
if(attribute.type == ValueNode::BOOL) {
|
||||
if(check(TokenType::TRUE)) {
|
||||
bump();
|
||||
attribute.defaultValue = ValueNode::ofBool(true);
|
||||
} else if(check(TokenType::FALSE)) {
|
||||
bump();
|
||||
attribute.defaultValue = ValueNode::ofBool(false);
|
||||
} else {
|
||||
return unexpected();
|
||||
@@ -742,7 +744,10 @@ PResult<AttributeNode> ComdelParser::parseAttribute() {
|
||||
if(check(TokenType::IDENTIFIER)) {
|
||||
auto identifier = parseIdentifier();
|
||||
attribute.defaultValue = ValueNode::ofWire(identifier->value);
|
||||
} else {
|
||||
} else if(check(TokenType::NIL)) {
|
||||
bump();
|
||||
attribute.defaultValue = ValueNode::ofNull();
|
||||
} else {
|
||||
return unexpected();
|
||||
}
|
||||
}
|
||||
@@ -868,8 +873,8 @@ PResult<ConnectionNode> ComdelParser::parseConnection() {
|
||||
APPEND_OR_RETURN_IF_ERR(connection.attributes, parseAttribute());
|
||||
} else if(check(TokenType::KW_WIRES)) {
|
||||
bump();
|
||||
auto wires = parseList<IdentifierNode>(std::optional<TokenType>(TokenType::LBRACE), TokenType::RBRACE, std::optional<TokenType>(TokenType::COMMA), false,
|
||||
[this] { return parseIdentifier(); });
|
||||
auto wires = parseList<ValueNode>(std::optional<TokenType>(TokenType::LBRACE), TokenType::RBRACE, std::optional<TokenType>(TokenType::COMMA), false,
|
||||
[this] { return parseConnectionWire(); });
|
||||
RETURN_IF_ERR(wires);
|
||||
connection.wires = *wires;
|
||||
} else {
|
||||
@@ -973,9 +978,14 @@ PResult<ValueNode> ComdelParser::parseValue() {
|
||||
} else if(check(TokenType::NUMBER)) {
|
||||
value = ValueNode::ofInt(parseNumber()->value);
|
||||
} else if(check(TokenType::TRUE)) {
|
||||
bump();
|
||||
value = ValueNode::ofBool(true);
|
||||
} else if(check(TokenType::FALSE)) {
|
||||
bump();
|
||||
value = ValueNode::ofBool(false);
|
||||
} else if(check(TokenType::NIL)) {
|
||||
bump();
|
||||
value = ValueNode::ofNull();
|
||||
} else {
|
||||
return unexpected();
|
||||
}
|
||||
@@ -1167,3 +1177,16 @@ PResult<ConnectionInstanceNode> ComdelParser::parseConnectionInstance() {
|
||||
return spanner(connection);
|
||||
}
|
||||
|
||||
PResult<ValueNode> ComdelParser::parseConnectionWire() {
|
||||
if(check(TokenType::NUMBER)) {
|
||||
return ValueNode::ofInt(parseNumber()->value);
|
||||
} else if(check(TokenType::NIL)) {
|
||||
bump();
|
||||
return ValueNode::ofNull();
|
||||
} else if(check(TokenType::IDENTIFIER)) {
|
||||
return ValueNode::ofIdentifier(parseIdentifier()->value);
|
||||
} else {
|
||||
return unexpected();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ private:
|
||||
PResult<PropertyNode> parseProperty(std::optional<TokenType> valueType);
|
||||
PResult<EnumerationNode> parseEnumeration();
|
||||
|
||||
PResult<ValueNode> parseConnectionWire();
|
||||
PResult<ComponentNode> parseComponent();
|
||||
PResult<AddressSpaceNode> parseAddress();
|
||||
PResult<PinNode> parsePin();
|
||||
@@ -84,6 +85,7 @@ private:
|
||||
PResult<IfStatementNode> parseIfStatement();
|
||||
PResult<ValueNode> parseValue();
|
||||
|
||||
|
||||
PResult<WireInstanceNode> parseWireInstance();
|
||||
PResult<CountNode> parsePosition();
|
||||
PResult<InstanceNode> parseInstance();
|
||||
|
||||
@@ -65,6 +65,9 @@ enum class TokenType {
|
||||
TRUE,
|
||||
FALSE,
|
||||
|
||||
// NULL
|
||||
NIL,
|
||||
|
||||
// KEYWORDS
|
||||
KW_NAME,
|
||||
KW_INFO,
|
||||
|
||||
@@ -76,6 +76,7 @@ TokenTables::TokenTables() {
|
||||
add( TokenType::ELSE, "else", TOKENIZABLE),
|
||||
|
||||
add( TokenType::DEFAULT, "default", TOKENIZABLE),
|
||||
add( TokenType::NIL, "null", TOKENIZABLE),
|
||||
|
||||
// all keywords
|
||||
add( TokenType::KW_NAME, "@name", TOKENIZABLE),
|
||||
|
||||
Reference in new issue
Block a user