Commit 085a215d72581edad94b1274fd24fc954a5bc4b5

Thomas de Grivel 2024-10-08T01:51:37

test/ikc3/facts_with

diff --git a/http/http_request.c b/http/http_request.c
index 5b53b96..f282646 100644
--- a/http/http_request.c
+++ b/http/http_request.c
@@ -150,6 +150,7 @@ s_tag * http_request_buf_parse (s_tag *req, s_buf *buf)
     tmp_req.body.type = TAG_STR;
     if (! buf_read(buf, content_length_uw, &tmp_req.body.data.str))
       goto restore;
+    err_inspect_str(&tmp_req.body.data.str);
   }
   if (! tag_init_struct(&tmp, sym_1("HTTP.Request")))
     goto restore;
diff --git a/httpd/fx/app/controllers/fx_controller.kc3 b/httpd/fx/app/controllers/fx_controller.kc3
index 9e96f12..38d5bd3 100644
--- a/httpd/fx/app/controllers/fx_controller.kc3
+++ b/httpd/fx/app/controllers/fx_controller.kc3
@@ -184,22 +184,38 @@ defmodule FXController do
   }
 
   def properties_route = fn (req) {
-    slash = if Str.ends_with?(req.url, "/") do "" else "/" end
-    url = req.url + slash
-    if (Str.starts_with?(url, "/properties/")) do
-      url = Str.slice(url, 11, -1)
-      path = "fx" + url
+    url = if (req.url == "/properties/fx") do
+      req.url + "/"
+    else
+      req.url
+    end
+    if Str.starts_with?(url, "/properties/fx/") do
+      url = Str.slice(url, 12, -1)
       if (req.method == POST) do
-        property_create(path, property, value)
+        property = req.body.property_key
+        value = req.body.property_value
+        if property == void ||
+           value == void do
+          HTTPd.error_404_page(req)
+        else
+          property_create(url, property, value)
+        end
       else
         if (req.method == DELETE) do
-          property_delete(path, property, value)
+          property = req.body.property_key
+          value = req.body.property_value
+          if property == void ||
+            value == void do
+            HTTPd.error_404_page(req)
+          else
+            property_delete(url, property, value)
+          end
         else
-          error_405_page(req)
+          HTTPd.error_405_page(req)
         end
       end
     else
-      error_404_page(req)
+      HTTPd.error_404_page(req)
     end
   }
 
diff --git a/httpd/fx/app/templates/fx/properties.html.ekc3 b/httpd/fx/app/templates/fx/properties.html.ekc3
index 149943a..67aec07 100644
--- a/httpd/fx/app/templates/fx/properties.html.ekc3
+++ b/httpd/fx/app/templates/fx/properties.html.ekc3
@@ -23,7 +23,7 @@
 </table>
 <!-- if is_admin(auth_user) do -->
 <form action="/properties/<%= URL.escape(path) %>"
-      enctype="multipart/form-data"
+      enctype="application/x-www-form-urlencoded"
       method="POST">
   <div>
     <label for="property_key">Key</label>
