mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
User-defined literal suffixes: Parsing
This commit is contained in:
parent
2986772f3f
commit
00509830d5
@ -2050,7 +2050,44 @@ ASTPointer<Expression> Parser::parseLiteral()
|
|||||||
return nodeFactory.createNode<Literal>(initialToken, std::move(value), subDenomination);
|
return nodeFactory.createNode<Literal>(initialToken, std::move(value), subDenomination);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nodeFactory.createNode<Literal>(initialToken, std::move(value), Literal::SubDenomination::None);
|
ASTPointer<Literal> literal = nodeFactory.createNode<Literal>(initialToken, std::move(value), Literal::SubDenomination::None);
|
||||||
|
|
||||||
|
if (m_scanner->currentToken() != Token::Identifier)
|
||||||
|
return literal;
|
||||||
|
|
||||||
|
ASTPointer<Expression> suffix = parseLiteralSuffix();
|
||||||
|
nodeFactory.setEndPositionFromNode(suffix);
|
||||||
|
|
||||||
|
return nodeFactory.createNode<FunctionCall>(
|
||||||
|
std::move(suffix),
|
||||||
|
std::vector<ASTPointer<Expression>>{std::move(literal)},
|
||||||
|
vector<ASTPointer<ASTString>>{},
|
||||||
|
vector<SourceLocation>{},
|
||||||
|
true /* _isSuffixCall */
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ASTPointer<Expression> Parser::parseLiteralSuffix()
|
||||||
|
{
|
||||||
|
RecursionGuard recursionGuard(*this);
|
||||||
|
ASTNodeFactory nodeFactory(*this);
|
||||||
|
|
||||||
|
nodeFactory.markEndPosition();
|
||||||
|
ASTPointer<Expression> suffix = nodeFactory.createNode<Identifier>(expectIdentifierToken());
|
||||||
|
|
||||||
|
while (m_scanner->currentToken() == Token::Period)
|
||||||
|
{
|
||||||
|
advance();
|
||||||
|
SourceLocation memberLocation = currentLocation();
|
||||||
|
nodeFactory.markEndPosition();
|
||||||
|
suffix = nodeFactory.createNode<MemberAccess>(
|
||||||
|
std::move(suffix),
|
||||||
|
expectIdentifierToken(),
|
||||||
|
std::move(memberLocation)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTPointer<Expression> Parser::parsePrimaryExpression()
|
ASTPointer<Expression> Parser::parsePrimaryExpression()
|
||||||
|
@ -161,6 +161,7 @@ private:
|
|||||||
ASTPointer<Expression> const& _partiallyParsedExpression = ASTPointer<Expression>()
|
ASTPointer<Expression> const& _partiallyParsedExpression = ASTPointer<Expression>()
|
||||||
);
|
);
|
||||||
ASTPointer<Expression> parseLiteral();
|
ASTPointer<Expression> parseLiteral();
|
||||||
|
ASTPointer<Expression> parseLiteralSuffix();
|
||||||
ASTPointer<Expression> parsePrimaryExpression();
|
ASTPointer<Expression> parsePrimaryExpression();
|
||||||
std::vector<ASTPointer<Expression>> parseFunctionCallListArguments();
|
std::vector<ASTPointer<Expression>> parseFunctionCallListArguments();
|
||||||
|
|
||||||
|
@ -4,4 +4,4 @@ contract C {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// ParserError 2314: (58-64): Expected ';' but got identifier
|
// DeclarationError 7576: (58-64): Undeclared identifier.
|
||||||
|
@ -4,4 +4,4 @@ contract C {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// ParserError 2314: (58-63): Expected ';' but got identifier
|
// DeclarationError 7576: (58-63): Undeclared identifier.
|
||||||
|
Loading…
Reference in New Issue
Block a user