diff --git a/src/nasal_lexer.h b/src/nasal_lexer.h index 2e60d65..a0e41cd 100644 --- a/src/nasal_lexer.h +++ b/src/nasal_lexer.h @@ -97,10 +97,12 @@ private: std::string filename; std::string res; +private: error err; u64 invalid_char; std::vector toks; +private: const std::unordered_map 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& result() const {return toks;} }; diff --git a/src/nasal_parse.cpp b/src/nasal_parse.cpp index 811c6ce..5b8ec1a 100644 --- a/src/nasal_parse.cpp +++ b/src/nasal_parse.cpp @@ -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; } diff --git a/src/nasal_parse.h b/src/nasal_parse.h index 5e28d35..612585b 100644 --- a/src/nasal_parse.h +++ b/src/nasal_parse.h @@ -23,7 +23,7 @@ private: error err; private: - const std::unordered_map tokname = { + const std::unordered_map 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();