mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Accept any kind of whitespace after natspec tags
This commit is contained in:
parent
ba9a045002
commit
5738e865d5
@ -16,16 +16,39 @@ static inline string::const_iterator skipLineOrEOS(
|
||||
return (_nlPos == _end) ? _end : ++_nlPos;
|
||||
}
|
||||
|
||||
static inline string::const_iterator firstSpaceOrNl(
|
||||
static inline string::const_iterator firstSpaceOrTab(
|
||||
string::const_iterator _pos,
|
||||
string::const_iterator _end
|
||||
)
|
||||
{
|
||||
auto spacePos = find(_pos, _end, ' ');
|
||||
auto nlPos = find(_pos, _end, '\n');
|
||||
return (spacePos < nlPos) ? spacePos : nlPos;
|
||||
auto tabPos = find(_pos, _end, '\t');
|
||||
return (spacePos < tabPos) ? spacePos : tabPos;
|
||||
}
|
||||
|
||||
static inline string::const_iterator firstWsOrNl(
|
||||
string::const_iterator _pos,
|
||||
string::const_iterator _end
|
||||
)
|
||||
{
|
||||
auto wsPos = firstSpaceOrTab(_pos, _end);
|
||||
auto nlPos = find(wsPos, _end, '\n');
|
||||
return (wsPos < nlPos) ? wsPos : nlPos;
|
||||
}
|
||||
|
||||
|
||||
static inline string::const_iterator skipWhitespace(
|
||||
string::const_iterator _pos,
|
||||
string::const_iterator _end
|
||||
)
|
||||
{
|
||||
auto currPos = _pos;
|
||||
while ((*currPos == ' ' || *currPos == '\t') && currPos != _end)
|
||||
currPos += 1;
|
||||
return currPos;
|
||||
}
|
||||
|
||||
|
||||
bool DocStringParser::parse(string const& _docString, ErrorList& _errors)
|
||||
{
|
||||
m_errors = &_errors;
|
||||
@ -43,7 +66,7 @@ bool DocStringParser::parse(string const& _docString, ErrorList& _errors)
|
||||
if (tagPos != end && tagPos < nlPos)
|
||||
{
|
||||
// we found a tag
|
||||
auto tagNameEndPos = firstSpaceOrNl(tagPos, end);
|
||||
auto tagNameEndPos = firstWsOrNl(tagPos, end);
|
||||
if (tagNameEndPos == end)
|
||||
{
|
||||
appendError("End of tag " + string(tagPos, tagNameEndPos) + "not found");
|
||||
@ -75,7 +98,7 @@ DocStringParser::iter DocStringParser::parseDocTagLine(iter _pos, iter _end, boo
|
||||
{
|
||||
solAssert(!!m_lastTag, "");
|
||||
auto nlPos = find(_pos, _end, '\n');
|
||||
if (_appending && _pos < _end && *_pos != ' ')
|
||||
if (_appending && _pos < _end && *_pos != ' ' && *_pos != '\t')
|
||||
m_lastTag->content += " ";
|
||||
copy(_pos, nlPos, back_inserter(m_lastTag->content));
|
||||
return skipLineOrEOS(nlPos, _end);
|
||||
@ -83,19 +106,30 @@ DocStringParser::iter DocStringParser::parseDocTagLine(iter _pos, iter _end, boo
|
||||
|
||||
DocStringParser::iter DocStringParser::parseDocTagParam(iter _pos, iter _end)
|
||||
{
|
||||
// find param name
|
||||
auto currPos = find(_pos, _end, ' ');
|
||||
if (currPos == _end)
|
||||
// find param name start
|
||||
auto nameStartPos = skipWhitespace(_pos, _end);
|
||||
if (nameStartPos == _end)
|
||||
{
|
||||
appendError("End of param name not found" + string(_pos, _end));
|
||||
appendError("No param name given" + string(nameStartPos, _end));
|
||||
return _end;
|
||||
}
|
||||
auto nameEndPos = firstSpaceOrTab(nameStartPos, _end);
|
||||
if (nameEndPos == _end)
|
||||
{
|
||||
appendError("End of param name not found" + string(nameStartPos, _end));
|
||||
return _end;
|
||||
}
|
||||
auto paramName = string(nameStartPos, nameEndPos);
|
||||
|
||||
auto descStartPos = skipWhitespace(nameEndPos, _end);
|
||||
if (descStartPos == _end)
|
||||
{
|
||||
appendError("No description given for param" + paramName);
|
||||
return _end;
|
||||
}
|
||||
|
||||
auto paramName = string(_pos, currPos);
|
||||
|
||||
currPos += 1;
|
||||
auto nlPos = find(currPos, _end, '\n');
|
||||
auto paramDesc = string(currPos, nlPos);
|
||||
auto nlPos = find(descStartPos, _end, '\n');
|
||||
auto paramDesc = string(descStartPos, nlPos);
|
||||
newTag("param");
|
||||
m_lastTag->paramName = paramName;
|
||||
m_lastTag->content = paramDesc;
|
||||
|
@ -251,6 +251,29 @@ BOOST_AUTO_TEST_CASE(dev_multiple_params)
|
||||
checkNatspec(sourceCode, natspec, false);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(dev_multiple_params_mixed_whitespace)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" /// @dev Multiplies a number by 7 and adds second parameter\n"
|
||||
" /// @param a Documentation for the first parameter\n"
|
||||
" /// @param second Documentation for the second parameter\n"
|
||||
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
|
||||
"}\n";
|
||||
|
||||
char const* natspec = "{"
|
||||
"\"methods\":{"
|
||||
" \"mul(uint256,uint256)\":{ \n"
|
||||
" \"details\": \"Multiplies a number by 7 and adds second parameter\",\n"
|
||||
" \"params\": {\n"
|
||||
" \"a\": \"Documentation for the first parameter\",\n"
|
||||
" \"second\": \"Documentation for the second parameter\"\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}}";
|
||||
|
||||
checkNatspec(sourceCode, natspec, false);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(dev_mutiline_param_description)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
|
Loading…
Reference in New Issue
Block a user