From 82e27dcad9e384ae68b51cb3fd4c1d9b443b1993 Mon Sep 17 00:00:00 2001 From: Eduard Date: Thu, 16 Feb 2023 17:11:27 +0100 Subject: [PATCH] Fixed Prefixing Version with Range --- liblangutil/SemVerHandler.cpp | 15 +++++++++++++++ liblangutil/SemVerHandler.h | 1 + liblangutil/Token.h | 1 + 3 files changed, 17 insertions(+) diff --git a/liblangutil/SemVerHandler.cpp b/liblangutil/SemVerHandler.cpp index 6e85e2609..1d57e4dd5 100644 --- a/liblangutil/SemVerHandler.cpp +++ b/liblangutil/SemVerHandler.cpp @@ -208,6 +208,13 @@ void SemVerMatchExpressionParser::parseMatchExpression() range.components.push_back(parseMatchComponent()); if (currentToken() == Token::Sub) { + if(containPrefixingToken()) { + solThrow( + SemVerError, + "You cannot use operators (<, <=, >=, >, ^) with verison ranges (-)." + ); + } + range.components[0].prefix = Token::GreaterThanOrEqual; nextToken(); range.components.push_back(parseMatchComponent()); @@ -324,3 +331,11 @@ void SemVerMatchExpressionParser::nextToken() ++m_pos; m_posInside = 0; } + +bool SemVerMatchExpressionParser::containPrefixingToken() const +{ + if (std::find_if(m_tokens.begin(), m_tokens.end(), TokenTraits::isPragmaOp) != m_tokens.end()) + return true; + else + return false; +} diff --git a/liblangutil/SemVerHandler.h b/liblangutil/SemVerHandler.h index cf344502e..26ddead6a 100644 --- a/liblangutil/SemVerHandler.h +++ b/liblangutil/SemVerHandler.h @@ -102,6 +102,7 @@ private: char nextChar(); Token currentToken() const; void nextToken(); + bool containPrefixingToken() const; std::vector m_tokens; std::vector m_literals; diff --git a/liblangutil/Token.h b/liblangutil/Token.h index c4907aeac..2ff4156f2 100644 --- a/liblangutil/Token.h +++ b/liblangutil/Token.h @@ -297,6 +297,7 @@ namespace TokenTraits op == Token::Add || op == Token::Mul || op == Token::Equal || op == Token::NotEqual; } constexpr bool isArithmeticOp(Token op) { return Token::Add <= op && op <= Token::Exp; } constexpr bool isCompareOp(Token op) { return Token::Equal <= op && op <= Token::GreaterThanOrEqual; } + constexpr bool isPragmaOp(Token op) { return (Token::LessThan <= op && op <= Token::GreaterThanOrEqual) || op == Token::BitXor; } constexpr bool isBitOp(Token op) { return (Token::BitOr <= op && op <= Token::BitAnd) || op == Token::BitNot; } constexpr bool isBooleanOp(Token op) { return (Token::Or <= op && op <= Token::And) || op == Token::Not; }