From c458af35ce10195c2caf42b24546d45d38ed217a Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 21 Nov 2023 19:05:09 -0600 Subject: [PATCH] small bugfixes with KDL parsing and onyx-pkg --- core/encoding/kdl/encoder.onyx | 6 ++++-- core/encoding/kdl/parser.onyx | 2 ++ scripts/onyx-pkg.onyx | 13 +++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/core/encoding/kdl/encoder.onyx b/core/encoding/kdl/encoder.onyx index f644298e..b1fe8661 100644 --- a/core/encoding/kdl/encoder.onyx +++ b/core/encoding/kdl/encoder.onyx @@ -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, "}"); } diff --git a/core/encoding/kdl/parser.onyx b/core/encoding/kdl/parser.onyx index b17e6cfc..46f452aa 100644 --- a/core/encoding/kdl/parser.onyx +++ b/core/encoding/kdl/parser.onyx @@ -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 { diff --git a/scripts/onyx-pkg.onyx b/scripts/onyx-pkg.onyx index 0e106f75..b13a07b3 100644 --- a/scripts/onyx-pkg.onyx +++ b/scripts/onyx-pkg.onyx @@ -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); -- 2.25.1