commit 4cf6d68f729fe6574e9d3135bcbac1ba321ebe69
parent 296d0d903a2c4a8fe905783fca550b33188621a8
Author: Mohammad-Reza Nabipoor <m.nabipoor@yahoo.com>
Date: Mon, 17 Aug 2020 07:54:51 +0430
kaleidoscope_tokens.hpp: Add util function for parser
Add the following utility functions to access token info:
- `token_type`
- `token_str`
- `token_num`
Diffstat:
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/kaleidoscope_tokens.hpp b/kaleidoscope_tokens.hpp
@@ -13,7 +13,7 @@ namespace kal {
struct Token
{
- kal::TkType type;
+ TkType type;
ptrdiff_t bpos;
ptrdiff_t epos;
std::string str;
@@ -28,6 +28,24 @@ struct Token
friend bool operator!=(const Token& x, const Token& y) { return !(x == y); }
};
+inline TkType
+token_type(const Token& t)
+{
+ return t.type;
+}
+
+inline std::string
+token_str(const Token& t)
+{
+ return t.str;
+}
+
+inline double
+token_num(const Token& t)
+{
+ return t.dbl;
+}
+
template<typename FwdIt, typename OutIt>
OutIt
tokenize(FwdIt first, FwdIt last, OutIt tokens)