From df3512b1120dc17a01f8cfebd1f2f9042acdb9b5 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 16 May 2021 12:38:27 +0100 Subject: [PATCH] Make `core:odin` use a `string` for the source rather than `[]byte` --- core/odin/ast/ast.odin | 2 +- core/odin/parser/parse_files.odin | 2 +- core/odin/tokenizer/tokenizer.odin | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/odin/ast/ast.odin b/core/odin/ast/ast.odin index 0d015f9bb..cf2cdeacc 100644 --- a/core/odin/ast/ast.odin +++ b/core/odin/ast/ast.odin @@ -69,7 +69,7 @@ File :: struct { pkg: ^Package, fullpath: string, - src: []byte, + src: string, docs: ^Comment_Group, diff --git a/core/odin/parser/parse_files.odin b/core/odin/parser/parse_files.odin index 99275777c..f622c9781 100644 --- a/core/odin/parser/parse_files.odin +++ b/core/odin/parser/parse_files.odin @@ -39,7 +39,7 @@ collect_package :: proc(path: string) -> (pkg: ^ast.Package, success: bool) { } file := ast.new(ast.File, NO_POS, NO_POS); file.pkg = pkg; - file.src = src; + file.src = string(src); file.fullpath = fullpath; pkg.files[fullpath] = file; } diff --git a/core/odin/tokenizer/tokenizer.odin b/core/odin/tokenizer/tokenizer.odin index 297f42e3d..f13dd5b7a 100644 --- a/core/odin/tokenizer/tokenizer.odin +++ b/core/odin/tokenizer/tokenizer.odin @@ -14,7 +14,7 @@ Flags :: distinct bit_set[Flag; u32]; Tokenizer :: struct { // Immutable data path: string, - src: []byte, + src: string, err: Error_Handler, flags: Flags, @@ -31,7 +31,7 @@ Tokenizer :: struct { error_count: int, } -init :: proc(t: ^Tokenizer, src: []byte, path: string, err: Error_Handler = default_error_handler) { +init :: proc(t: ^Tokenizer, src: string, path: string, err: Error_Handler = default_error_handler) { t.src = src; t.err = err; t.ch = ' '; @@ -87,7 +87,7 @@ advance_rune :: proc(using t: ^Tokenizer) { case r == 0: error(t, t.offset, "illegal character NUL"); case r >= utf8.RUNE_SELF: - r, w = utf8.decode_rune(src[read_offset:]); + r, w = utf8.decode_rune_in_string(src[read_offset:]); if r == utf8.RUNE_ERROR && w == 1 { error(t, t.offset, "illegal UTF-8 encoding"); } else if r == utf8.RUNE_BOM && offset > 0 {