Browse Source

Merge branch 'master' of https://github.com/odin-lang/Odin

gingerBill 6 years ago
parent
commit
0755dfbd5d
3 changed files with 51 additions and 22 deletions
  1. 22 20
      core/encoding/json/tokenizer.odin
  2. 0 2
      core/encoding/json/types.odin
  3. 29 0
      core/sys/win32/helpers.odin

+ 22 - 20
core/encoding/json/tokenizer.odin

@@ -68,12 +68,12 @@ next_rune :: proc(t: ^Tokenizer) -> rune #no_bounds_check {
 get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
 get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
 	skip_digits :: proc(t: ^Tokenizer) {
 	skip_digits :: proc(t: ^Tokenizer) {
 		for t.offset < len(t.data) {
 		for t.offset < len(t.data) {
-			next_rune(t);
 			if '0' <= t.r && t.r <= '9' {
 			if '0' <= t.r && t.r <= '9' {
 				// Okay
 				// Okay
 			} else {
 			} else {
 				return;
 				return;
 			}
 			}
+			next_rune(t);
 		}
 		}
 	}
 	}
 	skip_hex_digits :: proc(t: ^Tokenizer) {
 	skip_hex_digits :: proc(t: ^Tokenizer) {
@@ -158,6 +158,7 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
 	skip_whitespace(t);
 	skip_whitespace(t);
 
 
 	token.pos = t.pos;
 	token.pos = t.pos;
+
 	token.kind = Kind.Invalid;
 	token.kind = Kind.Invalid;
 
 
 	curr_rune := t.r;
 	curr_rune := t.r;
@@ -213,23 +214,6 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
 		}
 		}
 		fallthrough;
 		fallthrough;
 
 
-	case '.':
-		err = Error.Illegal_Character;
-		if t.spec == Specification.JSON5 { // Allow leading decimal point
-			skip_digits(t);
-			if t.r == 'e' || t.r == 'E' {
-				switch r := next_rune(t); r {
-				case '+', '-':
-					next_rune(t);
-				}
-				skip_digits(t);
-			}
-			str := string(t.data[token.offset:t.offset]);
-			if !is_valid_number(str, t.spec) {
-				err = Error.Invalid_Number;
-			}
-		}
-
 	case '0'..'9':
 	case '0'..'9':
 		token.kind = Kind.Integer;
 		token.kind = Kind.Integer;
 		if t.spec == Specification.JSON5 { // Hexadecimal Numbers
 		if t.spec == Specification.JSON5 { // Hexadecimal Numbers
@@ -241,6 +225,7 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
 		}
 		}
 
 
 		skip_digits(t);
 		skip_digits(t);
+
 		if t.r == '.' {
 		if t.r == '.' {
 			token.kind = Kind.Float;
 			token.kind = Kind.Float;
 			next_rune(t);
 			next_rune(t);
@@ -259,6 +244,23 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
 			err = Error.Invalid_Number;
 			err = Error.Invalid_Number;
 		}
 		}
 
 
+	case '.':
+		err = Error.Illegal_Character;
+		if t.spec == Specification.JSON5 { // Allow leading decimal point
+			skip_digits(t);
+			if t.r == 'e' || t.r == 'E' {
+				switch r := next_rune(t); r {
+				case '+', '-':
+					next_rune(t);
+				}
+				skip_digits(t);
+			}
+			str := string(t.data[token.offset:t.offset]);
+			if !is_valid_number(str, t.spec) {
+				err = Error.Invalid_Number;
+			}
+		}
+
 
 
 	case '\'':
 	case '\'':
 		err = Error.Illegal_Character;
 		err = Error.Illegal_Character;
@@ -436,8 +438,8 @@ is_valid_string_literal :: proc(s: string, spec: Specification) -> bool {
 				i += 5;
 				i += 5;
 
 
 				for j := 0; j < 4; j += 1 {
 				for j := 0; j < 4; j += 1 {
-					c := hex[j];
-					switch c {
+					c2 := hex[j];
+					switch c2 {
 					case '0'..'9', 'a'..'z', 'A'..'Z':
 					case '0'..'9', 'a'..'z', 'A'..'Z':
 						// Okay
 						// Okay
 					case:
 					case:

+ 0 - 2
core/encoding/json/types.odin

@@ -1,7 +1,5 @@
 package json
 package json
 
 
-import "core:strconv"
-
 Specification :: enum {
 Specification :: enum {
 	JSON,
 	JSON,
 	JSON5,
 	JSON5,

+ 29 - 0
core/sys/win32/helpers.odin

@@ -0,0 +1,29 @@
+// +build windows
+package win32
+
+import "core:strings";
+
+call_external_process :: proc(program, command_line: string) -> bool {
+    si := Startup_Info{ cb=size_of(Startup_Info) };
+    pi := Process_Information{};
+
+    return cast(bool)create_process_w(
+        utf8_to_wstring(program),
+        utf8_to_wstring(command_line),
+        nil, 
+        nil, 
+        Bool(false), 
+        u32(0x10), 
+        nil, 
+        nil, 
+        &si, 
+        &pi
+    );
+}
+
+open_website :: proc(url: string) -> bool {
+	p :: "C:\\Windows\\System32\\cmd.exe";
+	arg := []string{"/C", "start", url};
+	args := strings.join(arg, " ", context.temp_allocator);
+	return call_external_process(p, args);
+}