aboutsummaryrefslogtreecommitdiffstats
path: root/Token.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2015-01-12 19:46:52 +0800
committerChristian <c@ethdev.com>2015-01-12 19:46:52 +0800
commit307a83e1dea95cd144a955aa0891476e7dd159de (patch)
tree5adca427a0debe24ba729bd3cd917c821c92ebca /Token.cpp
parent94cff9684f8b1d4a5e2eeba58444a99e32e8a7ae (diff)
downloaddexon-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.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/Token.cpp b/Token.cpp
index 093bd9c1..7dc56c32 100644
--- a/Token.cpp
+++ b/Token.cpp
@@ -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