Browse Source

Make `core:odin` use a `string` for the source rather than `[]byte`

gingerBill 4 years ago
parent
commit
df3512b112
3 changed files with 5 additions and 5 deletions
  1. 1 1
      core/odin/ast/ast.odin
  2. 1 1
      core/odin/parser/parse_files.odin
  3. 3 3
      core/odin/tokenizer/tokenizer.odin

+ 1 - 1
core/odin/ast/ast.odin

@@ -69,7 +69,7 @@ File :: struct {
 	pkg: ^Package,
 
 	fullpath: string,
-	src:      []byte,
+	src:      string,
 
 	docs: ^Comment_Group,
 

+ 1 - 1
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;
 	}

+ 3 - 3
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 {