Posted to tcl by mookie at Mon Aug 03 20:09:06 GMT 2026view raw

  1. ;# This file reads the .prompt files, and dispatches data accordingly "prompt_read.ix"
  2. namespace eval crystal::parser { puts "-> [file tail [info script]]" }
  3. namespace eval crystal::parser {
  4. namespace export {[a-z]*}
  5. namespace ensemble create
  6. }
  7.  
  8. ;## Initalise our dispatch
  9. ;# We do this within crystal.ix
  10. ;## [crystal::parser::init_dispatch]
  11. proc crystal::parser {args} {
  12. ;# Switch: [crystal::lidx $args 0]
  13. ;# execute dependednt on the first argurement given
  14. ;# this result should only come from the netdisc
  15. ;# /// FEATURE_IDEA : Implement arg_source
  16. ;# Case: load
  17. ;# This loads the prompt file
  18. switch [lindex $args 0] {
  19. morph { crystal::debug 0 "loaded" "prompted file"
  20. variable base16_viewer_key [lindex $args 1] ;# Viewer Key
  21. variable base32_prompt_script [lindex $args 2] ;# neoncrystal_online
  22. variable base32_prompt_file [format "%s.prompt" [lindex $args 2]] ;# example: neoncrystal_online.prompt
  23.  
  24. # Get our prompt/craft paths
  25. variable base32_craft_script_path [crystal::2Base [crystal::hextdict "retrieve_from" "crystal" "craftsheets" "$base32_prompt_script"]]
  26. variable base32_prompt_script_path [crystal::2Base [crystal::hextdict "retrieve_from" "crystal" "promptsheets" "$base32_prompt_script"]]
  27. #
  28. crystal::debug 0 $base32_prompt_script "Prompt script path"
  29.  
  30. switch [crystal::hextdict "retrieve_from" $base32_craft_script_path "$base32_prompt_file" "file_scanned"] {
  31. 0 {
  32. ;#### modified time setup
  33. ;# /forest/crystal_forest/crystal/main/netdisc_system/craft/system_resources.craft
  34. ;# > system_resources.prompt -> file_mtime
  35. ;# > system_resources.prompt -> file_scanned
  36. ;# > prompt_script -> line_index -> 0 ..
  37. ;# > craft_script -> line_index -> 1 ..
  38. crystal::hextdict "insert_to" $base32_craft_script_path "$base32_prompt_file" "file_mtime" [file mtime $base32_prompt_script_path]
  39. crystal::hextdict "insert_to" $base32_craft_script_path "$base32_prompt_file" "file_scanned" 1
  40. #####
  41. set fh [open $base32_prompt_script_path r] ;# establish our file handlder
  42. set index 0 ;# set our index
  43. ;# Gather our lines in the file
  44. while {[gets $fh base32_file_line] >= 0} {
  45. crystal::hextdict "insert_to" "$base32_craft_script_path" "prompt_script" "$index" "$base32_file_line"
  46. incr index
  47. } ;# end while
  48. ;#
  49. close $fh
  50. #
  51. crystal::debug 0 [crystal::hextdict "list" "$base32_craft_script_path" "prompt_script"] "prompt line indexes"
  52. }
  53. 31 { crystal::debug 0 "[crystal::hextdict "retrieve_from" "$base32_craft_script_path" "$base32_prompt_file" "file_mtime"]" "our prompt modifed time" }
  54. } ;# end switch [crystal::hextdict "retrieve_from" "crystal" "$base32_prompt_file" "scanned"]
  55. ;####
  56. crystal::parser::parse $base16_viewer_key $base32_prompt_script
  57. }
  58. } ;# end switch
  59. } ;# end proc
  60.  
  61. proc crystal::parser::parse {base32_viewer_key base32_prompt_script} {
  62. # Get our prompt/craft paths
  63. variable base32_craft_script_path [crystal::2Base [crystal::hextdict "retrieve_from" "crystal" "craftsheets" "$base32_prompt_script"]]
  64. variable base32_prompt_script_path [crystal::2Base [crystal::hextdict "retrieve_from" "crystal" "promptsheets" "$base32_prompt_script"]]
  65. variable base32_prompt_file [format "%s.prompt" base32_prompt_script] ;# example: neoncrystal_online.prompt
  66. ;#
  67. crystal::debug 0 $base32_prompt_script_path "Prompt script loaded path"
  68.  
  69. # Expiremental - Set our "default key when none has been defined"
  70. switch $base32_viewer_key { ;# Set default viewer
  71. "" { set base32_viewer_key "00000000000000000000000000000000000000000000000000000000000000FF" }
  72. }
  73.  
  74. ;# raw file mtime
  75. variable base16_file_mtime [crystal::2Hex [file mtime $base32_prompt_script_path]]
  76. ;# neoncrystal_online.craft
  77. ;# > neoncrystal_online.prompt -> file_mtime
  78. variable base16_crystal_mtime [crystal::hextdict "retrieve_from" $base32_craft_script_path "$base32_prompt_file" "file_mtime"]
  79.  
  80. crystal::debug 0 "$base16_file_mtime" "$base16_crystal_mtime"
  81. crystal::debug 0 [expr {$base16_file_mtime != $base16_crystal_mtime}] "mtime check"
  82.  
  83. ;# Switch: [expr {$base16_file_mtime != $base16_crystal_mtime}]
  84. ;# Checks our file mtime with our crystal time
  85. ;# When the modified time has changed update our dictionary with the new file
  86. ;# Case: 1
  87. ;# Reset our prompt_dictionary
  88. ;# Set our file handler to that of the script path
  89. ;# Set the index as 0
  90. switch [expr {$base16_file_mtime != $base16_crystal_mtime}] {
  91. 1 { ;# mtime differs, reread file and rebuild dictionary
  92. ;# Read our file in to a dictionary
  93. ;#
  94. set fh [open $base32_prompt_script_path r] ;# establish our file handlder
  95. set index 0 ;# set our index
  96.  
  97. # Clean our old stale prompt lines
  98. crystal::hextdict "reset" $base32_craft_script_path prompt_script
  99. # crystal::hextdict "reset" $base32_craft_script_path "prompt_lines"
  100. #
  101. while {[gets $fh base32_file_line] >= 0} {
  102. crystal::hextdict "insert_to" "$base32_craft_script_path" "prompt_script" "$index" "$base32_file_line"
  103. incr index
  104. }
  105. close $fh
  106. ;# End read
  107.  
  108. ;# Update our modified time for the file
  109. crystal::hextdict "insert_to" $base32_craft_script_path "$base32_prompt_file" "file_mtime" [file mtime $base32_prompt_script_path]
  110. }
  111. } ;# end switch [expr {$base16_file_mtime != $base16_crystal_mtime}]
  112.  
  113. ;# Foreach index in our prompt_line dictionary
  114. foreach index [crystal::hextdict "list" "$base32_craft_script_path" "prompt_script"] {
  115. set base32_file_line [crystal::hextdict "retrieve_from_32" "$base32_craft_script_path" "prompt_script" "[crystal::2Base $index]"]
  116. crystal::debug 0 $base32_file_line "file line"
  117.  
  118. ;# Switch: $base32_file_line
  119. ;# This switch handles the file line
  120. ;# Case: "" - This is an empty Line, skip
  121. ;# Skip empty lines
  122. switch $base32_file_line {
  123. "" { break }
  124. default {
  125. variable base32_parsed_string [crystal::parser::hex_scope $base32_file_line]
  126.  
  127. crystal::debug 0 "$base32_parsed_string" "base32_parsed_string"
  128.  
  129. ;# Cleansing - remove our braces
  130. ;# This is where remove our { }
  131. ;# Variable abase32_prompt_str = to be our string that has been broken from the blocks
  132. ;# switch: "[string index $base32_parsed_elements 0][string index $base32_parsed_elements end]"
  133. ;# Get the first element and the last element
  134. ;# Case: {}
  135. ;# This means that it matches a bracket {} and collect the characters inbetween
  136. ;# Case: default
  137. ;# Collect string
  138.  
  139. variable base32_prompt_str [lmap base32_parsed_elements $base32_parsed_string {
  140. switch -- "[string index $base32_parsed_elements 0][string index $base32_parsed_elements end]" {
  141. "{}" {
  142. string range $base32_parsed_elements 1 end-1
  143. }
  144. default {
  145. set base32_parsed_elements
  146. }
  147. }
  148. }]
  149. crystal::debug 0 "$base32_prompt_str" "base32_prompt_str"
  150.  
  151. ;# Extract variables
  152. variable base32_obj_target [crystal::lidx $base32_prompt_str 0]
  153. variable base32_obj_type [crystal::lidx $base32_prompt_str 1] ;# Type
  154.  
  155. ;# Activate processing
  156. ;# switch $base32_obj_type
  157. ;# This switch assigns variable based on the type
  158. ;# Case: Text
  159. ;# This case handles the text given from the prompt file
  160. ;# Case: Button
  161. ;# This case handles the buttons assigned from the prompt file
  162. ;# Case: title
  163. ;# This case handles the craftsheet Title
  164. switch $base32_obj_type {
  165. text { ;# case to popoulate variables on type
  166. variable base32_class [crystal::lidx $base32_prompt_str 2]
  167. variable base32_text_data [crystal::lidx $base32_prompt_str 3]
  168. variable base16_dispatch_data [crystal::parser::dispatch $base32_obj_type \
  169. $base32_class \
  170. $base32_text_data \
  171. $base32_viewer_key]
  172. }
  173. button { ;# {"%_panel_text_xx_%"}, {"button_style"}, {"button"}, {"/::coffee"}, {"coffee_button"}, {"panel_content_box"}
  174. variable base32_btn_style [crystal::lidx $base32_prompt_str 2] ;# HTML CSS style
  175. variable base32_btn_uri [crystal::lidx $base32_prompt_str 3] ;# HTML PostPath
  176. variable base32_btn_ident [crystal::lidx $base32_prompt_str 4] ;# Button identity
  177. variable base32_btn_target [crystal::lidx $base32_prompt_str 5] ;# Button target / PostTo
  178. variable base32_btn_label [crystal::lidx $base32_prompt_str 6] ;# Display text
  179. variable base32_btn_text [crystal::lidx $base32_prompt_str 7] ;# Display text
  180. variable base16_dispatch_data [crystal::parser::dispatch $base32_obj_type \
  181. $base32_btn_style \
  182. $base32_btn_uri \
  183. $base32_btn_ident \
  184. $base32_btn_target \
  185. $base32_btn_label \
  186. $base32_btn_text \
  187. $base32_viewer_key]
  188. }
  189. button_demo { ;# {"%_panel_text_xx_%"}, {"button_style"}, {"button"}, {"/::coffee"}, {"coffee_button"}, {"panel_content_box"}
  190. crystal::debug 1 [foreach arg $base32_prompt_str { incr i ; puts ">> $arg [expr $i-1]" }] "base32_prompt_str index crystal::parser::parse \n"
  191. variable base32_btn_style [crystal::lidx $base32_prompt_str 2] ;# HTML CSS style
  192. variable base32_btn_uri [crystal::lidx $base32_prompt_str 3] ;# HTML PostPath
  193. variable base32_btn_ident [crystal::lidx $base32_prompt_str 4] ;# Button identity
  194. variable base32_btn_target [crystal::lidx $base32_prompt_str 5] ;# Button target / PostTo
  195. variable base32_btn_label [crystal::lidx $base32_prompt_str 6] ;# Display text
  196. variable base32_btn_text [crystal::lidx $base32_prompt_str 7] ;# Display text
  197. crystal::debug 1 $base32_btn_text "button text"
  198. variable base16_dispatch_data [crystal::parser::dispatch $base32_obj_type \
  199. $base32_btn_style \
  200. $base32_btn_uri \
  201. $base32_btn_ident \
  202. $base32_btn_target \
  203. $base32_btn_label \
  204. $base32_btn_text \
  205. $base32_viewer_key]
  206. }
  207. title {
  208. variable base32_title_data [crystal::lidx $base32_prompt_str 2] ;# HTML CSS style
  209. variable base16_dispatch_data [crystal::parser::dispatch $base32_obj_type \
  210. $base32_title_data \
  211. $base32_viewer_key]
  212. #
  213. crystal::debug 0 "$base32_prompt_str" "[crystal::lidx $base32_prompt_str 2]"
  214. crystal::debug 0 "$base16_dispatch_data" "dispatch data"
  215. }
  216. image {
  217. crystal::debug 0 $base32_prompt_str "prompt read string"
  218. variable base32_obj_type [crystal::lidx $base32_prompt_str 1] ;# image
  219. variable base32_img_type [crystal::lidx $base32_prompt_str 2] ;# jpg/svg/png
  220. variable base32_img_di_anchor [crystal::lidx $base32_prompt_str 3] ;# Digital resource file
  221. variable base32_img_anchor [crystal::lidx $base32_prompt_str 4] ;# The Data
  222. variable base32_img_surface [crystal::lidx $base32_prompt_str 5] ;# The Data
  223. variable base16_dispatch_data [crystal::parser::dispatch $base32_obj_type \
  224. $base32_img_type \
  225. $base32_img_di_anchor \
  226. $base32_img_anchor \
  227. $base32_img_surface \
  228. $base32_viewer_key]
  229. # ensure to check prompt_parser and action_dispatch align with your obj_type
  230. crystal::debug 0 "$base32_prompt_str" "[crystal::lidx $base32_prompt_str 2]"
  231. crystal::debug 0 "$base16_dispatch_data" "dispatched data"
  232. crystal::debug 0 $base32_obj_type "object type"
  233. crystal::debug 0 $base32_img_type "img type"
  234. crystal::debug 0 $base32_img_di_anchor "dispatched Di anchor"
  235. crystal::debug 0 $base32_img_anchor "dispatched svg anchor"
  236. crystal::debug 0 $base32_img_surface "dispatched svg data"
  237. crystal::debug 0 $base16_dispatch_data "dispatched base16_dispatch_data"
  238. }
  239.  
  240. default { crystal::debug 1 "$base32_obj_type" "Invalid base32_obj_type" }
  241. } ;# end switch base32_obj_type
  242.  
  243. variable base16_obj_target [crystal::2Hex $base32_obj_target]
  244. crystal::debug 0 $base16_obj_target "base16_target"
  245. crystal::debug 0 $base16_dispatch_data "base16_dispatch_data"
  246. ;# Throws the results to our morph
  247. lappend base16_morph_data $base16_obj_target $base16_dispatch_data
  248. }
  249. } ;# end switch
  250. } ;# end while
  251. return $base16_morph_data
  252. } ;# end proc

Add a comment

Please note that this site uses the meta tags nofollow,noindex for all pages that contain comments.
Items are closed for new comments after 1 week