mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Parsing notice and dev doxytags.
- Only initial work done. Still need to refine the logic and incorporate all the other types of tags. - Added/Modified some tests - Work in progress
This commit is contained in:
parent
ba27dc7421
commit
3e803b40e1
@ -9,6 +9,7 @@ namespace solidity {
|
|||||||
|
|
||||||
InterfaceHandler::InterfaceHandler()
|
InterfaceHandler::InterfaceHandler()
|
||||||
{
|
{
|
||||||
|
m_lastTag = DOCTAG_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<std::string> InterfaceHandler::getDocumentation(std::shared_ptr<ContractDefinition> _contractDef,
|
std::unique_ptr<std::string> InterfaceHandler::getDocumentation(std::shared_ptr<ContractDefinition> _contractDef,
|
||||||
@ -71,7 +72,9 @@ std::unique_ptr<std::string> InterfaceHandler::getUserDocumentation(std::shared_
|
|||||||
auto strPtr = f->getDocumentation();
|
auto strPtr = f->getDocumentation();
|
||||||
if (strPtr)
|
if (strPtr)
|
||||||
{
|
{
|
||||||
user["notice"] = Json::Value(*strPtr);
|
m_notice.clear();
|
||||||
|
parseDocString(*strPtr);
|
||||||
|
user["notice"] = Json::Value(m_notice);
|
||||||
methods[f->getName()] = user;
|
methods[f->getName()] = user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,7 +97,7 @@ std::unique_ptr<std::string> InterfaceHandler::getDevDocumentation(std::shared_p
|
|||||||
m_dev.clear();
|
m_dev.clear();
|
||||||
parseDocString(*strPtr);
|
parseDocString(*strPtr);
|
||||||
|
|
||||||
method["dev"] = Json::Value(m_dev);
|
method["details"] = Json::Value(m_dev);
|
||||||
methods[f->getName()] = method;
|
methods[f->getName()] = method;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,7 +109,11 @@ std::unique_ptr<std::string> InterfaceHandler::getDevDocumentation(std::shared_p
|
|||||||
/* -- private -- */
|
/* -- private -- */
|
||||||
size_t InterfaceHandler::parseDocTag(std::string const& _string, std::string const& _tag, size_t _pos)
|
size_t InterfaceHandler::parseDocTag(std::string const& _string, std::string const& _tag, size_t _pos)
|
||||||
{
|
{
|
||||||
|
//TODO: This is pretty naive at the moment. e.g. need to check for
|
||||||
|
// '@' between _pos and \n, remove redundancy e.t.c.
|
||||||
size_t nlPos = _pos;
|
size_t nlPos = _pos;
|
||||||
|
if (m_lastTag == DOCTAG_NONE || _tag != "")
|
||||||
|
{
|
||||||
if (_tag == "dev")
|
if (_tag == "dev")
|
||||||
{
|
{
|
||||||
nlPos = _string.find("\n", _pos);
|
nlPos = _string.find("\n", _pos);
|
||||||
@ -114,6 +121,7 @@ size_t InterfaceHandler::parseDocTag(std::string const& _string, std::string con
|
|||||||
nlPos == std::string::npos ?
|
nlPos == std::string::npos ?
|
||||||
_string.length() :
|
_string.length() :
|
||||||
nlPos - _pos);
|
nlPos - _pos);
|
||||||
|
m_lastTag = DOCTAG_DEV;
|
||||||
}
|
}
|
||||||
else if (_tag == "notice")
|
else if (_tag == "notice")
|
||||||
{
|
{
|
||||||
@ -122,11 +130,35 @@ size_t InterfaceHandler::parseDocTag(std::string const& _string, std::string con
|
|||||||
nlPos == std::string::npos ?
|
nlPos == std::string::npos ?
|
||||||
_string.length() :
|
_string.length() :
|
||||||
nlPos - _pos);
|
nlPos - _pos);
|
||||||
|
m_lastTag = DOCTAG_NOTICE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//TODO: Some form of warning
|
//TODO: Some form of warning
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch(m_lastTag)
|
||||||
|
{
|
||||||
|
case DOCTAG_DEV:
|
||||||
|
nlPos = _string.find("\n", _pos);
|
||||||
|
m_dev += _string.substr(_pos,
|
||||||
|
nlPos == std::string::npos ?
|
||||||
|
_string.length() :
|
||||||
|
nlPos - _pos);
|
||||||
|
break;
|
||||||
|
case DOCTAG_NOTICE:
|
||||||
|
nlPos = _string.find("\n", _pos);
|
||||||
|
m_notice += _string.substr(_pos,
|
||||||
|
nlPos == std::string::npos ?
|
||||||
|
_string.length() :
|
||||||
|
nlPos - _pos);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nlPos;
|
return nlPos;
|
||||||
}
|
}
|
||||||
@ -134,16 +166,28 @@ size_t InterfaceHandler::parseDocTag(std::string const& _string, std::string con
|
|||||||
void InterfaceHandler::parseDocString(std::string const& _string, size_t _startPos)
|
void InterfaceHandler::parseDocString(std::string const& _string, size_t _startPos)
|
||||||
{
|
{
|
||||||
size_t pos2;
|
size_t pos2;
|
||||||
|
size_t newPos = _startPos;
|
||||||
size_t pos1 = _string.find("@", _startPos);
|
size_t pos1 = _string.find("@", _startPos);
|
||||||
|
|
||||||
if (pos1 == std::string::npos)
|
if (pos1 != std::string::npos)
|
||||||
return; // no doxytags found
|
{
|
||||||
|
// we found a tag
|
||||||
pos2 = _string.find(" ", pos1);
|
pos2 = _string.find(" ", pos1);
|
||||||
if (pos2 == std::string::npos)
|
if (pos2 == std::string::npos)
|
||||||
|
{
|
||||||
|
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("End of tag not found"));
|
||||||
return; //no end of tag found
|
return; //no end of tag found
|
||||||
|
}
|
||||||
|
|
||||||
size_t newPos = parseDocTag(_string, _string.substr(pos1 + 1, pos2 - pos1), pos2);
|
newPos = parseDocTag(_string, _string.substr(pos1 + 1, pos2 - pos1 - 1), pos2 + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newPos = parseDocTag(_string, "", _startPos + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newPos == std::string::npos)
|
||||||
|
return; // EOS
|
||||||
parseDocString(_string, newPos);
|
parseDocString(_string, newPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,13 @@ namespace solidity {
|
|||||||
class ContractDefinition;
|
class ContractDefinition;
|
||||||
enum documentationType: unsigned short;
|
enum documentationType: unsigned short;
|
||||||
|
|
||||||
|
enum docTagType
|
||||||
|
{
|
||||||
|
DOCTAG_NONE = 0,
|
||||||
|
DOCTAG_DEV,
|
||||||
|
DOCTAG_NOTICE,
|
||||||
|
};
|
||||||
|
|
||||||
class InterfaceHandler
|
class InterfaceHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -73,6 +80,7 @@ private:
|
|||||||
Json::StyledWriter m_writer;
|
Json::StyledWriter m_writer;
|
||||||
|
|
||||||
// internal state
|
// internal state
|
||||||
|
enum docTagType m_lastTag;
|
||||||
std::string m_notice;
|
std::string m_notice;
|
||||||
std::string m_dev;
|
std::string m_dev;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user