From fa6566b0e83f6bd2396ada96c1ec7e1f9d8ddb51 Mon Sep 17 00:00:00 2001 From: StarCells Date: Sat, 29 Aug 2026 00:36:39 +0800 Subject: [PATCH] 202608290036 --- src/r8asm.cc | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/r8asm.cc b/src/r8asm.cc index aaafe07..dcdec83 100644 --- a/src/r8asm.cc +++ b/src/r8asm.cc @@ -624,15 +624,16 @@ r8asm::token_stream::lex(const std::string &char_stream) { const std::map operator_map = { // without "-" {"+", "op_add"}, {"*", "op_mul"}, {"/", "op_div"}, {"^", "op_xor"}, - {"&", "op_and"}, {"|", "op_or"}, {"~", "op_not"}, {"-", "op_sub"},}; + {"&", "op_and"}, {"|", "op_or"}, {"~", "op_not"}, {"-", "op_sub"}, + }; while (std::getline(iss, str_buffer)) { std::vector token_buffer = {}; bool start_of_line = true; bool lquote_appeared = false; - std::string token_val; - do { + for (std::string token_val = r8asm_strtools::peel(str_buffer); + token_val != ""; token_val = r8asm_strtools::peel(str_buffer)) { token_val = r8asm_strtools::peel(str_buffer); if (lquote_appeared && token_val[0] != '\"') token_buffer.push_back({r8asm::token_t::STRING, token_val}); @@ -641,11 +642,11 @@ r8asm::token_stream::lex(const std::string &char_stream) { start_of_line = false; if (token_val[0] == '.') // builtin token_buffer.push_back( - {r8asm::token_t::BUILTIN, "builtin_" + token_val.substr(0, 1)}); + {r8asm::token_t::BUILTIN, "builtin_" + token_val.substr(1)}); // e.g. .var -> builtin_var else if (token_val[0] == '%') // directive token_buffer.push_back( - {r8asm::token_t::DIRECTIVE, token_val.substr(0, 1)}); + {r8asm::token_t::DIRECTIVE, token_val.substr(1)}); // e.g. %macro -> macro else if (token_val[0] == ';') // remark next_will_be_remark = true; @@ -658,18 +659,19 @@ r8asm::token_stream::lex(const std::string &char_stream) { if (token_val[0] == ';') // remark next_will_be_remark = true; else if (token_val[0] == '%') // parameter - token_buffer.push_back({r8asm::token_t::PARAMETER, token_val.substr(0,1)}); + token_buffer.push_back( + {r8asm::token_t::PARAMETER, token_val.substr(1)}); else if (token_val[0] == '"') { // quote(filename) if (!lquote_appeared) { lquote_appeared = true; // only %include will use quotes, they // won't appear again - token_buffer.push_back({r8asm::token_t::LQUOTE}); + token_buffer.push_back({r8asm::token_t::LQUOTE, token_val}); } else - token_buffer.push_back({r8asm::token_t::RQUOTE}); + token_buffer.push_back({r8asm::token_t::RQUOTE, token_val}); } else if (token_val[0] == '(') - token_buffer.push_back({r8asm::token_t::LPAREN}); + token_buffer.push_back({r8asm::token_t::LPAREN,token_val}); else if (token_val[0] == ')') - token_buffer.push_back({r8asm::token_t::RPAREN}); + token_buffer.push_back({r8asm::token_t::RPAREN,token_val}); else if (std::string(OPERATORS).find(token_val[0]) != std::string::npos) // operator token_buffer.push_back( @@ -679,11 +681,11 @@ r8asm::token_stream::lex(const std::string &char_stream) { } } } - num++; - if (!token_buffer.empty()) - to_return.push_back({num, token_buffer}); - next_will_be_remark = false; - } while (token_val != ""); + } + num++; + if (!token_buffer.empty()) + to_return.push_back({num, token_buffer}); + next_will_be_remark = false; } return to_return; }