]> 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:18:01 +0000 (19:18 -0600)
committerKevin Day <kevin@kevux.org>
Mon, 6 Mar 2023 01:19:32 +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/main/common.c
level_3/iki_write/c/main/common/string.c
level_3/iki_write/c/main/common/string.h
level_3/iki_write/c/main/common/type.h
level_3/iki_write/c/main/print.c
level_3/iki_write/c/main/process.c

index 264e4ef39e904a9e726423631dbcd50b93b6c8f2..85b2ce78d428fb4240c96ee60b640f6361600b5d 100644 (file)
@@ -95,6 +95,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 {
 
@@ -122,8 +123,10 @@ extern "C" {
         }
 
         if (state->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;
+          }
 
           state->status = f_utf_buffer_increment(*buffer, range, 1);
           if (F_status_is_error(state->status)) break;
@@ -133,6 +136,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;
+        }
+
         state->status = f_utf_buffer_increment(*buffer, range, 1);
         if (F_status_is_error(state->status)) break;
       } // while
@@ -152,6 +166,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) {
+            state->status = F_next;
+
+            break;
+          }
+
           do {
             state->status = f_utf_buffer_increment(*buffer, range, 1);
           } while (F_status_is_fine(state->status) && buffer->string[range->start] == f_iki_syntax_placeholder_s.string[0] && range->start <= range->stop && range->start < buffer->used);
@@ -222,6 +244,22 @@ extern "C" {
           if (state->status == F_true) break;
           if (F_status_is_error(state->status) || range->start > range->stop || range->start >= buffer->used || state->status == F_next) break;
         }
