📝 rename tokname => token_name_mapper

This commit is contained in:
ValKmjolnir 2024-06-04 00:14:47 +08:00
parent 5e2268e4c5
commit 32c0b93e05
3 changed files with 15 additions and 5 deletions

View File

@ -97,10 +97,12 @@ private:
std::string filename;
std::string res;
private:
error err;
u64 invalid_char;
std::vector<token> toks;
private:
const std::unordered_map<std::string, tok> token_mapper = {
{"use" , tok::tk_use },
{"true" , tok::tk_true },
@ -160,6 +162,7 @@ private:
{">=" , tok::tk_geq }
};
private:
tok get_type(const std::string&);
bool skip(char);
bool is_id(char);
@ -183,9 +186,11 @@ private:
token single_opr();
token dots();
token calc_opr();
public:
lexer(): line(1), column(0), ptr(0),
filename(""), res(""), invalid_char(0) {}
filename(""), res(""),
invalid_char(0) {}
const error& scan(const std::string&);
const std::vector<token>& result() const {return toks;}
};

View File

@ -82,7 +82,11 @@ void parse::match(tok type, const char* info) {
case tok::tk_num: die(thisspan, "expected number"); break;
case tok::tk_str: die(thisspan, "expected string"); break;
case tok::tk_id: die(thisspan, "expected identifier"); break;
default: die(thisspan, "expected \""+tokname.at(type)+"\""); break;
default:
die(thisspan,
"expected \"" + token_name_mapper.at(type)+"\""
);
break;
}
return;
}

View File

@ -23,7 +23,7 @@ private:
error err;
private:
const std::unordered_map<tok, std::string> tokname = {
const std::unordered_map<tok, std::string> token_name_mapper = {
{tok::tk_true , "true" },
{tok::tk_false , "false" },
{tok::tk_use , "use" },
@ -155,8 +155,9 @@ public:
}
public:
parse(): ptr(0), in_func_depth(0), in_loop_depth(0),
toks(nullptr), root(nullptr) {}
parse(): ptr(0), in_func_depth(0),
in_loop_depth(0), toks(nullptr),
root(nullptr) {}
~parse() {delete root;}
const error& compile(const lexer&);
static void easter_egg();