diff options
author | Christian <c@ethdev.com> | 2015-01-12 19:46:52 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2015-01-12 19:46:52 +0800 |
commit | 307a83e1dea95cd144a955aa0891476e7dd159de (patch) | |
tree | 5adca427a0debe24ba729bd3cd917c821c92ebca /Token.cpp | |
parent | 94cff9684f8b1d4a5e2eeba58444a99e32e8a7ae (diff) | |
download | dexon-solidity-307a83e1dea95cd144a955aa0891476e7dd159de.tar dexon-solidity-307a83e1dea95cd144a955aa0891476e7dd159de.tar.gz dexon-solidity-307a83e1dea95cd144a955aa0891476e7dd159de.tar.bz2 dexon-solidity-307a83e1dea95cd144a955aa0891476e7dd159de.tar.lz dexon-solidity-307a83e1dea95cd144a955aa0891476e7dd159de.tar.xz dexon-solidity-307a83e1dea95cd144a955aa0891476e7dd159de.tar.zst dexon-solidity-307a83e1dea95cd144a955aa0891476e7dd159de.zip |
More convenient function type construction.
Diffstat (limited to 'Token.cpp')
-rw-r--r-- | Token.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -40,8 +40,11 @@ // You should have received a copy of the GNU General Public License // along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. +#include <map> #include <libsolidity/Token.h> +using namespace std; + namespace dev { namespace solidity @@ -77,6 +80,20 @@ char const Token::m_tokenType[] = { TOKEN_LIST(KT, KK) }; + +Token::Value Token::fromIdentifierOrKeyword(const std::string& _name) +{ + // The following macros are used inside TOKEN_LIST and cause non-keyword tokens to be ignored + // and keywords to be put inside the keywords variable. +#define KEYWORD(name, string, precedence) {string, Token::name}, +#define TOKEN(name, string, precedence) + static const map<string, Token::Value> keywords({TOKEN_LIST(TOKEN, KEYWORD)}); +#undef KEYWORD +#undef TOKEN + auto it = keywords.find(_name); + return it == keywords.end() ? Token::IDENTIFIER : it->second; +} + #undef KT #undef KK |