added: syntax highlighting for `dyn_str`; bugfix: array.insert
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 7 Mar 2023 23:18:59 +0000 (17:18 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 7 Mar 2023 23:18:59 +0000 (17:18 -0600)
core/container/array.onyx
core/string/string.onyx
misc/onyx-mode.el
misc/onyx.sublime-syntax
misc/onyx.vim
misc/vscode/onyx-0.1.5.vsix
misc/vscode/syntaxes/onyx.tmLanguage
tests/bugs/print_formatters [new file with mode: 0644]
tests/bugs/print_formatters.onyx [new file with mode: 0644]
tests/dyn_str [new file with mode: 0644]
tests/dyn_str.onyx [new file with mode: 0644]

index cfe352e6dcb15bb0722454d8ad9768508a4232db..340eeae82d209b3eb630f5994ff4d418ef6a7816 100644 (file)
@@ -140,7 +140,7 @@ insert :: (arr: &[..] $T, idx: u32, new_arr: [] T) -> bool {
 
     arr.count += new_arr.count;
     while i := arr.count; i > idx {
-        arr.data[i] = arr.data[i - 1];
+        arr.data[i] = arr.data[i - new_arr.count];
         i -= 1;
     }
 
index 4295c32745220727123d483384c050c587f9ca6c..ba6e4c66db40e7da5be96ad74745859f47a891ef 100644 (file)
@@ -16,7 +16,10 @@ as_str :: macro (t: $T/HasAsStrMethod) -> str {
 
 
 
-free :: (s: str, allocator := context.allocator) do raw_free(allocator, s.data);
+free :: #match #locked {
+    (s: str, allocator := context.allocator) { raw_free(allocator, s.data); },
+    (s: &dyn_str) { core.array.free(s); },
+}
 
 alloc_copy :: (original: str, allocator := context.allocator) -> str {
     if original.count == 0 do return .{};
index 73edbfd3e66071314f141a97776873a00101fce2..5f8e5ab67e9e50a5d7599825ac5467d924678969 100644 (file)
@@ -52,7 +52,7 @@
 (defconst onyx-typenames
   '("u64" "u32" "u16" "u8"
     "i64" "i32" "i16" "i8"
-    "f32" "f64" "str" "cstr" "any" "type_expr"
+    "f32" "f64" "str" "cstr" "dyn_str" "any" "type_expr"
     "bool" "void" "rawptr"
     "i8x16" "i16x8" "i32x4" "i64x2"
     "f32x4" "f64x2" "v128"))
index ccce21610d71d616088a32f778a7f179590498cc..1bbf0fea98004965fcbd8ca08eee52fd6c07d9d3 100644 (file)
@@ -32,7 +32,7 @@ contexts:
     - match: '\b(package|struct|interface|use|where|global|enum|if|elseif|else|for|while|do|break|continue|fallthrough|return|cast|sizeof|alignof|typeof|defer|switch|case|macro)\b'
       scope: keyword.control.onyx
 
-    - match: '\b(bool|void|i8|u8|i16|u16|i32|u32|i64|u64|f32|f64|rawptr|str|cstr|range|type_expr|any)\b'
+    - match: '\b(bool|void|i8|u8|i16|u16|i32|u32|i64|u64|f32|f64|rawptr|str|cstr|dyn_str|range|type_expr|any)\b'
       scope: storage.type
 
     - match: '\b(i8x16|i16x8|i32x4|i64x2|f32x4|f64x2|v128)\b'
index 4d90cba9e3823c1c8d05260057ce66f48df25acf..53eccd91ceb0af812aa128594761045c48de6f3c 100644 (file)
@@ -23,7 +23,7 @@ syn keyword onyxType i32 u32
 syn keyword onyxType i64 u64
 syn keyword onyxType f32 f64
 syn keyword onyxType rawptr
-syn keyword onyxType str cstr
+syn keyword onyxType str cstr dyn_str
 syn keyword onyxType i8x16 i16x8 i32x4 i64x2 f32x4 f64x2 v128
 syn keyword onyxType type_expr any
 
index ddeb2156d4911dfaf64a4365e8a34ea2edfb5df9..82722466d1202c47bded8a01025f07baa107567a 100644 (file)
Binary files a/misc/vscode/onyx-0.1.5.vsix and b/misc/vscode/onyx-0.1.5.vsix differ
index 43605084f07d971f9801804203da5bbeae14f0c3..aa669a9bb45c05f9b869d115a69a47c1339d94a2 100644 (file)
                                </dict>
                                <dict>
                                        <key>match</key>
-                                       <string>\b(str|cstr|type_expr|any)\b</string>
+                                       <string>\b(str|cstr|dyn_str|type_expr|any)\b</string>
                                        <key>name</key>
                                        <string>storage.type.onyx</string>
                                </dict>
diff --git a/tests/bugs/print_formatters b/tests/bugs/print_formatters
new file mode 100644 (file)
index 0000000..5867894
--- /dev/null
@@ -0,0 +1,5 @@
+{
+Hello{}World
+Hello{}World
+}{hello}{
+}3R{
diff --git a/tests/bugs/print_formatters.onyx b/tests/bugs/print_formatters.onyx
new file mode 100644 (file)
index 0000000..ccd5ecf
--- /dev/null
@@ -0,0 +1,10 @@
+use core
+
+main :: () {
+    printf("{\n");
+    printf("Hello{");
+    printf("}World\n");
+    printf("Hello{{}}World\n");
+    printf("}{hello}{\n", 123);
+    printf("}{b32}{\n", 123);
+}
\ No newline at end of file
diff --git a/tests/dyn_str b/tests/dyn_str
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/dyn_str.onyx b/tests/dyn_str.onyx
new file mode 100644 (file)
index 0000000..1918c79
--- /dev/null
@@ -0,0 +1,15 @@
+use core
+
+
+main :: () {
+    output: dyn_str;
+    defer string.free(&output);
+
+    string.append(&output, "Hello");
+    string.append(&output, "World");
+    string.append(&output, "!");
+
+    string.insert(&output, 5, ", ");
+
+    println(output);
+}
\ No newline at end of file