Looking pragma operators per range and not per tokens.

Add 3 invalid tests and 2 valid tests
This commit is contained in:
Eduard 2023-02-21 20:20:11 +01:00
parent 3a4a504c42
commit ed7123c8df
7 changed files with 17 additions and 12 deletions

View File

@ -208,7 +208,10 @@ void SemVerMatchExpressionParser::parseMatchExpression()
range.components.push_back(parseMatchComponent());
if (currentToken() == Token::Sub)
{
if (containPrefixingToken())
nextToken();
range.components.push_back(parseMatchComponent());
if (TokenTraits::isPragmaOp(range.components[0].prefix) || TokenTraits::isPragmaOp(range.components[1].prefix))
{
solThrow(
SemVerError,
@ -217,8 +220,6 @@ void SemVerMatchExpressionParser::parseMatchExpression()
}
range.components[0].prefix = Token::GreaterThanOrEqual;
nextToken();
range.components.push_back(parseMatchComponent());
range.components[1].prefix = Token::LessThanOrEqual;
}
else
@ -332,11 +333,3 @@ 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;
}

View File

@ -102,7 +102,6 @@ private:
char nextChar();
Token currentToken() const;
void nextToken();
bool containPrefixingToken() const;
std::vector<Token> m_tokens;
std::vector<std::string> m_literals;

View File

@ -0,0 +1,3 @@
pragma solidity <0.8.17 - 0.8.20;
// ----
// ParserError 1684: (0-33): Invalid version pragma. You cannot use operators (<, <=, >=, >, ^) with version ranges (-).

View File

@ -0,0 +1,3 @@
pragma solidity 0.8.17 - >0.8.20;
// ----
// ParserError 1684: (0-33): Invalid version pragma. You cannot use operators (<, <=, >=, >, ^) with version ranges (-).

View File

@ -0,0 +1,3 @@
pragma solidity 0.8.14 || 0.8.17 - >0.8.20;
// ----
// ParserError 1684: (0-43): Invalid version pragma. You cannot use operators (<, <=, >=, >, ^) with version ranges (-).

View File

@ -0,0 +1,2 @@
pragma solidity 0.8.17 - 0.8.20;
// ----

View File

@ -0,0 +1,2 @@
pragma solidity <0.8.15 || 0.8.17 - 0.8.20;
// ----