xo-tokenizer: mvp: recognize keywords
This commit is contained in:
parent
f57d23fef0
commit
5d31ac7a43
3 changed files with 37 additions and 0 deletions
|
|
@ -86,6 +86,7 @@ namespace xo {
|
|||
static token if_token() { return token(tokentype::tk_if); }
|
||||
static token let() { return token(tokentype::tk_let); }
|
||||
static token in() { return token(tokentype::tk_in); }
|
||||
static token end() { return token(tokentype::tk_end); }
|
||||
|
||||
tokentype tk_type() const { return tk_type_; }
|
||||
const std::string & text() const { return text_; }
|
||||
|
|
|
|||
|
|
@ -510,6 +510,34 @@ namespace xo {
|
|||
; /* nothing to do here -- desired tk_text already constructed */
|
||||
}
|
||||
|
||||
if (tk_type == tokentype::tk_symbol) {
|
||||
/* check for keywords */
|
||||
|
||||
bool keep_text = false;
|
||||
|
||||
if (tk_text == "type") {
|
||||
tk_type = tokentype::tk_type;
|
||||
} else if (tk_text == "def") {
|
||||
tk_type = tokentype::tk_def;
|
||||
} else if (tk_text == "lambda") {
|
||||
tk_type = tokentype::tk_lambda;
|
||||
} else if (tk_text == "if") {
|
||||
tk_type = tokentype::tk_if;
|
||||
} else if (tk_text == "let") {
|
||||
tk_type = tokentype::tk_let;
|
||||
} else if (tk_text == "in") {
|
||||
tk_type = tokentype::tk_in;
|
||||
} else if (tk_text == "end") {
|
||||
tk_type = tokentype::tk_end;
|
||||
} else {
|
||||
/* keep as symbol */
|
||||
keep_text = true;
|
||||
}
|
||||
|
||||
if (!keep_text)
|
||||
tk_text.clear();
|
||||
}
|
||||
|
||||
return token_type(tk_type, std::move(tk_text));
|
||||
} /*assemble_token*/
|
||||
|
||||
|
|
|
|||
|
|
@ -100,6 +100,14 @@ namespace xo {
|
|||
token::string_token("tab to the right [\t], to the right [\t]"), true},
|
||||
|
||||
{"symbol", false, token::symbol_token("symbol"), true},
|
||||
|
||||
{"type", false, token::type(), true},
|
||||
{"def", false, token::def(), true},
|
||||
{"lambda", false, token::lambda(), true},
|
||||
{"if", false, token::if_token(), true},
|
||||
{"let", false, token::let(), true},
|
||||
{"in", false, token::in(), true},
|
||||
{"end", false, token::end(), true},
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue