diff --git a/comdel/domain/comdelgenerator.cpp b/comdel/domain/comdelgenerator.cpp index 8c94cc6..8c57d06 100644 --- a/comdel/domain/comdelgenerator.cpp +++ b/comdel/domain/comdelgenerator.cpp @@ -58,6 +58,8 @@ Value toType(ValueNode node) { return Value::fromInt(node.asInt()); } else if(node.getType() == ValueNode::STRING) { return Value::fromString(node.asString()); + } else if(node.getType() == ValueNode::NIL) { + return Value::fromNull(); } return Value::fromReference(node.asIdentifier(), Value::UNDEFINED); } @@ -228,12 +230,12 @@ std::optional ComdelGenerator::loadConnection(ConnectionNode node) auto componentInstance = getComponentPin(component, pin); if(!componentInstance) { - errors.push_back(SourceError(node.span, "pin does not exist")); + errors.emplace_back(node.span, "pin does not exist"); } auto busInstance = getBus(bus); if(!busInstance) { - errors.push_back(SourceError(node.span, "bus does not exist")); + errors.emplace_back(node.span, "bus does not exist"); } std::set wireNames; @@ -258,12 +260,20 @@ std::optional ComdelGenerator::loadConnection(ConnectionNode node) std::vector wires; for(uint i=0; i ComdelGenerator::loadPopup(PopupNode node, std::string name std::vector enumeration; if(node.enumerated) { for(uint i=0; i attributes; - std::vector wires; + std::vector wires; }; diff --git a/comdel/parser/comdellexer.cpp b/comdel/parser/comdellexer.cpp index 6dd5311..e4c2032 100644 --- a/comdel/parser/comdellexer.cpp +++ b/comdel/parser/comdellexer.cpp @@ -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 ComdelLexer::nextTokenType() { } else if (numberStart(ch)) { + if(ch == '-') { + bump(); + } unsigned takenDigits; Radix radix = takeRadix(); takenDigits = takeNumberInRadix(radix); @@ -393,15 +396,6 @@ PResult ComdelLexer::nextTokenType() { bump(); return TokenType::EQUALS; } - else if (ch == '<') - { - bump(); - return TokenType::LT; - } - else if (ch == '>') - { - return TokenType::GT; - } else { std::stringstream message; diff --git a/comdel/parser/comdelparser.cpp b/comdel/parser/comdelparser.cpp index 1741e04..23129b9 100644 --- a/comdel/parser/comdelparser.cpp +++ b/comdel/parser/comdelparser.cpp @@ -711,8 +711,10 @@ PResult 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 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 ComdelParser::parseConnection() { APPEND_OR_RETURN_IF_ERR(connection.attributes, parseAttribute()); } else if(check(TokenType::KW_WIRES)) { bump(); - auto wires = parseList(std::optional(TokenType::LBRACE), TokenType::RBRACE, std::optional(TokenType::COMMA), false, - [this] { return parseIdentifier(); }); + auto wires = parseList(std::optional(TokenType::LBRACE), TokenType::RBRACE, std::optional(TokenType::COMMA), false, + [this] { return parseConnectionWire(); }); RETURN_IF_ERR(wires); connection.wires = *wires; } else { @@ -973,9 +978,14 @@ PResult 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 ComdelParser::parseConnectionInstance() { return spanner(connection); } +PResult 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(); + } +} + diff --git a/comdel/parser/comdelparser.h b/comdel/parser/comdelparser.h index 898219f..25f4d3f 100644 --- a/comdel/parser/comdelparser.h +++ b/comdel/parser/comdelparser.h @@ -69,6 +69,7 @@ private: PResult parseProperty(std::optional valueType); PResult parseEnumeration(); + PResult parseConnectionWire(); PResult parseComponent(); PResult parseAddress(); PResult parsePin(); @@ -84,6 +85,7 @@ private: PResult parseIfStatement(); PResult parseValue(); + PResult parseWireInstance(); PResult parsePosition(); PResult parseInstance(); diff --git a/comdel/parser/token.h b/comdel/parser/token.h index 9b8f952..03023e7 100644 --- a/comdel/parser/token.h +++ b/comdel/parser/token.h @@ -65,6 +65,9 @@ enum class TokenType { TRUE, FALSE, + // NULL + NIL, + // KEYWORDS KW_NAME, KW_INFO, diff --git a/comdel/parser/tokenstype.cpp b/comdel/parser/tokenstype.cpp index 524b512..458b4eb 100644 --- a/comdel/parser/tokenstype.cpp +++ b/comdel/parser/tokenstype.cpp @@ -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), diff --git a/mainwindow.cpp b/mainwindow.cpp index c556403..1c75f7f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -63,14 +63,14 @@ void MainWindow::onTestModal() { library = generator.loadLibrary(*schemaNode->library); for (auto& error : generator.getErrors()) { - parseContext.formatError(error, std::cout, "ERROR: "); + parseContext.formatError(error, std::cout, "GENERATOR ERROR: "); } if(library) { schema = generator.loadSchema(*schemaNode, *library); for (auto& error : generator.getErrors()) { - parseContext.formatError(error, std::cout, "ERROR: "); + parseContext.formatError(error, std::cout, "LIBRARY ERROR: "); } }