]> Kevux Git Server - fll/commitdiff
Feature: Implement wrap support for IKI standard to be compliant with recent changes.
authorKevin Day <kevin@kevux.org>
Mon, 6 Mar 2023 01:16:21 +0000 (19:16 -0600)
committerKevin Day <kevin@kevux.org>
Mon, 6 Mar 2023 01:19:41 +0000 (19:19 -0600)
The wrap support for IKI (using open and close brackets '[' (U+005B) ']' (U+005D)) has been recently added to the specification.
This updates the project to be in compliance.

level_0/f_iki/c/iki.c
level_0/f_iki/c/iki/common.c
level_0/f_iki/c/iki/common.h
level_3/iki_write/c/common.c
level_3/iki_write/c/common.h
level_3/iki_write/c/iki_write.c
level_3/iki_write/c/private-write.c

index e9ca32bfbb5f6643a206ae63f83567148e0713bd..a39e5f3d845082236c1ed96c85941f22e15e9e68 100644 (file)
@@ -98,6 +98,7 @@ extern "C" {
     const f_array_length_t delimits_used = data->delimits.used;
 
     uint8_t quote = 0;
+    uint8_t wrapped = F_false; // 0x0 (false) = not wapped, 0x1 (true) = wrapped, 0x2 = valid wrapped.
 
     do {
 
@@ -130,8 +131,10 @@ extern "C" {
         }
 
         if (status == F_true) {
-          found_vocabulary.start = range->start;
-          found_vocabulary.stop = range->start;
+          if (!wrapped) {
+            found_vocabulary.start = range->start;
+            found_vocabulary.stop = range->start;
+          }
 
           status = f_utf_buffer_increment(*buffer, range, 1);
           if (F_status_is_error(status)) break;
@@ -141,6 +144,17 @@ extern "C" {
           break;
         }
 
+        // Wrapped must be followed by a valid vocabulary name.
+        if (buffer->string[range->start] == f_iki_syntax_wrap_open_s.string[0]) {
+          found_vocabulary.start = range->start;
+          found_vocabulary.stop = range->start;
+
+          wrapped = F_true;
+        }
+        else if (wrapped) {
+          wrapped = F_false;
+        }
+
         status = f_utf_buffer_increment(*buffer, range, 1);
         if (F_status_is_error(status)) break;
       } // while
@@ -165,6 +179,14 @@ extern "C" {
         }
 
         if (buffer->string[range->start] == f_iki_syntax_separator_s.string[0]) {
+
+          // Wrapped must close in a wrap close before the seperator.
+          if (wrapped == F_true) {
+            status = F_next;
+
+            break;
+          }
+
           do {
             status = f_utf_buffer_increment(*buffer, range, 1);
           } while (F_status_is_fine(status) && buffer->string[range->start] == f_iki_syntax_placeholder_s.string[0] && range->start <= range->stop && range->start < buffer->used);
@@ -240,6 +262,22 @@ extern "C" {
           if (status == F_true) break;
           if (F_status_is_error(status) || range->start > range->stop || range->start >= buffer->used || status == F_next) break;
         }
+        else if (buffer->string[range->start] == f_iki_syntax_wrap_open_s.string[0]) {
+          status = F_next;
+
+          break;
+        }
+        else if (wrapped == F_true && buffer->string[range->start] == f_iki_syntax_wrap_close_s.string[0]) {
+          wrapped = 0x2;
+          found_vocabulary.stop = range->start;
+        }
+        else if (wrapped == 0x2) {
+
+          // Wrapped close must be immediately before a separator (ignoring any placeholders in between).
+          status = F_next;
+
+          break;
+        }
         else {
           width_max = buffer->used - range->start;
 
@@ -259,9 +297,9 @@ extern "C" {
           if (status == F_true) {
             found_vocabulary.stop = range->start;
           }
-
-          // Not a valid IKI vocabulary name.
           else {
+
+            // Not a valid IKI vocabulary name.
             status = f_utf_buffer_increment(*buffer, range, 1);
             if (F_status_is_error(status)) break;
 
@@ -279,6 +317,7 @@ extern "C" {
 
       if (status == F_next) {
         quote = 0;
+        wrapped = F_false;
 
         continue;
       }
@@ -318,8 +357,8 @@ extern "C" {
             data->variable.array[data->variable.used].start = found_vocabulary.start;
             data->variable.array[data->variable.used++].stop = range->start;
 
-            data->vocabulary.array[data->vocabulary.used].start = found_vocabulary.start;
-            data->vocabulary.array[data->vocabulary.used++].stop = found_vocabulary.stop;
+            data->vocabulary.array[data->vocabulary.used].start = wrapped ? found_vocabulary.start + f_iki_syntax_wrap_open_s.used : found_vocabulary.start;
+            data->vocabulary.array[data->vocabulary.used++].stop = wrapped ? found_vocabulary.stop - f_iki_syntax_wrap_close_s.used : found_vocabulary.stop;
 
             data->content.array[data->content.used].start = found_content;
             data->content.array[data->content.used++].stop = range->start - 1;
@@ -384,8 +423,8 @@ extern "C" {
                   data->variable.array[data->variable.used].start = found_vocabulary.start;
                   data->variable.array[data->variable.used++].stop = range->start;
 
-                  data->vocabulary.array[data->vocabulary.used].start = found_vocabulary.start;
-                  data->vocabulary.array[data->vocabulary.used++].stop = found_vocabulary.stop;
+                  data->vocabulary.array[data->vocabulary.used].start = wrapped ? found_vocabulary.start + f_iki_syntax_wrap_open_s.used : found_vocabulary.start;
+                  data->vocabulary.array[data->vocabulary.used++].stop = wrapped ? found_vocabulary.stop - f_iki_syntax_wrap_close_s.used : found_vocabulary.stop;
 
                   data->content.array[data->content.used].start = found_content;
                   data->content.array[data->content.used++].stop = range->start - 1;
@@ -415,6 +454,7 @@ extern "C" {
         } // while
 
         quote = 0;
+        wrapped = F_false;
       }
 
       if (F_status_is_error(status) || range->start > range->stop || range->start >= buffer->used) break;
index 566a314e6beb7ebb1f4cef33dfbe2a87b75c4d69..5f9daeffe8657105356bec646c14f9caec65d7c2 100644 (file)
@@ -11,6 +11,8 @@ extern "C" {
   const f_string_static_t f_iki_syntax_quote_double_s = macro_f_string_static_t_initialize(F_iki_syntax_quote_double_s, 0, F_iki_syntax_quote_double_s_length);
   const f_string_static_t f_iki_syntax_quote_single_s = macro_f_string_static_t_initialize(F_iki_syntax_quote_single_s, 0, F_iki_syntax_quote_single_s_length);
   const f_string_static_t f_iki_syntax_slash_s = macro_f_string_static_t_initialize(F_iki_syntax_slash_s, 0, F_iki_syntax_slash_s_length);
+  const f_string_static_t f_iki_syntax_wrap_open_s = macro_f_string_static_t_initialize(F_iki_syntax_wrap_open_s, 0, F_iki_syntax_wrap_open_s_length);
+  const f_string_static_t f_iki_syntax_wrap_close_s = macro_f_string_static_t_initialize(F_iki_syntax_wrap_close_s, 0, F_iki_syntax_wrap_close_s_length);
 #endif //_di_f_iki_syntax_
 
 #ifndef _di_f_iki_vocabulary_0001_s_
index 5fbe2e06dfc04f017734c8e2ac67a69d80ea143a..727440c42c887c57c5dbf3fdeb6636c6f1f5f089 100644 (file)
@@ -43,18 +43,24 @@ extern "C" {
   #define F_iki_syntax_quote_double_s "\""
   #define F_iki_syntax_quote_single_s "\'"
   #define F_iki_syntax_slash_s        "\\"
+  #define F_iki_syntax_wrap_open_s    "["
+  #define F_iki_syntax_wrap_close_s   "]"
 
   #define F_iki_syntax_separator_s_length    1
   #define F_iki_syntax_placeholder_s_length  1
   #define F_iki_syntax_quote_double_s_length 1
   #define F_iki_syntax_quote_single_s_length 1
   #define F_iki_syntax_slash_s_length        1
+  #define F_iki_syntax_wrap_open_s_length    1
+  #define F_iki_syntax_wrap_close_s_length   1
 
   extern const f_string_static_t f_iki_syntax_separator_s;
   extern const f_string_static_t f_iki_syntax_placeholder_s;
   extern const f_string_static_t f_iki_syntax_quote_double_s;
   extern const f_string_static_t f_iki_syntax_quote_single_s;
   extern const f_string_static_t f_iki_syntax_slash_s;
+  extern const f_string_static_t f_iki_syntax_wrap_open_s;
+  extern const f_string_static_t f_iki_syntax_wrap_close_s;
 #endif //_di_f_iki_syntax_
 
 #ifndef _di_f_iki_vocabulary_0001_
index c9e6d7b790b425e95a8bc99ccb33c313df083c5a..d6cca2c443bd6583bf0043e66b598be3d52794a4 100644 (file)
@@ -19,12 +19,14 @@ extern "C" {
   const f_string_static_t iki_write_short_file_s = macro_f_string_static_t_initialize(IKI_WRITE_short_file_s, 0, IKI_WRITE_short_file_s_length);
   const f_string_static_t iki_write_short_object_s = macro_f_string_static_t_initialize(IKI_WRITE_short_object_s, 0, IKI_WRITE_short_object_s_length);
   const f_string_static_t iki_write_short_single_s = macro_f_string_static_t_initialize(IKI_WRITE_short_single_s, 0, IKI_WRITE_short_single_s_length);
+  const f_string_static_t iki_write_short_wrap_s = macro_f_string_static_t_initialize(IKI_WRITE_short_wrap_s, 0, IKI_WRITE_short_wrap_s_length);
 
   const f_string_static_t iki_write_long_content_s = macro_f_string_static_t_initialize(IKI_WRITE_long_content_s, 0, IKI_WRITE_long_content_s_length);
   const f_string_static_t iki_write_long_double_s = macro_f_string_static_t_initialize(IKI_WRITE_long_double_s, 0, IKI_WRITE_long_double_s_length);
   const f_string_static_t iki_write_long_file_s = macro_f_string_static_t_initialize(IKI_WRITE_long_file_s, 0, IKI_WRITE_long_file_s_length);
   const f_string_static_t iki_write_long_object_s = macro_f_string_static_t_initialize(IKI_WRITE_long_object_s, 0, IKI_WRITE_long_object_s_length);
   const f_string_static_t iki_write_long_single_s = macro_f_string_static_t_initialize(IKI_WRITE_long_single_s, 0, IKI_WRITE_long_single_s_length);
+  const f_string_static_t iki_write_long_wrap_s = macro_f_string_static_t_initialize(IKI_WRITE_long_wrap_s, 0, IKI_WRITE_long_wrap_s_length);
 #endif // _di_iki_write_parameters_
 
 #ifdef __cplusplus
index 7ff513fb64bf34ebf967b9bf1da425eb2cfdf0a7..91553e620ac7e19cc58028a0fdff95a5af5823f0 100644 (file)
@@ -75,36 +75,42 @@ extern "C" {
   #define IKI_WRITE_short_file_s    "f"
   #define IKI_WRITE_short_object_s  "o"
   #define IKI_WRITE_short_single_s  "s"
+  #define IKI_WRITE_short_wrap_s    "w"
 
   #define IKI_WRITE_long_content_s "content"
   #define IKI_WRITE_long_double_s  "double"
   #define IKI_WRITE_long_file_s    "file"
   #define IKI_WRITE_long_object_s  "object"
   #define IKI_WRITE_long_single_s  "single"
+  #define IKI_WRITE_long_wrap_s    "wrap"
 
   #define IKI_WRITE_short_content_s_length 1
   #define IKI_WRITE_short_double_s_length  1
   #define IKI_WRITE_short_file_s_length    1
   #define IKI_WRITE_short_object_s_length  1
   #define IKI_WRITE_short_single_s_length  1
+  #define IKI_WRITE_short_wrap_s_length    1
 
   #define IKI_WRITE_long_content_s_length 7
   #define IKI_WRITE_long_double_s_length  6
   #define IKI_WRITE_long_file_s_length    4
   #define IKI_WRITE_long_object_s_length  6
   #define IKI_WRITE_long_single_s_length  6
+  #define IKI_WRITE_long_wrap_s_length    4
 
   extern const f_string_static_t iki_write_short_content_s;
   extern const f_string_static_t iki_write_short_double_s;
   extern const f_string_static_t iki_write_short_file_s;
   extern const f_string_static_t iki_write_short_object_s;
   extern const f_string_static_t iki_write_short_single_s;
+  extern const f_string_static_t iki_write_short_wrap_s;
 
   extern const f_string_static_t iki_write_long_content_s;
   extern const f_string_static_t iki_write_long_double_s;
   extern const f_string_static_t iki_write_long_file_s;
   extern const f_string_static_t iki_write_long_object_s;
   extern const f_string_static_t iki_write_long_single_s;
+  extern const f_string_static_t iki_write_long_wrap_s;
 
   enum {
     iki_write_parameter_help_e,
@@ -124,6 +130,7 @@ extern "C" {
     iki_write_parameter_file_e,
     iki_write_parameter_object_e,
     iki_write_parameter_single_e,
+    iki_write_parameter_wrap_e,
   };
 
   #define iki_write_console_parameter_t_initialize \
@@ -144,9 +151,10 @@ extern "C" {
       macro_f_console_parameter_t_initialize(iki_write_short_file_s.string, iki_write_long_file_s.string, 0, 1, f_console_type_normal_e), \
       macro_f_console_parameter_t_initialize(iki_write_short_object_s.string, iki_write_long_object_s.string, 0, 1, f_console_type_normal_e), \
       macro_f_console_parameter_t_initialize(iki_write_short_single_s.string, iki_write_long_single_s.string, 0, 0, f_console_type_normal_e), \
+      macro_f_console_parameter_t_initialize(iki_write_short_wrap_s.string, iki_write_long_wrap_s.string, 0, 0, f_console_type_normal_e), \
     }
 
-  #define iki_write_total_parameters_d 16
+  #define iki_write_total_parameters_d 17
 #endif // _di_iki_write_parameters_
 
 #ifdef __cplusplus
index 1eb161a6c0138571209511c70af63786d2cea5c2..198ac9e727113f363cb484420b33aa9e562d1653 100644 (file)
@@ -56,6 +56,7 @@ extern "C" {
     fll_program_print_help_option(file, context, iki_write_short_file_s, iki_write_long_file_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, "   Specify a file to send data to.");
     fll_program_print_help_option(file, context, iki_write_short_object_s, iki_write_long_object_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " The Object to write.");
     fll_program_print_help_option(file, context, iki_write_short_single_s, iki_write_long_single_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Use single quotes.");
+    fll_program_print_help_option(file, context, iki_write_short_wrap_s, iki_write_long_wrap_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, "   Wrap the vocabulary name.");
 
     fll_program_print_help_usage(file, context, iki_write_program_name_s, f_string_empty_s);
 
index 28c197641361d325496dea690e8e523a9fd0d3f1..91e1807545e8137c73749988d67c899558f8f83b 100644 (file)
@@ -54,7 +54,12 @@ extern "C" {
       return F_status_set_error(F_failure);
     }
 
-    fl_print_format("%Q%r%r%Q%r", output.stream, object, f_iki_syntax_separator_s, data->quote, *escaped, data->quote);
+    if (data->main->parameters.array[iki_write_parameter_wrap_e].result & f_console_result_found_e) {
+      fl_print_format("%r%Q%r%r%r%Q%r", output.stream, f_iki_syntax_wrap_open_s, object, f_iki_syntax_wrap_close_s, f_iki_syntax_separator_s, data->quote, *escaped, data->quote);
+    }
+    else {
+      fl_print_format("%Q%r%r%Q%r", output.stream, object, f_iki_syntax_separator_s, data->quote, *escaped, data->quote);
+    }
 
     return F_none;
   }