Implemented tokenise_literal_hex
Note the overall size of this function in comparison to the C version, as well as its clarity. Of course, it is doing allocations in the background through std::string which requires more profiling if I want to make this super efficient™ but honestly the assembler just needs to work, whereas the runtime needs to be fast.
This commit is contained in:
@@ -20,7 +20,7 @@ using std::string, std::string_view, std::pair, std::make_pair;
|
|||||||
|
|
||||||
constexpr auto VALID_SYMBOL = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV"
|
constexpr auto VALID_SYMBOL = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV"
|
||||||
"WXYZ0123456789-_.:()%#$",
|
"WXYZ0123456789-_.:()%#$",
|
||||||
VALID_DIGIT = "0123456789";
|
VALID_DIGIT = "0123456789", VALID_HEX = "0123456789abcdefABCDEF";
|
||||||
|
|
||||||
bool is_char_in_s(char c, const char *s)
|
bool is_char_in_s(char c, const char *s)
|
||||||
{
|
{
|
||||||
@@ -237,3 +237,19 @@ token_t tokenise_literal_number(string_view &source, size_t &column)
|
|||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
token_t tokenise_literal_hex(string_view &source, size_t &column)
|
||||||
|
{
|
||||||
|
// Remove x char from source
|
||||||
|
source.remove_prefix(1);
|
||||||
|
auto end = source.find_first_not_of(VALID_HEX);
|
||||||
|
if (end == string::npos)
|
||||||
|
end = source.size() - 1;
|
||||||
|
string digits{source.substr(0, end)};
|
||||||
|
source.remove_prefix(end);
|
||||||
|
|
||||||
|
token_t t = {token_type_t::LITERAL_NUMBER, "0x" + digits, column};
|
||||||
|
|
||||||
|
column += digits.size() + 1;
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user