Fixed Tokenizer producing wrong line number and column #6
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 14 May 2020 22:05:10 +0000 (17:05 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 14 May 2020 22:05:10 +0000 (17:05 -0500)
onyx
onyx.c
onyxlex.c
progs/demo.onyx
progs/mvp.onyx

diff --git a/onyx b/onyx
index 413bb28fcef15e2533296e2a29fd93f2a3e4c51d..12c20cea85d1dbf22f3d155297ce643cb8735fb1 100755 (executable)
Binary files a/onyx and b/onyx differ
diff --git a/onyx.c b/onyx.c
index 5195faf5dfaa699efedb7d784d36508b35e53fbb..a7925bb16de6c10a4a79adcef9d91b28b779f6b6 100644 (file)
--- a/onyx.c
+++ b/onyx.c
@@ -25,7 +25,7 @@ int main(int argc, char *argv[]) {
        printf("There are %d tokens (Allocated space for %d tokens)\n", bh_arr_length(token_arr), bh_arr_capacity(token_arr));
 
        for (OnyxToken* it = token_arr; !bh_arr_end(token_arr, it); it++) {
-               printf("%s\n", onyx_get_token_type_name(*it));
+               printf("%s (Line %ld, Col %ld)\n", onyx_get_token_type_name(*it), it->line_number, it->line_column);
        }
 
        bh_hash_iterator it = bh_hash_iter_setup(u16, symbol_count);
index fb552d136ac90aeb81e9297f96ecb82f2c20212b..dbbfad53ec068ad9c0c6f43aa3a602a3b79b44e1 100644 (file)
--- a/onyxlex.c
+++ b/onyxlex.c
@@ -61,12 +61,11 @@ static const char* onyx_token_type_names[] = {
 
 #ifndef INCREMENT_CURR_TOKEN
 #define INCREMENT_CURR_TOKEN(tkn) { \
-       (tkn)->curr++; \
-       while (*(tkn)->curr == '\n' && (tkn)->curr != (tkn)->end) { \
-               (tkn)->curr++; \
+       if (*(tkn)->curr == '\n') { \
                (tkn)->line_number++; \
-               (tkn)->line_start = (tkn)->curr; \
+               (tkn)->line_start = (tkn)->curr + 1; \
        } \
+       (tkn)->curr++; \
 }
 #endif
 
index b0d3cf0778ebd3cf87dfc27b3897d6d94508980c..2300ab04c6f7770337187cc03ee1c31323f9361d 100644 (file)
@@ -6,7 +6,6 @@ use "core"; /* Looks for "core.onyx" in the current directory */
 
 Foo :: struct { x i32, y i32 };
 
-add :: (a i32, b i32) -> i32 {
-       return a + b + 1234.56;
-};
-
+add :: proc (a i32, b i32) -> i32 {
+    return a + b + 1234.56;
+};
\ No newline at end of file
index 1a8d8c00ae90e193c06c198815fe5a39d06518e6..cef77e5047478856fc4273b87b4d724171cb9a82 100644 (file)
@@ -2,13 +2,15 @@
  /* nested comments /* are /* okay */ */ */
 */
 
-foreign proc "console" "log" :: (data ptr, length i32) -> void;
+foreign "console" "log" :: proc (data ptr, length i32) -> void ---;
 
-export proc add :: (a i32, b i32) -> i32 {
+global thing :: 
+
+export add :: proc (a i32, b i32) -> i32 {
        return a + b;
 };
 
-export proc max :: (a i32, b i32) -> i32 {
+export max :: proc (a i32, b i32) -> i32 {
        /* Curly braces are required */
        x := "String literal! HERE \\\"Woot Woot\" done";