refactor: rename DTree to DValue

This commit is contained in:
udo
2026-06-12 11:05:52 +00:00
parent 941f5aea08
commit 7066da3cde
157 changed files with 1203 additions and 1074 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
// Minimal exported helper used by the `unit_call()` demo page.
EXPORT DTree* test_func(DTree* call_param)
EXPORT DValue* test_func(DValue* call_param)
{
print("HELLO FROM TEST FUNCTION");
return(0);
+7 -7
View File
@@ -2,7 +2,7 @@
RENDER(Request& context)
{
DTree p;
DValue p;
p.set(context.params);
StringList routes = {"index", "dashboard", "themes", "dashboard", "workspace/projects"};
@@ -10,15 +10,15 @@ RENDER(Request& context)
StringList sorted_routes = list_sort(unique_routes);
StringList labels = map(sorted_routes, [](String route) { return(to_upper(replace(route, "/", " / "))); });
DTree cards;
DTree card;
DValue cards;
DValue card;
card["title"] = "Dashboard"; card["section"] = "app"; card["href"] = "?dashboard"; cards.push(card); card.clear();
card["title"] = "Themes"; card["section"] = "app"; card["href"] = "?themes"; cards.push(card); card.clear();
card["title"] = "Docs"; card["section"] = "reference"; card["href"] = "../doc/index.uce"; cards.push(card);
DTree app_cards = dtree_filter(cards, [](DTree item, String key) { return(item["section"].to_string() == "app"); });
DTree titles = dtree_map(app_cards, [](DTree item, String key) { DTree out; out = item["title"].to_string(); return(out); });
DTree grouped = dtree_group_by(cards, [](DTree item, String key) { return(item["section"].to_string()); });
DValue app_cards = dv_filter(cards, [](DValue item, String key) { return(item["section"].to_string() == "app"); });
DValue titles = dv_map(app_cards, [](DValue item, String key) { DValue out; out = item["title"].to_string(); return(out); });
DValue grouped = dv_group_by(cards, [](DValue item, String key) { return(item["section"].to_string()); });
<><html>
<head>
@@ -30,7 +30,7 @@ RENDER(Request& context)
<h2>Collection Helpers</h2>
<p>Small data-shaping helpers are useful for route lists, nav records, cards, and other render-adjacent structures.</p>
<div class="system-info"><h3>StringList route labels</h3><pre><?= join(labels, "\n") ?></pre></div>
<div class="system-info"><h3>DTree app card titles</h3><pre><?= json_encode(titles) ?></pre></div>
<div class="system-info"><h3>DValue app card titles</h3><pre><?= json_encode(titles) ?></pre></div>
<div class="system-info"><h3>Grouped cards</h3><pre><?= json_encode(grouped) ?></pre></div>
<details>
<summary>Request Parameters</summary>
+2 -2
View File
@@ -1,11 +1,11 @@
RENDER(Request& context)
{
DTree card_props;
DValue card_props;
card_props["title"] = "Component Example";
card_props["body"] = "This card body comes from context.props and is rendered through component().";
DTree named_props;
DValue named_props;
named_props["title"] = "Named Render Example";
named_props["body"] = "This content is rendered through the COMPONENT:BODY(Request& context) entry point.";
+1 -1
View File
@@ -78,7 +78,7 @@ void test_demo_render_restricted_json(Request& context, String title, String ris
{
context.set_status(403, "Restricted");
context.header["Content-Type"] = "application/json; charset=utf-8";
DTree payload;
DValue payload;
payload["ok"].set_bool(false);
payload["error"] = "restricted";
payload["title"] = title;
+16 -16
View File
@@ -2,13 +2,13 @@
RENDER(Request& context)
{
DTree t;
DValue t;
<>
<link rel="stylesheet" href='style.css'></link>
<h1>
<a href="index.uce">UCE Test</a>:
DTree
DValue
</h1>
<h2>Value Types</h2>
@@ -33,21 +33,21 @@ RENDER(Request& context)
<pre><?
DTree scalar_text;
DValue scalar_text;
scalar_text = "42.75";
print("text -> f64: ", scalar_text.to_f64(), "\n");
print("text -> u64: ", scalar_text.to_u64(), "\n");
print("text -> s64: ", scalar_text.to_s64(), "\n");
DTree bool_text;
DValue bool_text;
bool_text = "yes";
print("yes -> bool: ", bool_text.to_bool() ? "true" : "false", "\n");
DTree single_value_map;
DValue single_value_map;
single_value_map["value"] = "123";
print("{value:123} -> u64: ", single_value_map.to_u64(), "\n");
DTree headers;
DValue headers;
headers["Content-Type"] = "text/plain";
headers["X-Test"] = "123";
print("map -> StringMap:\n", var_dump(headers.to_stringmap()), "\n");
@@ -58,12 +58,12 @@ RENDER(Request& context)
<pre><?
DTree lookup;
DValue lookup;
print("has(user) before create: ", lookup.has("user") ? "true" : "false", "\n");
print("key(user) before create: ", lookup.key("user") ? "present" : "missing", "\n");
lookup.get_or_create("user")->set("Ada");
print("has(user) after create: ", lookup.has("user") ? "true" : "false", "\n");
if(DTree* user = lookup.key("user"))
if(DValue* user = lookup.key("user"))
print("key(user) after create: ", user->to_string(), "\n");
?></pre>
@@ -90,11 +90,11 @@ RENDER(Request& context)
<pre><?
DTree assoc_left;
DValue assoc_left;
assoc_left["name"] = "left";
assoc_left["shared"] = "left-value";
DTree assoc_right;
DValue assoc_right;
assoc_right["shared"] = "right-value";
assoc_right["extra"] = "new-value";
@@ -108,15 +108,15 @@ RENDER(Request& context)
<pre><?
DTree list_left;
DValue list_left;
list_left.set_array();
DTree a; a = "A"; list_left.push(a);
DTree b; b = "B"; list_left.push(b);
DValue a; a = "A"; list_left.push(a);
DValue b; b = "B"; list_left.push(b);
DTree list_right;
DValue list_right;
list_right.set_array();
DTree c; c = "C"; list_right.push(c);
DTree d; d = "D"; list_right.push(d);
DValue c; c = "C"; list_right.push(c);
DValue d; d = "D"; list_right.push(d);
print("left:\n", var_dump(list_left), "\n");
print("right:\n", var_dump(list_right), "\n");
+1 -1
View File
@@ -11,7 +11,7 @@ RENDER(Request& context)
test_demo_render_restricted_html(context, "File Append", "write to server-side files");
return;
}
DTree t;
DValue t;
<>
<link rel="stylesheet" href='style.css'></link>
+1 -1
View File
@@ -2,7 +2,7 @@
RENDER(Request& context)
{
DTree t;
DValue t;
<>
<link rel="stylesheet" href='style.css'></link>
+1 -1
View File
@@ -2,7 +2,7 @@
RENDER(Request& context)
{
DTree t;
DValue t;
<>
<link rel="stylesheet" href='style.css'></link>
+4 -4
View File
@@ -12,7 +12,7 @@ void render_card(String url, String title, String desc)
RENDER(Request& context)
{
DTree p;
DValue p;
p.set(context.params);
bool allow_server_demos = test_demo_request_allowed(context);
@@ -35,10 +35,10 @@ RENDER(Request& context)
<? if(allow_server_demos) { render_card("error-reporting.uce", "Error Reporting", "Error handling and output"); } ?>
<div class="grid-heading">Data Types &amp; Parsing</div>
<? render_card("dtree.uce", "DTree", "Dynamic hierarchical data tree"); ?>
<? render_card("dvalue.uce", "DValue", "Dynamic hierarchical data tree"); ?>
<? render_card("json.uce", "JSON", "Parse and encode JSON data"); ?>
<? render_card("xml.uce", "XML", "Structural XML encode/decode with DTree"); ?>
<? render_card("yaml.uce", "YAML", "Concise config files with DTree"); ?>
<? render_card("xml.uce", "XML", "Structural XML encode/decode with DValue"); ?>
<? render_card("yaml.uce", "YAML", "Concise config files with DValue"); ?>
<? render_card("preprocessor-comments.uce", "Preprocessor Comments", "Regression coverage for comment parsing in templates"); ?>
<? render_card("regex.uce", "Regular Expressions", "PCRE2 matching, captures, replacement, and splitting"); ?>
<? render_card("string.uce", "String", "String operations"); ?>
+2 -2
View File
@@ -2,13 +2,13 @@
RENDER(Request& context)
{
DTree t;
DValue t;
<>
<link rel="stylesheet" href='style.css'></link>
<h1>
<a href="index.uce">UCE Test</a>:
DTree/JSON
DValue/JSON
</h1>
JSON:
+2 -2
View File
@@ -1,6 +1,6 @@
RENDER(Request& context)
{
DTree options;
DValue options;
options["components"][":::warning"] = "components/markdown/warning";
options["components"]["node.code_block"] = "components/markdown/code_block";
@@ -9,7 +9,7 @@ RENDER(Request& context)
file_get_contents("markdown-example.md")
);
DTree ast = markdown_to_ast(markdown_src, options);
DValue ast = markdown_to_ast(markdown_src, options);
String html = markdown_to_html(markdown_src, options);
<>
+1 -1
View File
@@ -9,7 +9,7 @@ RENDER(Request& context)
test_demo_render_restricted_html(context, "MemcacheD", "inspect and mutate local memcached state");
return;
}
DTree t;
DValue t;
<>
<link rel="stylesheet" href='style.css'></link>
+3 -3
View File
@@ -28,13 +28,13 @@ COMPONENT:PROBE(Request& context)
RENDER(Request& context)
{
DTree first;
DValue first;
first["label"] = "First component call";
DTree second;
DValue second;
second["label"] = "Second component call in the same request";
DTree third;
DValue third;
third["label"] = "Third component call through unit_call(\"COMPONENT:PROBE\")";
<><html>
+3 -3
View File
@@ -19,8 +19,8 @@ void regex_bool_row(String label, bool result, bool expect)
RENDER(Request& context)
{
String text = "Contact ops@example.test or tag #uce, #docs, and café.";
DTree first_email = regex_search("(?<user>[A-Za-z0-9._%+-]+)@(?<host>[A-Za-z0-9.-]+)", text);
DTree tags = regex_search_all("#(?<tag>[A-Za-z0-9_]+)", text);
DValue first_email = regex_search("(?<user>[A-Za-z0-9._%+-]+)@(?<host>[A-Za-z0-9.-]+)", text);
DValue tags = regex_search_all("#(?<tag>[A-Za-z0-9_]+)", text);
StringList pieces = regex_split("\\s*,\\s*", "uce, components, markdown");
<>
@@ -38,7 +38,7 @@ RENDER(Request& context)
Regular Expressions
</h1>
<p>UCE regex functions use PCRE2 and return ordinary UCE strings, lists, and DTree values.</p>
<p>UCE regex functions use PCRE2 and return ordinary UCE strings, lists, and DValue values.</p>
<p>sample = <code><?= text ?></code></p>
<h2>Validation And Search</h2>
+2 -2
View File
@@ -23,7 +23,7 @@ RENDER(Request& context)
return;
}
DTree notes = sqlite_query(db, "select id, body, created_at from notes order by id desc limit 10");
DValue notes = sqlite_query(db, "select id, body, created_at from notes order by id desc limit 10");
String error = sqlite_error(db);
?><html>
<head>
@@ -41,7 +41,7 @@ RENDER(Request& context)
<? if(error != "ok" && error != "connected") { ?><pre><?= error ?></pre><? } ?>
</div>
<div class="test-grid">
<? notes.each([&](DTree note, String key) { ?>
<? notes.each([&](DValue note, String key) { ?>
<div class="test-card">
<strong>#<?= note["id"].to_string() ?> <?= note["created_at"].to_string() ?></strong>
<span><?= note["body"].to_string() ?></span>
+1 -1
View File
@@ -8,7 +8,7 @@ RENDER(Request& context)
test_demo_render_restricted_html(context, "Tasks", "spawn and inspect background tasks");
return;
}
DTree t;
DValue t;
String task_name = first(context.get["task-name"], "example-task");
+1 -1
View File
@@ -8,7 +8,7 @@ RENDER(Request& context)
test_demo_render_restricted_html(context, "Task repeat", "schedule recurring background tasks");
return;
}
DTree t;
DValue t;
String task_name = first(context.get["task-name"], "example-task");
+2 -2
View File
@@ -27,7 +27,7 @@ String unit_status_class(String compile_status, String error_status)
return("status-muted");
}
String unit_flag_label(DTree value)
String unit_flag_label(DValue value)
{
return(value.to_string() == "(true)" ? "✅" : "❌");
}
@@ -61,7 +61,7 @@ RENDER(Request& context)
if(selected_path == "" && unit_paths.size() > 0)
selected_path = unit_paths.front();
DTree selected_info = unit_info(selected_path);
DValue selected_info = unit_info(selected_path);
String selected_compile_status = selected_info["compile_status"].to_string();
String selected_error_status = selected_info["error_status"].to_string();
String selected_status_class = unit_status_class(selected_compile_status, selected_error_status);
+3 -3
View File
@@ -3,7 +3,7 @@
RENDER(Request& context)
{
bool allow_mutation = test_demo_request_allowed(context);
DTree payload;
DValue payload;
if(context.get["compile"] != "")
{
@@ -19,11 +19,11 @@ RENDER(Request& context)
payload["current"] = unit_info();
DTree units;
DValue units;
units.set_array();
for(auto& unit_path : units_list())
{
DTree item;
DValue item;
item = unit_path;
units.push(item);
}
+4 -4
View File
@@ -8,9 +8,9 @@ String clean_chat_field(String raw, u32 max_length)
return(value);
}
DTree chat_event(Request& context, String type, String body)
DValue chat_event(Request& context, String type, String body)
{
DTree event;
DValue event;
event["type"] = type;
event["body"] = body;
event["connection_id"] = context.params["WS_CONNECTION_ID"];
@@ -159,7 +159,7 @@ WS(Request& context)
return;
}
DTree payload = json_decode(context.in);
DValue payload = json_decode(context.in);
String type = clean_chat_field(payload["type"].to_string(), 24);
String name = clean_chat_field(payload["name"].to_string(), 32);
String body = clean_chat_field(payload["body"].to_string(), 500);
@@ -183,7 +183,7 @@ WS(Request& context)
context.connection["last_type"] = type;
context.connection["last_body"] = body;
context.connection["message_count"] = (f64)(message_count + 1);
DTree event = chat_event(context, "message", body);
DValue event = chat_event(context, "message", body);
ws_send(json_encode(event));
return;
}
+9 -9
View File
@@ -2,31 +2,31 @@
RENDER(Request& context)
{
DTree book;
DValue book;
book["name"] = "book";
book["attrs"]["id"] = "b1";
book["attrs"]["type"] = "reference";
DTree title;
DValue title;
title["name"] = "title";
title["text"] = "UCE & XML";
book["children"].push(title);
DTree chapter;
DValue chapter;
chapter["name"] = "chapter";
chapter["attrs"]["number"] = "1";
chapter["text"] = "Structural conversion without schema validation.";
book["children"].push(chapter);
String encoded = xml_encode(book);
DTree decoded = xml_decode(encoded);
DValue decoded = xml_decode(encoded);
DTree simple;
DValue simple;
simple["title"] = "Hello";
simple["count"] = "3";
String incoming = "<note priority=\"high\"><to>UCE</to><body><![CDATA[5 < 6]]></body><symbol>&#x41;&#66;</symbol></note>";
DTree incoming_tree = xml_decode(incoming);
DValue incoming_tree = xml_decode(incoming);
<>
<link rel="stylesheet" href='style.css'></link>
@@ -35,12 +35,12 @@ RENDER(Request& context)
XML
</h1>
<p><code>xml_encode()</code> and <code>xml_decode()</code> convert between XML strings and element-shaped <code>DTree</code> values without schema validation.</p>
<p><code>xml_encode()</code> and <code>xml_decode()</code> convert between XML strings and element-shaped <code>DValue</code> values without schema validation.</p>
<h2>Encoded Element Tree</h2>
<pre><?= encoded ?></pre>
<h2>Decoded DTree</h2>
<h2>Decoded DValue</h2>
<pre><?= json_encode(decoded) ?></pre>
<h2>Simple Map Encoding</h2>
@@ -49,7 +49,7 @@ RENDER(Request& context)
<h2>Decode Existing XML</h2>
<p>Input XML:</p>
<pre><?= incoming ?></pre>
<p>Decoded DTree:</p>
<p>Decoded DValue:</p>
<pre><?= json_encode(incoming_tree) ?></pre>
<p>
+7 -7
View File
@@ -12,19 +12,19 @@ RENDER(Request& context)
" - cache\n"
"message: |\n"
" Keep config files readable.\n"
" Load them as DTree values.\n";
" Load them as DValue values.\n";
DTree cfg = yaml_decode(source);
DValue cfg = yaml_decode(source);
String encoded = yaml_encode(cfg);
DTree roundtrip = yaml_decode(encoded);
DValue roundtrip = yaml_decode(encoded);
DTree generated;
DValue generated;
generated["database"]["host"] = "localhost";
generated["database"]["port"] = (f64)3306;
generated["features"]["components"].set_bool(true);
generated["features"]["markdown"].set_bool(true);
DTree theme;
DValue theme;
theme = "clean";
generated["themes"].push(theme);
theme = "compact";
@@ -37,12 +37,12 @@ RENDER(Request& context)
YAML
</h1>
<p><code>yaml_encode()</code> and <code>yaml_decode()</code> convert concise config-style YAML to and from <code>DTree</code> values.</p>
<p><code>yaml_encode()</code> and <code>yaml_decode()</code> convert concise config-style YAML to and from <code>DValue</code> values.</p>
<h2>Config Source</h2>
<pre><?= source ?></pre>
<h2>Decoded DTree</h2>
<h2>Decoded DValue</h2>
<pre><?= json_encode(cfg) ?></pre>
<h2>Encoded Again</h2>
+2 -2
View File
@@ -14,12 +14,12 @@ RENDER(Request& context)
mkdir(base);
mkdir(extract_dir);
DTree entries;
DValue entries;
entries["hello.txt"] = "Hello from a generated ZIP archive.\n";
entries["notes/readme.txt"] = "zip_create(), zip_list(), zip_read(), and zip_extract() are available to UCE pages.\n";
zip_create(archive, entries);
DTree listing = zip_list(archive);
DValue listing = zip_list(archive);
String hello = zip_read(archive, "hello.txt");
zip_extract(archive, extract_dir);
String extracted = file_get_contents(path_join(extract_dir, "notes/readme.txt"));