From: Brendan Hansen Date: Mon, 3 Aug 2020 20:58:08 +0000 (-0500) Subject: Very sad but working implementation of hex literals X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=661e9c43285f13096570bf4df7c78fcd10551d36;p=onyx.git Very sad but working implementation of hex literals --- diff --git a/docs/plan b/docs/plan index aadfdc33..12652ee9 100644 --- a/docs/plan +++ b/docs/plan @@ -140,9 +140,9 @@ HOW: [X] #private - symbol is scoped to package and not brought in from a 'use package' statement - [ ] Better checking for casts + [X] Hex literals - [ ] Hex literals + [ ] Better checking for casts [ ] All code paths return correct value diff --git a/misc/onyx.sublime-syntax b/misc/onyx.sublime-syntax index 67c95740..4327aa60 100644 --- a/misc/onyx.sublime-syntax +++ b/misc/onyx.sublime-syntax @@ -36,6 +36,9 @@ contexts: - match: '\b(-)?[0-9.]+\b' scope: constant.numeric.onyx + - match: '\b0x[0-9A-Fa-f]+\b' + scope: constant.numeric.onyx + - match: '#[a-zA-Z]+' scope: keyword.other.onyx diff --git a/onyx b/onyx index 6252d1f4..28f1e29a 100755 Binary files a/onyx and b/onyx differ diff --git a/src/onyxlex.c b/src/onyxlex.c index 9546f7bd..ba69632e 100644 --- a/src/onyxlex.c +++ b/src/onyxlex.c @@ -233,6 +233,23 @@ OnyxToken* onyx_get_token(OnyxTokenizer* tokenizer) { goto token_parsed; } + // Hex literal + if (*tokenizer->curr == '0' && *(tokenizer->curr + 1) == 'x' && char_is_num(*(tokenizer->curr + 2))) { + INCREMENT_CURR_TOKEN(tokenizer); + INCREMENT_CURR_TOKEN(tokenizer); + u32 len = 3; + while (char_is_num(*(tokenizer->curr + 1)) || charset_contains("abcdefABCDEF", *(tokenizer->curr + 1))) { + len++; + INCREMENT_CURR_TOKEN(tokenizer); + } + + tk.type = Token_Type_Literal_Numeric; + tk.length = len; + + INCREMENT_CURR_TOKEN(tokenizer); + goto token_parsed; + } + // Number literal if (char_is_num(*tokenizer->curr)) { u32 len = 1;