mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Got it working exactly like you wanted ;)
This commit is contained in:
parent
6395168371
commit
6c61e28dc2
@ -44,7 +44,24 @@ int ParserBase::endPosition() const
|
|||||||
|
|
||||||
void ParserBase::expectToken(Token::Value _value)
|
void ParserBase::expectToken(Token::Value _value)
|
||||||
{
|
{
|
||||||
if (m_scanner->currentToken() != _value)
|
Token::Value tok = m_scanner->currentToken();
|
||||||
|
if (tok != _value)
|
||||||
|
{
|
||||||
|
if (Token::isElementaryTypeName(tok)) //for the sake of accuracy in reporting
|
||||||
|
{
|
||||||
|
unsigned firstSize;
|
||||||
|
unsigned secondSize;
|
||||||
|
tie(firstSize, secondSize) = m_scanner->currentTokenInfo();
|
||||||
|
ElementaryTypeNameToken elemTypeName(tok, firstSize, secondSize);
|
||||||
|
fatalParserError(
|
||||||
|
string("Expected token ") +
|
||||||
|
string(Token::name(_value)) +
|
||||||
|
string(" got '") +
|
||||||
|
elemTypeName.toString() +
|
||||||
|
string("'")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
fatalParserError(
|
fatalParserError(
|
||||||
string("Expected token ") +
|
string("Expected token ") +
|
||||||
string(Token::name(_value)) +
|
string(Token::name(_value)) +
|
||||||
@ -52,6 +69,7 @@ void ParserBase::expectToken(Token::Value _value)
|
|||||||
string(Token::name(m_scanner->currentToken())) +
|
string(Token::name(m_scanner->currentToken())) +
|
||||||
string("'")
|
string("'")
|
||||||
);
|
);
|
||||||
|
}
|
||||||
m_scanner->next();
|
m_scanner->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,23 +77,54 @@ Token::Value ParserBase::expectAssignmentOperator()
|
|||||||
{
|
{
|
||||||
Token::Value op = m_scanner->currentToken();
|
Token::Value op = m_scanner->currentToken();
|
||||||
if (!Token::isAssignmentOp(op))
|
if (!Token::isAssignmentOp(op))
|
||||||
|
{
|
||||||
|
if (Token::isElementaryTypeName(op)) //for the sake of accuracy in reporting
|
||||||
|
{
|
||||||
|
unsigned firstSize;
|
||||||
|
unsigned secondSize;
|
||||||
|
tie(firstSize, secondSize) = m_scanner->currentTokenInfo();
|
||||||
|
ElementaryTypeNameToken elemTypeName(op, firstSize, secondSize);
|
||||||
|
fatalParserError(
|
||||||
|
string("Expected assignment operator, got '") +
|
||||||
|
elemTypeName.toString() +
|
||||||
|
string("'")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
fatalParserError(
|
fatalParserError(
|
||||||
string("Expected assignment operator, got '") +
|
string("Expected assignment operator, got '") +
|
||||||
string(Token::name(m_scanner->currentToken())) +
|
string(Token::name(m_scanner->currentToken())) +
|
||||||
string("'")
|
string("'")
|
||||||
);
|
);
|
||||||
|
}
|
||||||
m_scanner->next();
|
m_scanner->next();
|
||||||
return op;
|
return op;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTPointer<ASTString> ParserBase::expectIdentifierToken()
|
ASTPointer<ASTString> ParserBase::expectIdentifierToken()
|
||||||
{
|
{
|
||||||
if (m_scanner->currentToken() != Token::Identifier)
|
Token::Value id = m_scanner->currentToken();
|
||||||
|
if (id != Token::Identifier)
|
||||||
|
{
|
||||||
|
if (Token::isElementaryTypeName(id)) //for the sake of accuracy in reporting
|
||||||
|
{
|
||||||
|
unsigned firstSize;
|
||||||
|
unsigned secondSize;
|
||||||
|
tie(firstSize, secondSize) = m_scanner->currentTokenInfo();
|
||||||
|
ElementaryTypeNameToken elemTypeName(id, firstSize, secondSize);
|
||||||
fatalParserError(
|
fatalParserError(
|
||||||
string("Expected identifier, got '") +
|
string("Expected identifier, got '") +
|
||||||
string(Token::name(m_scanner->currentToken())) +
|
elemTypeName.toString() +
|
||||||
string("'")
|
string("'")
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
fatalParserError(
|
||||||
|
string("Expected identifier, got '") +
|
||||||
|
string(Token::name(id)) +
|
||||||
|
string("'")
|
||||||
|
);
|
||||||
|
}
|
||||||
return getLiteralAndAdvance();
|
return getLiteralAndAdvance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,18 +190,18 @@ namespace solidity
|
|||||||
K(After, "after", 0) \
|
K(After, "after", 0) \
|
||||||
/* type keywords*/ \
|
/* type keywords*/ \
|
||||||
K(Int, "int", 0) \
|
K(Int, "int", 0) \
|
||||||
T(IntM, "intM", 0) \
|
|
||||||
K(UInt, "uint", 0) \
|
K(UInt, "uint", 0) \
|
||||||
T(UIntM, "uintM", 0) \
|
|
||||||
K(Bytes, "bytes", 0) \
|
K(Bytes, "bytes", 0) \
|
||||||
T(BytesM, "bytesM", 0) \
|
|
||||||
K(Byte, "byte", 0) \
|
K(Byte, "byte", 0) \
|
||||||
K(String, "string", 0) \
|
K(String, "string", 0) \
|
||||||
K(Address, "address", 0) \
|
K(Address, "address", 0) \
|
||||||
K(Bool, "bool", 0) \
|
K(Bool, "bool", 0) \
|
||||||
K(Fixed, "fixed", 0) \
|
K(Fixed, "fixed", 0) \
|
||||||
T(FixedMxN, "fixedMxN", 0) \
|
|
||||||
K(UFixed, "ufixed", 0) \
|
K(UFixed, "ufixed", 0) \
|
||||||
|
T(IntM, "intM", 0) \
|
||||||
|
T(UIntM, "uintM", 0) \
|
||||||
|
T(BytesM, "bytesM", 0) \
|
||||||
|
T(FixedMxN, "fixedMxN", 0) \
|
||||||
T(UFixedMxN, "ufixedMxN", 0) \
|
T(UFixedMxN, "ufixedMxN", 0) \
|
||||||
T(TypesEnd, NULL, 0) /* used as type enum end marker */ \
|
T(TypesEnd, NULL, 0) /* used as type enum end marker */ \
|
||||||
\
|
\
|
||||||
@ -334,7 +334,9 @@ public:
|
|||||||
std::string name = Token::toString(m_token);
|
std::string name = Token::toString(m_token);
|
||||||
if (tokenValue || (firstNumber() == 0 && secondNumber() == 0))
|
if (tokenValue || (firstNumber() == 0 && secondNumber() == 0))
|
||||||
return name;
|
return name;
|
||||||
//need to set it up this way for fixed types construction in future
|
else if (m_token == Token::FixedMxN || m_token == Token::UFixedMxN)
|
||||||
|
return name.substr(0, name.size() - 3) + std::to_string(m_firstNumber) + "x" + std::to_string(m_secondNumber);
|
||||||
|
else
|
||||||
return name.substr(0, name.size() - 1) + std::to_string(m_firstNumber);
|
return name.substr(0, name.size() - 1) + std::to_string(m_firstNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user