Very sad but working implementation of hex literals
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 3 Aug 2020 20:58:08 +0000 (15:58 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 3 Aug 2020 20:58:08 +0000 (15:58 -0500)
docs/plan
misc/onyx.sublime-syntax
onyx
src/onyxlex.c

index aadfdc3306c746216db9e4d36b0cb960c3cb7b29..12652ee995c7ea7df8127b48b108babcc96650a0 100644 (file)
--- 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
 
index 67c95740a5031b7237b912f52995813669b22a43..4327aa60ca7ffb327b27f6638ec274ae60cd7716 100644 (file)
@@ -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 6252d1f404eeeb277aef03aba8dc772605368250..28f1e29a31758ecb68e87001e7ed98479b652676 100755 (executable)
Binary files a/onyx and b/onyx differ
index 9546f7bdb0c56787cb8de61f60cb8d6b78b5489a..ba69632e7b3df7cbae919c0b1d342098fa711ca2 100644 (file)
@@ -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;