📝 rename tokname => token_name_mapper
This commit is contained in:
parent
5e2268e4c5
commit
32c0b93e05
|
@ -97,10 +97,12 @@ private:
|
||||||
std::string filename;
|
std::string filename;
|
||||||
std::string res;
|
std::string res;
|
||||||
|
|
||||||
|
private:
|
||||||
error err;
|
error err;
|
||||||
u64 invalid_char;
|
u64 invalid_char;
|
||||||
std::vector<token> toks;
|
std::vector<token> toks;
|
||||||
|
|
||||||
|
private:
|
||||||
const std::unordered_map<std::string, tok> token_mapper = {
|
const std::unordered_map<std::string, tok> token_mapper = {
|
||||||
{"use" , tok::tk_use },
|
{"use" , tok::tk_use },
|
||||||
{"true" , tok::tk_true },
|
{"true" , tok::tk_true },
|
||||||
|
@ -160,6 +162,7 @@ private:
|
||||||
{">=" , tok::tk_geq }
|
{">=" , tok::tk_geq }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
tok get_type(const std::string&);
|
tok get_type(const std::string&);
|
||||||
bool skip(char);
|
bool skip(char);
|
||||||
bool is_id(char);
|
bool is_id(char);
|
||||||
|
@ -183,9 +186,11 @@ private:
|
||||||
token single_opr();
|
token single_opr();
|
||||||
token dots();
|
token dots();
|
||||||
token calc_opr();
|
token calc_opr();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
lexer(): line(1), column(0), ptr(0),
|
lexer(): line(1), column(0), ptr(0),
|
||||||
filename(""), res(""), invalid_char(0) {}
|
filename(""), res(""),
|
||||||
|
invalid_char(0) {}
|
||||||
const error& scan(const std::string&);
|
const error& scan(const std::string&);
|
||||||
const std::vector<token>& result() const {return toks;}
|
const std::vector<token>& result() const {return toks;}
|
||||||
};
|
};
|
||||||
|
|
|
@ -82,7 +82,11 @@ void parse::match(tok type, const char* info) {
|
||||||
case tok::tk_num: die(thisspan, "expected number"); break;
|
case tok::tk_num: die(thisspan, "expected number"); break;
|
||||||
case tok::tk_str: die(thisspan, "expected string"); break;
|
case tok::tk_str: die(thisspan, "expected string"); break;
|
||||||
case tok::tk_id: die(thisspan, "expected identifier"); 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ private:
|
||||||
error err;
|
error err;
|
||||||
|
|
||||||
private:
|
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_true , "true" },
|
||||||
{tok::tk_false , "false" },
|
{tok::tk_false , "false" },
|
||||||
{tok::tk_use , "use" },
|
{tok::tk_use , "use" },
|
||||||
|
@ -155,8 +155,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
parse(): ptr(0), in_func_depth(0), in_loop_depth(0),
|
parse(): ptr(0), in_func_depth(0),
|
||||||
toks(nullptr), root(nullptr) {}
|
in_loop_depth(0), toks(nullptr),
|
||||||
|
root(nullptr) {}
|
||||||
~parse() {delete root;}
|
~parse() {delete root;}
|
||||||
const error& compile(const lexer&);
|
const error& compile(const lexer&);
|
||||||
static void easter_egg();
|
static void easter_egg();
|
||||||
|
|
Loading…
Reference in New Issue