+        else if (buffer->string[range->start] == f_iki_syntax_wrap_open_s.string[0]) {
+          state->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).
+          state->status = F_next;
+
+          break;
+        }
         else {
           width_max = buffer->used - range->start;
 
@@ -241,9 +279,9 @@ extern "C" {
           if (state->status == F_true) {
             found_vocabulary.stop = range->start;
           }
-
-          // Not a valid IKI vocabulary name.
           else {
+
+            // Not a valid IKI vocabulary name.
             state->status = f_utf_buffer_increment(*buffer, range, 1);
             if (F_status_is_error(state->status)) break;
 
@@ -261,6 +299,7 @@ extern "C" {
 
       if (state->status == F_next) {
         quote = 0;
+        wrapped = F_false;
 
         continue;
       }
@@ -295,8 +334,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;
@@ -368,8 +407,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;
@@ -406,6 +445,7 @@ extern "C" {
         } // while
 
         quote = 0;
+        wrapped = F_false;
       }
 
       if (F_status_is_error(state->status) || range->start > range->stop || range->start >= buffer->used) break;
index dc5a66d6050675a5f3b56f639c2771b4b05d7c9c..c94f79feb8ebcb7b82581d6cbd65c9d8a50f42ab 100644 (file)
@@ -29,6 +29,14 @@ extern "C" {
   #ifndef _di_f_iki_syntax_slash_s_
     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);
   #endif // _di_f_iki_syntax_slash_s_
+
+  #ifndef _di_f_iki_syntax_wrap_open_s_
+    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);
+  #endif // _di_f_iki_syntax_wrap_open_s_
+
+  #ifndef _di_f_iki_syntax_wrap_close_s_
+    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_wrap_close_s_
 #endif //_di_f_iki_syntax_s_
 
 #ifndef _di_f_iki_vocabulary_0001_s_
index 15f4a0aa9d01754edef5fe65f24e7bba36fc3b28..f973c026378a349dfe0a5806c512da7c9f060b4e 100644 (file)
@@ -60,6 +60,8 @@ extern "C" {
   #define F_iki_syntax_quote_double_s   F_string_ascii_quote_double_s
   #define F_iki_syntax_quote_single_s   F_string_ascii_quote_single_s
   #define F_iki_syntax_slash_s          F_string_ascii_slash_backward_s
+  #define F_iki_syntax_wrap_open_s      F_string_ascii_bracket_open_s
+  #define F_iki_syntax_wrap_close_s     F_string_ascii_bracket_close_s
 
   #define F_iki_syntax_separator_s_length      F_string_ascii_colon_s_length
   #define F_iki_syntax_placeholder_s_length    F_string_placeholder_s_length
@@ -67,6 +69,8 @@ extern "C" {
   #define F_iki_syntax_quote_double_s_length   F_string_ascii_quote_double_s_length
   #define F_iki_syntax_quote_single_s_length   F_string_ascii_quote_single_s_length
   #define F_iki_syntax_slash_s_length          F_string_ascii_slash_backward_s_length
+  #define F_iki_syntax_wrap_open_s_length      F_string_ascii_bracket_open_s_length
+  #define F_iki_syntax_wrap_close_s_length     F_string_ascii_bracket_close_s_length
 
   #ifndef _di_f_iki_syntax_separator_s_
     extern const f_string_static_t f_iki_syntax_separator_s;
@@ -91,6 +95,14 @@ extern "C" {
   #ifndef _di_f_iki_syntax_slash_s_
     extern const f_string_static_t f_iki_syntax_slash_s;
   #endif // _di_f_iki_syntax_slash_s_
+
+  #ifndef _di_f_iki_syntax_wrap_open_s_
+    extern const f_string_static_t f_iki_syntax_wrap_open_s;
+  #endif // _di_f_iki_syntax_wrap_open_s_
+
+  #ifndef _di_f_iki_syntax_wrap_close_s_
+    extern const f_string_static_t f_iki_syntax_wrap_close_s;
+  #endif // _di_f_iki_syntax_wrap_close_s_
 #endif //_di_f_iki_syntax_s_
 
 #ifndef _di_f_iki_vocabulary_0001_s_
index 5facea56e389ddf71bdc80ff6e0d79296f6765ba..4a3d5c05cac00413b39701dab42cb3610ff7abbf 100644 (file)
@@ -229,6 +229,10 @@ extern "C" {
       return;
     }
 
+    if (main->parameters.array[iki_write_parameter_wrap_e].result & f_console_result_found_e) {
+      setting->flag |= iki_write_main_flag_wrap_e;
+    }
+
     setting->quote = f_iki_syntax_quote_double_s;
 
     if (main->parameters.array[iki_write_parameter_double_e].result & f_console_result_found_e) {
index 28d8e0aad648b47b9afde2983843b14e55de1245..d68a65e16be403db0a8f47cd9e24b6764ccfa8d4 100644 (file)
@@ -24,6 +24,7 @@ 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_backtick_s = macro_f_string_static_t_initialize(IKI_WRITE_long_backtick_s, 0, IKI_WRITE_long_backtick_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);
@@ -31,6 +32,7 @@ extern "C" {
   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_parameter_s_
 
 #ifdef __cplusplus
index 44d1a20f8f89ee8fcb560e436f19083db1d1e963..12f736031c2c48addcd5abd8e30176f0f1d37e18 100644 (file)
@@ -80,6 +80,7 @@ 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_backtick_s "backtick"
   #define IKI_WRITE_long_content_s  "content"
@@ -87,6 +88,7 @@ extern "C" {
   #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_backtick_s_length 1
   #define IKI_WRITE_short_content_s_length  1
@@ -94,6 +96,7 @@ extern "C" {
   #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_backtick_s_length 8
   #define IKI_WRITE_long_content_s_length  7
@@ -101,6 +104,7 @@ extern "C" {
   #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_backtick_s;
   extern const f_string_static_t iki_write_short_content_s;
@@ -108,6 +112,7 @@ extern "C" {
   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_backtick_s;
   extern const f_string_static_t iki_write_long_content_s;
@@ -115,6 +120,7 @@ extern "C" {
   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;
 #endif // _di_iki_write_parameter_s_
 
 #ifdef __cplusplus
index 03efbb0a510fd8ae067cf76a7da355df97794fd7..a1be8f805fa8f53c3bd345aa16c1a19aaa3e36e8 100644 (file)
@@ -44,6 +44,7 @@ extern "C" {
  *   - object:      The Object being written is specified.
  *   - print_first: When set, the first character printing logic is to be processed (this is usually automatic).
  *   - version:     Print version.
+ *   - wrap:        Wrap the vocabulary.
  */
 #ifndef _di_iki_write_main_flag_e_
   enum {
@@ -55,6 +56,7 @@ extern "C" {
     iki_write_main_flag_object_e      = 0x10,
     iki_write_main_flag_print_first_e = 0x20,
     iki_write_main_flag_version_e     = 0x40,
+    iki_write_main_flag_wrap_e        = 0x80,
   }; // enum
 #endif // _di_iki_write_main_flag_e_
 
@@ -83,6 +85,7 @@ extern "C" {
     iki_write_parameter_file_e,
     iki_write_parameter_object_e,
     iki_write_parameter_single_e,
+    iki_write_parameter_wrap_e,
   }; // enum
 
   #define iki_write_console_parameter_t_initialize \
@@ -107,9 +110,10 @@ extern "C" {
       macro_f_console_parameter_t_initialize_3(iki_write_short_file_s,     iki_write_long_file_s,     1, f_console_flag_normal_e), \
       macro_f_console_parameter_t_initialize_3(iki_write_short_object_s,   iki_write_long_object_s,   1, f_console_flag_normal_e), \
       macro_f_console_parameter_t_initialize_3(iki_write_short_single_s,   iki_write_long_single_s,   0, f_console_flag_normal_e), \
+      macro_f_console_parameter_t_initialize_3(iki_write_short_wrap_s,     iki_write_long_wrap_s,     0, f_console_flag_normal_e), \
     }
 
-  #define iki_write_total_parameters_d 19
+  #define iki_write_total_parameters_d 20
 #endif // _di_iki_write_parameter_e_
 
 /**
index 3af6e4df7a69a5e7514c5304650816cc5626f482..080459f97223efcdb89f09a5ccbb215e7782e503 100644 (file)
@@ -34,6 +34,7 @@ extern "C" {
     fll_program_print_help_option(print, iki_write_short_file_s, iki_write_long_file_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, "    Specify a file to send data to.");
     fll_program_print_help_option(print, iki_write_short_object_s, iki_write_long_object_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, "  The Object to write.");
     fll_program_print_help_option(print, iki_write_short_single_s, iki_write_long_single_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, "  Use single quotes.");
+    fll_program_print_help_option(print, iki_write_short_wrap_s, iki_write_long_wrap_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, "    Wrap the vocabulary name.");
 
     f_print_dynamic_raw(f_string_eol_s, print.to);
     f_print_dynamic_raw(f_string_eol_s, print.to);
index ef7d6b805be93326a1b0dae862a021a0537af2cb..a25ede5a7a8aa17697400de5d3ab264c97e89798 100644 (file)
@@ -44,7 +44,12 @@ extern "C" {
       return;
     }
 
-    fl_print_format("%Q%r%r%Q%r", main->output.to, object, f_iki_syntax_separator_s, setting->quote, setting->escaped, setting->quote);
+    if (setting->flag & iki_write_main_flag_wrap_e) {
+      fl_print_format("%r%Q%r%r%r%Q%r", main->output.to, f_iki_syntax_wrap_open_s, object, f_iki_syntax_wrap_close_s, f_iki_syntax_separator_s, setting->quote, setting->escaped, setting->quote);
+    }
+    else {
+      fl_print_format("%Q%r%r%Q%r", main->output.to, object, f_iki_syntax_separator_s, setting->quote, setting->escaped, setting->quote);
+    }
   }
 #endif // _di_iki_write_process_