small bugfixes with KDL parsing and onyx-pkg
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 22 Nov 2023 01:05:09 +0000 (19:05 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 22 Nov 2023 01:05:09 +0000 (19:05 -0600)
core/encoding/kdl/encoder.onyx
core/encoding/kdl/parser.onyx
scripts/onyx-pkg.onyx

index f644298ea5c45bf44cd69f1bd8283ad1ea1419a6..b1fe86618a8f29b0be24ffae352624e2d62943ee 100644 (file)
@@ -1,6 +1,8 @@
 package core.encoding.kdl
 #allow_stale_code
 
+KDL_TAB_SIZE :: 4
+
 use core {io}
 
 write :: (d: &Document, w: &io.Writer) {
@@ -11,7 +13,7 @@ write :: (d: &Document, w: &io.Writer) {
 }
 
 write_node :: (n: &Node, w: &io.Writer, indentation := 0) {
-    for indentation * 4 do io.write(w, " ");
+    for indentation * KDL_TAB_SIZE do io.write(w, " ");
 
     n.type_annotation->with([ta] {
         io.write_format(w, "({}) ", ta);
@@ -38,7 +40,7 @@ write_node :: (n: &Node, w: &io.Writer, indentation := 0) {
             write_node(it, w, indentation + 1);
         }
 
-        for indentation * 2 do io.write(w, " ");
+        for indentation * KDL_TAB_SIZE do io.write(w, " ");
         io.write(w, "}");
     }
 
index b17e6cfc28cf2625eaa8d5533993aec3cc1a85ae..46f452aa5fe0369541ed3240928be7c4ee28fac4 100644 (file)
@@ -383,6 +383,8 @@ Parse_Error :: union {
 
                 case .Start_Children {
                     self.tokenizer->next_token();
+                    self->skip_linespace();
+
                     while !self.tokenizer->peek_token().End_Children {
                         child := self->parse_node()?;
                         if child {
index 0e106f752ff30e315697d2ed1a930164a6ccd22b..b13a07b3c069494b816e36d7168d9c0eac3a3396 100644 (file)
@@ -1049,7 +1049,7 @@ Config :: struct {
 
     dependencies: Map(str, Dependency);
 
-    _source_doc: kdl.Document;
+    _source_doc: kdl.Document;
 }
 
 Dependency :: struct {
@@ -1092,6 +1092,7 @@ load_config :: (path: str) -> ? Config {
     doc := kdl.parse(contents).Ok?;
 
     c: Config;
+    c._source_doc = doc;
     c.dependency_source_path = "./lib";
     c.dependency_binary_path = "./bin";
 
@@ -1191,7 +1192,7 @@ store_config :: (path: str) -> bool {
         native_node.children << library_node;
 
         build_node := doc->create_node("build");
-        build_node->add_value(.{ String = config.native_library_build->unwrap() });
+        build_node->add_value(.{ String = config.native_library_build ?? "" });
         native_node.children << build_node;
     }
 
@@ -1214,6 +1215,14 @@ store_config :: (path: str) -> bool {
         }
     }
 
+    config._source_doc->with([source] {
+        for source->query_all("top() > []") {
+            if !array.contains(str.["package", "config", "native", "dependencies"], it.node) {
+                doc.nodes << it;
+            }
+        }
+    });
+
     file := os.open(path, .Write)->or_return(false);
     defer os.close(&file);