mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-23 04:50:17 +00:00
some fix
This commit is contained in:
parent
d1e6fdc948
commit
c0a855ab7a
@ -25,9 +25,11 @@ constexpr const char* kTokens[] = {
|
||||
"**", "=", ">", "<", "..", "...", "->", "@", "==", "!=", ">=", "<=",
|
||||
"++", "--", "~",
|
||||
/** KW_BEGIN **/
|
||||
"class", "import", "as", "def", "lambda", "pass", "del", "from", "with", "yield",
|
||||
"None", "in", "is", "and", "or", "not", "True", "False", "global", "try", "except", "finally",
|
||||
"while", "for", "if", "elif", "else", "break", "continue", "return", "assert", "raise"
|
||||
// NOTE: These keywords should be sorted in ascending order!!
|
||||
"False", "None", "True", "and", "as", "assert", "break", "class", "continue",
|
||||
"def", "del", "elif", "else", "except", "finally", "for", "from", "global",
|
||||
"if", "import", "in", "is", "lambda", "not", "or", "pass", "raise", "return",
|
||||
"try", "while", "with", "yield",
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
@ -50,12 +52,6 @@ constexpr TokenIndex TK(const char token[]) {
|
||||
constexpr inline bool is_raw_string_used(TokenIndex t) { return t == TK("@id") || t == TK("@long"); }
|
||||
|
||||
#define TK_STR(t) kTokens[t]
|
||||
const small_map<std::string_view, TokenIndex> kTokenKwMap = []() {
|
||||
small_map<std::string_view, TokenIndex> map;
|
||||
for(int k = TK("class"); k < kTokenCount; k++)
|
||||
map.insert(kTokens[k], k);
|
||||
return map;
|
||||
}();
|
||||
|
||||
struct Token {
|
||||
TokenIndex type;
|
||||
|
@ -153,9 +153,13 @@ int Lexer::eat_name() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto it = kTokenKwMap.try_get(name);
|
||||
if(it != nullptr) {
|
||||
add_token(*it);
|
||||
const auto KW_BEGIN = kTokens + TK("False");
|
||||
const auto KW_END = kTokens + kTokenCount;
|
||||
|
||||
auto it = std::lower_bound(KW_BEGIN, KW_END, name);
|
||||
if(it != KW_END) {
|
||||
assert(*it == name);
|
||||
add_token(it - kTokens);
|
||||
} else {
|
||||
add_token(TK("@id"));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user