aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2026-02-08 12:50:19 +0100
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2026-02-08 12:50:19 +0100
commit8b3ae667f449f7f013d926b5f3d9177b2483e54f (patch)
treeaa193ac6757295d7d7e00aac7719a79f178c7b6f /core
parentc265d297b5c9252db391cdf43eca079d8f634791 (diff)
More conflicts during rebase
Diffstat (limited to 'core')
-rw-r--r--core/unicode/tools/generate_entity_table.odin87
1 files changed, 31 insertions, 56 deletions
diff --git a/core/unicode/tools/generate_entity_table.odin b/core/unicode/tools/generate_entity_table.odin
index 9517b632b..02958ad26 100644
--- a/core/unicode/tools/generate_entity_table.odin
+++ b/core/unicode/tools/generate_entity_table.odin
@@ -1,17 +1,14 @@
package xml_example
-import "core:encoding/xml"
-import "core:os"
+import "core:encoding/xml"
+import os "core:os/os2"
import path "core:path/filepath"
-import "core:mem"
-import "core:strings"
-import "core:strconv"
-import "core:slice"
-import "core:fmt"
+import "core:strings"
+import "core:strconv"
+import "core:slice"
+import "core:fmt"
-/*
- Silent error handler for the parser.
-*/
+// Silent error handler for the parser.
Error_Handler :: proc(pos: xml.Pos, fmt: string, args: ..any) {}
OPTIONS :: xml.Options{ flags = { .Ignore_Unsupported, }, expected_doctype = "unicode", }
@@ -22,7 +19,7 @@ Entity :: struct {
description: string,
}
-generate_encoding_entity_table :: proc() {
+main :: proc() {
filename := path.join({ODIN_ROOT, "tests", "core", "assets", "XML", "unicode.xml"})
defer delete(filename)
@@ -33,14 +30,14 @@ generate_encoding_entity_table :: proc() {
defer xml.destroy(doc)
if err != .None {
- fmt.printf("Load/Parse error: %v\n", err)
+ fmt.printfln("Load/Parse error: %v", err)
if err == .File_Error {
- fmt.printf("\"%v\" not found. Did you run \"tests\\download_assets.py\"?", filename)
+ fmt.eprintfln("%q not found. Did you run \"tests\\download_assets.py\"?", filename)
}
os.exit(1)
}
- fmt.printf("\"%v\" loaded and parsed.\n", filename)
+ fmt.printfln("%q loaded and parsed.", filename)
generated_buf: strings.Builder
defer strings.builder_destroy(&generated_buf)
@@ -54,7 +51,7 @@ generate_encoding_entity_table :: proc() {
charlist := doc.elements[charlist_id]
- fmt.printf("Found `<charlist>` with %v children.\n", len(charlist.value))
+ fmt.printfln("Found `<charlist>` with %v children.", len(charlist.value))
entity_map: map[string]Entity
defer delete(entity_map)
@@ -73,7 +70,7 @@ generate_encoding_entity_table :: proc() {
char := doc.elements[id]
if char.ident != "character" {
- fmt.eprintf("Expected `<character>`, got `<%v>`\n", char.ident)
+ fmt.eprintfln("Expected `<character>`, got `<%v>`", char.ident)
os.exit(1)
}
@@ -90,15 +87,13 @@ generate_encoding_entity_table :: proc() {
}
desc, desc_ok := xml.find_child_by_ident(doc, id, "description")
+ assert(desc_ok)
description := ""
if len(doc.elements[desc].value) == 1 {
description = doc.elements[desc].value[0].(string)
}
- /*
- For us to be interested in this codepoint, it has to have at least one entity.
- */
-
+ // For us to be interested in this codepoint, it has to have at least one entity.
nth := 0
for {
character_entity := xml.find_child_by_ident(doc, id, "entity", nth) or_break
@@ -112,8 +107,8 @@ generate_encoding_entity_table :: proc() {
}
if name == "\"\"" {
- fmt.printf("%#v\n", char)
- fmt.printf("%#v\n", character_entity)
+ fmt.printfln("%#v", char)
+ fmt.printfln("%#v", character_entity)
}
if len(name) > max_name_length { longest_name = name }
@@ -139,18 +134,14 @@ generate_encoding_entity_table :: proc() {
}
}
- /*
- Sort by name.
- */
+ // Sort by name.
slice.sort(names[:])
- fmt.printf("Found %v unique `&name;` -> rune mappings.\n", count)
- fmt.printf("Shortest name: %v (%v)\n", shortest_name, min_name_length)
- fmt.printf("Longest name: %v (%v)\n", longest_name, max_name_length)
+ fmt.printfln("Found %v unique `&name;` -> rune mappings.", count)
+ fmt.printfln("Shortest name: %v (%v)", shortest_name, min_name_length)
+ fmt.printfln("Longest name: %v (%v)", longest_name, max_name_length)
- /*
- Generate table.
- */
+ // Generate table.
fmt.wprintln(w, "package encoding_unicode_entity")
fmt.wprintln(w, "")
fmt.wprintln(w, GENERATED)
@@ -158,10 +149,10 @@ generate_encoding_entity_table :: proc() {
fmt.wprintf (w, TABLE_FILE_PROLOG)
fmt.wprintln(w, "")
- fmt.wprintf (w, "// `&%v;`\n", shortest_name)
- fmt.wprintf (w, "XML_NAME_TO_RUNE_MIN_LENGTH :: %v\n", min_name_length)
- fmt.wprintf (w, "// `&%v;`\n", longest_name)
- fmt.wprintf (w, "XML_NAME_TO_RUNE_MAX_LENGTH :: %v\n", max_name_length)
+ fmt.wprintfln(w, "// `&%v;`", shortest_name)
+ fmt.wprintfln(w, "XML_NAME_TO_RUNE_MIN_LENGTH :: %v", min_name_length)
+ fmt.wprintfln(w, "// `&%v;`", longest_name)
+ fmt.wprintfln(w, "XML_NAME_TO_RUNE_MAX_LENGTH :: %v", max_name_length)
fmt.wprintln(w, "")
fmt.wprintln(w,
@@ -198,7 +189,7 @@ named_xml_entity_to_rune :: proc(name: string) -> (decoded: [2]rune, rune_count:
}
prefix = rune(v[0])
- fmt.wprintf (w, "\tcase '%v':\n", prefix)
+ fmt.wprintfln(w, "\tcase '%v':", prefix)
fmt.wprintln(w, "\t\tswitch name {")
}
@@ -214,7 +205,6 @@ named_xml_entity_to_rune :: proc(name: string) -> (decoded: [2]rune, rune_count:
} else {
fmt.wprintf(w, "\t\t\treturn {{%q, 0}}, 1, true\n", e.codepoints[0])
}
-
should_close = true
}
fmt.wprintln(w, "\t\t}")
@@ -229,11 +219,12 @@ named_xml_entity_to_rune :: proc(name: string) -> (decoded: [2]rune, rune_count:
written := os.write_entire_file(generated_filename, transmute([]byte)strings.to_string(generated_buf))
- if written {
- fmt.printf("Successfully written generated \"%v\".\n", generated_filename)
+ if written == nil {
+ fmt.printfln("Successfully written generated \"%v\".", generated_filename)
} else {
- fmt.printf("Failed to write generated \"%v\".\n", generated_filename)
+ fmt.printfln("Failed to write generated \"%v\".", generated_filename)
}
+ // Not a library, no need to clean up.
}
GENERATED :: `/*
@@ -274,20 +265,4 @@ is_dotted_name :: proc(name: string) -> (dotted: bool) {
if r == '.' { return true}
}
return false
-}
-
-main :: proc() {
- track: mem.Tracking_Allocator
- mem.tracking_allocator_init(&track, context.allocator)
- context.allocator = mem.tracking_allocator(&track)
-
- generate_encoding_entity_table()
-
- if len(track.allocation_map) > 0 {
- fmt.println()
- for _, v in track.allocation_map {
- fmt.printf("%v Leaked %v bytes.\n", v.location, v.size)
- }
- }
- fmt.println("Done and cleaned up!")
} \ No newline at end of file