diff --git a/libkc3/buf_inspect.c b/libkc3/buf_inspect.c
index e66ffc8..0a8362c 100644
--- a/libkc3/buf_inspect.c
+++ b/libkc3/buf_inspect.c
@@ -1333,28 +1333,26 @@ sw buf_inspect_cfn (s_buf *buf, const s_cfn *cfn)
 
 sw buf_inspect_cfn_size (s_pretty *pretty, const s_cfn *cfn)
 {
-  s_list *arg_type;
   sw r;
   sw result = 0;
   assert(cfn);
+  if ((r = buf_write_1_size(pretty, "cfn ")) < 0)
+    return r;
+  result += r;
+  if ((r = buf_inspect_sym_size(pretty, &cfn->result_type)) < 0)
+    return r;
+  result += r;
+  if ((r = buf_write_1_size(pretty, " ")) < 0)
+    return r;
+  result += r;
   if ((r = buf_inspect_str_size(pretty, &cfn->name->str)) < 0)
     return r;
   result += r;
-  if ((r = buf_write_1_size(pretty, "(")) < 0)
+  if ((r = buf_write_1_size(pretty, " ")) < 0)
     return r;
   result += r;
-  arg_type = cfn->arg_types;
-  while (arg_type) {
-    if ((r = buf_inspect_tag_size(pretty, &arg_type->tag)) < 0)
-      return r;
-    arg_type = list_next(arg_type);
-    if (arg_type) {
-      if ((r = buf_write_1_size(pretty, ", ")) < 0)
-        return r;
-      result += r;
-    }
-  }
-  if ((r = buf_write_1_size(pretty, ")")) < 0)
+  if ((r = buf_inspect_list_size(pretty, (const s_list * const *)
+                                 &cfn->arg_types)) < 0)
     return r;
   result += r;
   return result;
diff --git a/libkc3/inspect.c b/libkc3/inspect.c
index 99e6630..49f09b2 100644
--- a/libkc3/inspect.c
+++ b/libkc3/inspect.c
@@ -296,14 +296,14 @@ s_str * inspect_tag (const s_tag *tag, s_str *dest)
   assert(tag);
   assert(dest);
   if ((size = buf_inspect_tag_size(&pretty, tag)) < 0) {
-    err_puts("tag_inspect: size error");
-    assert(! "tag_inspect: size error");
+    err_puts("inspect_tag: buf_inspect_tag_size: error");
+    assert(! "inspect_tag: buf_inspect_tag_size: error");
     return NULL;
   }
   buf_init_alloc(&buf, size);
   if (buf_inspect_tag(&buf, tag) != size) {
-    err_puts("tag_inspect: inspect error");
-    assert(! "tag_inspect: inspect error");
+    err_puts("inspect_tag: buf_inspect_tag: error");
+    assert(! "inspect_tag: buf_inspect_tag: error");
     return NULL;
   }
   return buf_to_str(&buf, dest);
diff --git a/test/ikc3/facts_with.kc3 b/test/ikc3/facts_with.kc3
index c9f60a9..6535d06 100644
--- a/test/ikc3/facts_with.kc3
+++ b/test/ikc3/facts_with.kc3
@@ -8,3 +8,13 @@ Facts.with(Facts.env_db(), [[KC3, :operator, op = ?],
   puts("#{inspect(op)} #{inspect(sym)}")
   1
 end)
+quote Facts.with(Facts.env_db(), [[KC3, :operator, op = ?],
+                            [op, rel = ?, value = ?]], fn (fact) do
+  puts("#{inspect(op)} #{inspect(rel)} #{inspect(value)}")
+  2
+end)
+Facts.with(Facts.env_db(), [[KC3, :operator, op = ?],
+                            [op, rel = ?, value = ?]], fn (fact) do
+  puts("#{inspect(op)} #{inspect(rel)} #{inspect(value)}")
+  2
+end)
diff --git a/test/ikc3/facts_with.out.expected b/test/ikc3/facts_with.out.expected
index bec3f3f..0185d4f 100644
--- a/test/ikc3/facts_with.out.expected
+++ b/test/ikc3/facts_with.out.expected
@@ -34,3 +34,195 @@ operator_shift_left :<<
 operator_shift_right :>>
 operator_sub :-
 1
+Facts.with(Facts.env_db(), [[KC3, :operator, op = ?], [op, rel = ?, value = ?]], fn (fact) do
+  puts("#{inspect(op)} #{inspect(rel)} #{inspect(value)}")
+  2
+end)
+operator_add :arity 2
+operator_add :is_a :operator
+operator_add :operator_associativity :left
+operator_add :operator_precedence 12
+operator_add :sym :+
+operator_add :symbol_value cfn Tag "tag_add" (Tag, Tag, Result)
+operator_addi :arity 2
+operator_addi :is_a :operator
+operator_addi :operator_associativity :left
+operator_addi :operator_precedence 12
+operator_addi :sym :+i
+operator_addi :symbol_value cfn Tag "tag_addi" (Tag, Tag, Result)
+operator_and :arity 2
+operator_and :is_a :operator
+operator_and :operator_associativity :left
+operator_and :operator_precedence 5
+operator_and :sym :&&
+operator_and :symbol_value cfn Bool "kc3_and" (Tag, Tag, Result)
+operator_assign :arity 2
+operator_assign :is_a :operator
+operator_assign :operator_associativity :left
+operator_assign :operator_precedence 3
+operator_assign :sym :<-
+operator_assign :symbol_value cfn Tag "tag_assign" (Tag, Tag, Result)
+operator_assign_2 :arity 2
+operator_assign_2 :is_a :operator
+operator_assign_2 :operator_associativity :left
+operator_assign_2 :operator_precedence 3
+operator_assign_2 :sym :←
+operator_assign_2 :symbol_value cfn Tag "tag_assign" (Tag, Tag, Result)
+operator_band :arity 2
+operator_band :is_a :operator
+operator_band :operator_associativity :left
+operator_band :operator_precedence 8
+operator_band :sym :&
+operator_band :symbol_value cfn Tag "tag_band" (Tag, Tag, Result)
+operator_bnot :arity 1
+operator_bnot :is_a :operator
+operator_bnot :operator_associativity :right
+operator_bnot :operator_precedence 14
+operator_bnot :sym :~
+operator_bnot :symbol_value cfn Tag "tag_bnot" (Tag, Result)
+operator_bor :arity 2
+operator_bor :is_a :operator
+operator_bor :operator_associativity :left
+operator_bor :operator_precedence 6
+operator_bor :sym :bor
+operator_bor :symbol_value cfn Tag "tag_bor" (Tag, Tag, Result)
+operator_brackets :arity 2
+operator_brackets :is_a :operator
+operator_brackets :operator_associativity :left
+operator_brackets :operator_precedence 15
+operator_brackets :sym :"[]"
+operator_brackets :symbol_value cfn Tag "kc3_access" (Tag, List, Result)
+operator_bxor :arity 2
+operator_bxor :is_a :operator
+operator_bxor :operator_associativity :left
+operator_bxor :operator_precedence 7
+operator_bxor :sym :^
+operator_bxor :symbol_value cfn Tag "tag_bxor" (Tag, Tag, Result)
+operator_defstruct :arity 1
+operator_defstruct :is_a :operator
+operator_defstruct :operator_associativity :none
+operator_defstruct :operator_precedence 14
+operator_defstruct :sym :defstruct
+operator_defstruct :symbol_value cfn Tag "kc3_defstruct" (List, Result)
+operator_div :arity 2
+operator_div :is_a :operator
+operator_div :operator_associativity :left
+operator_div :operator_precedence 13
+operator_div :sym :/
+operator_div :symbol_value cfn Tag "tag_div" (Tag, Tag, Result)
+operator_eq :arity 2
+operator_eq :is_a :operator
+operator_eq :operator_associativity :left
+operator_eq :operator_precedence 9
+operator_eq :sym :==
+operator_eq :symbol_value cfn Bool "tag_eq" (Tag, Tag, Result)
+operator_equal :arity 2
+operator_equal :is_a :operator
+operator_equal :is_a :special_operator
+operator_equal :operator_associativity :right
+operator_equal :operator_precedence 2
+operator_equal :sym :=
+operator_equal :symbol_value cfn Tag "tag_equal" (Tag, Tag, Result)
+operator_gt :arity 2
+operator_gt :is_a :operator
+operator_gt :operator_associativity :left
+operator_gt :operator_precedence 10
+operator_gt :sym :>
+operator_gt :symbol_value cfn Bool "tag_gt" (Tag, Tag, Result)
+operator_gte :arity 2
+operator_gte :is_a :operator
+operator_gte :operator_associativity :left
+operator_gte :operator_precedence 10
+operator_gte :sym :>=
+operator_gte :symbol_value cfn Bool "tag_gte" (Tag, Tag, Result)
+operator_lt :arity 2
+operator_lt :is_a :operator
+operator_lt :operator_associativity :left
+operator_lt :operator_precedence 10
+operator_lt :sym :<
+operator_lt :symbol_value cfn Bool "tag_lt" (Tag, Tag, Result)
+operator_lte :arity 2
+operator_lte :is_a :operator
+operator_lte :operator_associativity :left
+operator_lte :operator_precedence 10
+operator_lte :sym :<=
+operator_lte :symbol_value cfn Bool "tag_lte" (Tag, Tag, Result)
+operator_mod :arity 2
+operator_mod :is_a :operator
+operator_mod :operator_associativity :left
+operator_mod :operator_precedence 13
+operator_mod :sym :mod
+operator_mod :symbol_value cfn Tag "tag_mod" (Tag, Tag, Result)
+operator_mul :arity 2
+operator_mul :is_a :operator
+operator_mul :operator_associativity :left
+operator_mul :operator_precedence 13
+operator_mul :sym :*
+operator_mul :symbol_value cfn Tag "tag_mul" (Tag, Tag, Result)
+operator_neg :arity 1
+operator_neg :is_a :operator
+operator_neg :operator_associativity :right
+operator_neg :operator_precedence 14
+operator_neg :sym :-
+operator_neg :symbol_value cfn Tag "tag_neg" (Tag, Result)
+operator_not :arity 1
+operator_not :is_a :operator
+operator_not :operator_associativity :right
+operator_not :operator_precedence 14
+operator_not :sym :!
+operator_not :symbol_value cfn Bool "tag_not" (Tag, Result)
+operator_not_eq :arity 2
+operator_not_eq :is_a :operator
+operator_not_eq :operator_associativity :left
+operator_not_eq :operator_precedence 9
+operator_not_eq :sym :!=
+operator_not_eq :symbol_value cfn Bool "tag_not_eq" (Tag, Tag, Result)
+operator_or :arity 2
+operator_or :is_a :operator
+operator_or :operator_associativity :left
+operator_or :operator_precedence 4
+operator_or :sym :||
+operator_or :symbol_value cfn Bool "kc3_or" (Tag, Tag, Result)
+operator_paren :arity 1
+operator_paren :is_a :operator
+operator_paren :operator_associativity :left
+operator_paren :operator_precedence 16
+operator_paren :sym :"()"
+operator_paren :symbol_value cfn Tag "tag_paren" (Tag, Result)
+operator_pin :arity 1
+operator_pin :is_a :operator
+operator_pin :operator_associativity :right
+operator_pin :operator_precedence 14
+operator_pin :sym :^
+operator_pin :symbol_value cfn Tag "kc3_identity" (Tag, Result)
+operator_require :arity 1
+operator_require :is_a :operator
+operator_require :operator_associativity :none
+operator_require :operator_precedence 14
+operator_require :sym :require
+operator_require :symbol_value cfn Bool "kc3_require" (Sym)
+operator_semicolumn :arity 2
+operator_semicolumn :is_a :operator
+operator_semicolumn :operator_associativity :left
+operator_semicolumn :operator_precedence 1
+operator_semicolumn :sym :";"
+operator_semicolumn :symbol_value cfn Tag "tag_semicolumn" (Tag, Tag, Result)
+operator_shift_left :arity 2
+operator_shift_left :is_a :operator
+operator_shift_left :operator_associativity :left
+operator_shift_left :operator_precedence 11
+operator_shift_left :sym :<<
+operator_shift_left :symbol_value cfn Tag "tag_shift_left" (Tag, Tag, Result)
+operator_shift_right :arity 2
+operator_shift_right :is_a :operator
+operator_shift_right :operator_associativity :left
+operator_shift_right :operator_precedence 11
+operator_shift_right :sym :>>
+operator_shift_right :symbol_value cfn Tag "tag_shift_right" (Tag, Tag, Result)
+operator_sub :arity 2
+operator_sub :is_a :operator
+operator_sub :operator_associativity :left
+operator_sub :operator_precedence 12
+operator_sub :sym :-
+operator_sub :symbol_value cfn Tag "tag_sub" (Tag, Tag, Result)
+2