Posted to tcl by mookie at Mon Aug 03 20:09:06 GMT 2026view raw
- ;# This file reads the .prompt files, and dispatches data accordingly "prompt_read.ix"
- namespace eval crystal::parser { puts "-> [file tail [info script]]" }
- namespace eval crystal::parser {
- namespace export {[a-z]*}
- namespace ensemble create
- }
-
- ;## Initalise our dispatch
- ;# We do this within crystal.ix
- ;## [crystal::parser::init_dispatch]
- proc crystal::parser {args} {
- ;# Switch: [crystal::lidx $args 0]
- ;# execute dependednt on the first argurement given
- ;# this result should only come from the netdisc
- ;# /// FEATURE_IDEA : Implement arg_source
- ;# Case: load
- ;# This loads the prompt file
- switch [lindex $args 0] {
- morph { crystal::debug 0 "loaded" "prompted file"
- variable base16_viewer_key [lindex $args 1] ;# Viewer Key
- variable base32_prompt_script [lindex $args 2] ;# neoncrystal_online
- variable base32_prompt_file [format "%s.prompt" [lindex $args 2]] ;# example: neoncrystal_online.prompt
-
- # Get our prompt/craft paths
- variable base32_craft_script_path [crystal::2Base [crystal::hextdict "retrieve_from" "crystal" "craftsheets" "$base32_prompt_script"]]
- variable base32_prompt_script_path [crystal::2Base [crystal::hextdict "retrieve_from" "crystal" "promptsheets" "$base32_prompt_script"]]
- #
- crystal::debug 0 $base32_prompt_script "Prompt script path"
-
- switch [crystal::hextdict "retrieve_from" $base32_craft_script_path "$base32_prompt_file" "file_scanned"] {
- 0 {
- ;#### modified time setup
- ;# /forest/crystal_forest/crystal/main/netdisc_system/craft/system_resources.craft
- ;# > system_resources.prompt -> file_mtime
- ;# > system_resources.prompt -> file_scanned
- ;# > prompt_script -> line_index -> 0 ..
- ;# > craft_script -> line_index -> 1 ..
- crystal::hextdict "insert_to" $base32_craft_script_path "$base32_prompt_file" "file_mtime" [file mtime $base32_prompt_script_path]
- crystal::hextdict "insert_to" $base32_craft_script_path "$base32_prompt_file" "file_scanned" 1
- #####
- set fh [open $base32_prompt_script_path r] ;# establish our file handlder
- set index 0 ;# set our index
- ;# Gather our lines in the file
- while {[gets $fh base32_file_line] >= 0} {
- crystal::hextdict "insert_to" "$base32_craft_script_path" "prompt_script" "$index" "$base32_file_line"
- incr index
- } ;# end while
- ;#
- close $fh
- #
- crystal::debug 0 [crystal::hextdict "list" "$base32_craft_script_path" "prompt_script"] "prompt line indexes"
- }
- 31 { crystal::debug 0 "[crystal::hextdict "retrieve_from" "$base32_craft_script_path" "$base32_prompt_file" "file_mtime"]" "our prompt modifed time" }
- } ;# end switch [crystal::hextdict "retrieve_from" "crystal" "$base32_prompt_file" "scanned"]
- ;####
- crystal::parser::parse $base16_viewer_key $base32_prompt_script
- }
- } ;# end switch
- } ;# end proc
-
- proc crystal::parser::parse {base32_viewer_key base32_prompt_script} {
- # Get our prompt/craft paths
- variable base32_craft_script_path [crystal::2Base [crystal::hextdict "retrieve_from" "crystal" "craftsheets" "$base32_prompt_script"]]
- variable base32_prompt_script_path [crystal::2Base [crystal::hextdict "retrieve_from" "crystal" "promptsheets" "$base32_prompt_script"]]
- variable base32_prompt_file [format "%s.prompt" base32_prompt_script] ;# example: neoncrystal_online.prompt
- ;#
- crystal::debug 0 $base32_prompt_script_path "Prompt script loaded path"
-
- # Expiremental - Set our "default key when none has been defined"
- switch $base32_viewer_key { ;# Set default viewer
- "" { set base32_viewer_key "00000000000000000000000000000000000000000000000000000000000000FF" }
- }
-
- ;# raw file mtime
- variable base16_file_mtime [crystal::2Hex [file mtime $base32_prompt_script_path]]
- ;# neoncrystal_online.craft
- ;# > neoncrystal_online.prompt -> file_mtime
- variable base16_crystal_mtime [crystal::hextdict "retrieve_from" $base32_craft_script_path "$base32_prompt_file" "file_mtime"]
-
- crystal::debug 0 "$base16_file_mtime" "$base16_crystal_mtime"
- crystal::debug 0 [expr {$base16_file_mtime != $base16_crystal_mtime}] "mtime check"
-
- ;# Switch: [expr {$base16_file_mtime != $base16_crystal_mtime}]
- ;# Checks our file mtime with our crystal time
- ;# When the modified time has changed update our dictionary with the new file
- ;# Case: 1
- ;# Reset our prompt_dictionary
- ;# Set our file handler to that of the script path
- ;# Set the index as 0
- switch [expr {$base16_file_mtime != $base16_crystal_mtime}] {
- 1 { ;# mtime differs, reread file and rebuild dictionary
- ;# Read our file in to a dictionary
- ;#
- set fh [open $base32_prompt_script_path r] ;# establish our file handlder
- set index 0 ;# set our index
-
- # Clean our old stale prompt lines
- crystal::hextdict "reset" $base32_craft_script_path prompt_script
- # crystal::hextdict "reset" $base32_craft_script_path "prompt_lines"
- #
- while {[gets $fh base32_file_line] >= 0} {
- crystal::hextdict "insert_to" "$base32_craft_script_path" "prompt_script" "$index" "$base32_file_line"
- incr index
- }
- close $fh
- ;# End read
-
- ;# Update our modified time for the file
- crystal::hextdict "insert_to" $base32_craft_script_path "$base32_prompt_file" "file_mtime" [file mtime $base32_prompt_script_path]
- }
- } ;# end switch [expr {$base16_file_mtime != $base16_crystal_mtime}]
-
- ;# Foreach index in our prompt_line dictionary
- foreach index [crystal::hextdict "list" "$base32_craft_script_path" "prompt_script"] {
- set base32_file_line [crystal::hextdict "retrieve_from_32" "$base32_craft_script_path" "prompt_script" "[crystal::2Base $index]"]
- crystal::debug 0 $base32_file_line "file line"
-
- ;# Switch: $base32_file_line
- ;# This switch handles the file line
- ;# Case: "" - This is an empty Line, skip
- ;# Skip empty lines
- switch $base32_file_line {
- "" { break }
- default {
- variable base32_parsed_string [crystal::parser::hex_scope $base32_file_line]
-
- crystal::debug 0 "$base32_parsed_string" "base32_parsed_string"
-
- ;# Cleansing - remove our braces
- ;# This is where remove our { }
- ;# Variable abase32_prompt_str = to be our string that has been broken from the blocks
- ;# switch: "[string index $base32_parsed_elements 0][string index $base32_parsed_elements end]"
- ;# Get the first element and the last element
- ;# Case: {}
- ;# This means that it matches a bracket {} and collect the characters inbetween
- ;# Case: default
- ;# Collect string
-
- variable base32_prompt_str [lmap base32_parsed_elements $base32_parsed_string {
- switch -- "[string index $base32_parsed_elements 0][string index $base32_parsed_elements end]" {
- "{}" {
- string range $base32_parsed_elements 1 end-1
- }
- default {
- set base32_parsed_elements
- }
- }
- }]
- crystal::debug 0 "$base32_prompt_str" "base32_prompt_str"
-
- ;# Extract variables
- variable base32_obj_target [crystal::lidx $base32_prompt_str 0]
- variable base32_obj_type [crystal::lidx $base32_prompt_str 1] ;# Type
-
- ;# Activate processing
- ;# switch $base32_obj_type
- ;# This switch assigns variable based on the type
- ;# Case: Text
- ;# This case handles the text given from the prompt file
- ;# Case: Button
- ;# This case handles the buttons assigned from the prompt file
- ;# Case: title
- ;# This case handles the craftsheet Title
- switch $base32_obj_type {
- text { ;# case to popoulate variables on type
- variable base32_class [crystal::lidx $base32_prompt_str 2]
- variable base32_text_data [crystal::lidx $base32_prompt_str 3]
- variable base16_dispatch_data [crystal::parser::dispatch $base32_obj_type \
- $base32_class \
- $base32_text_data \
- $base32_viewer_key]
- }
- button { ;# {"%_panel_text_xx_%"}, {"button_style"}, {"button"}, {"/::coffee"}, {"coffee_button"}, {"panel_content_box"}
- variable base32_btn_style [crystal::lidx $base32_prompt_str 2] ;# HTML CSS style
- variable base32_btn_uri [crystal::lidx $base32_prompt_str 3] ;# HTML PostPath
- variable base32_btn_ident [crystal::lidx $base32_prompt_str 4] ;# Button identity
- variable base32_btn_target [crystal::lidx $base32_prompt_str 5] ;# Button target / PostTo
- variable base32_btn_label [crystal::lidx $base32_prompt_str 6] ;# Display text
- variable base32_btn_text [crystal::lidx $base32_prompt_str 7] ;# Display text
- variable base16_dispatch_data [crystal::parser::dispatch $base32_obj_type \
- $base32_btn_style \
- $base32_btn_uri \
- $base32_btn_ident \
- $base32_btn_target \
- $base32_btn_label \
- $base32_btn_text \
- $base32_viewer_key]
- }
- button_demo { ;# {"%_panel_text_xx_%"}, {"button_style"}, {"button"}, {"/::coffee"}, {"coffee_button"}, {"panel_content_box"}
- crystal::debug 1 [foreach arg $base32_prompt_str { incr i ; puts ">> $arg [expr $i-1]" }] "base32_prompt_str index crystal::parser::parse \n"
- variable base32_btn_style [crystal::lidx $base32_prompt_str 2] ;# HTML CSS style
- variable base32_btn_uri [crystal::lidx $base32_prompt_str 3] ;# HTML PostPath
- variable base32_btn_ident [crystal::lidx $base32_prompt_str 4] ;# Button identity
- variable base32_btn_target [crystal::lidx $base32_prompt_str 5] ;# Button target / PostTo
- variable base32_btn_label [crystal::lidx $base32_prompt_str 6] ;# Display text
- variable base32_btn_text [crystal::lidx $base32_prompt_str 7] ;# Display text
- crystal::debug 1 $base32_btn_text "button text"
- variable base16_dispatch_data [crystal::parser::dispatch $base32_obj_type \
- $base32_btn_style \
- $base32_btn_uri \
- $base32_btn_ident \
- $base32_btn_target \
- $base32_btn_label \
- $base32_btn_text \
- $base32_viewer_key]
- }
- title {
- variable base32_title_data [crystal::lidx $base32_prompt_str 2] ;# HTML CSS style
- variable base16_dispatch_data [crystal::parser::dispatch $base32_obj_type \
- $base32_title_data \
- $base32_viewer_key]
- #
- crystal::debug 0 "$base32_prompt_str" "[crystal::lidx $base32_prompt_str 2]"
- crystal::debug 0 "$base16_dispatch_data" "dispatch data"
- }
- image {
- crystal::debug 0 $base32_prompt_str "prompt read string"
- variable base32_obj_type [crystal::lidx $base32_prompt_str 1] ;# image
- variable base32_img_type [crystal::lidx $base32_prompt_str 2] ;# jpg/svg/png
- variable base32_img_di_anchor [crystal::lidx $base32_prompt_str 3] ;# Digital resource file
- variable base32_img_anchor [crystal::lidx $base32_prompt_str 4] ;# The Data
- variable base32_img_surface [crystal::lidx $base32_prompt_str 5] ;# The Data
- variable base16_dispatch_data [crystal::parser::dispatch $base32_obj_type \
- $base32_img_type \
- $base32_img_di_anchor \
- $base32_img_anchor \
- $base32_img_surface \
- $base32_viewer_key]
- # ensure to check prompt_parser and action_dispatch align with your obj_type
- crystal::debug 0 "$base32_prompt_str" "[crystal::lidx $base32_prompt_str 2]"
- crystal::debug 0 "$base16_dispatch_data" "dispatched data"
- crystal::debug 0 $base32_obj_type "object type"
- crystal::debug 0 $base32_img_type "img type"
- crystal::debug 0 $base32_img_di_anchor "dispatched Di anchor"
- crystal::debug 0 $base32_img_anchor "dispatched svg anchor"
- crystal::debug 0 $base32_img_surface "dispatched svg data"
- crystal::debug 0 $base16_dispatch_data "dispatched base16_dispatch_data"
- }
-
- default { crystal::debug 1 "$base32_obj_type" "Invalid base32_obj_type" }
- } ;# end switch base32_obj_type
-
- variable base16_obj_target [crystal::2Hex $base32_obj_target]
- crystal::debug 0 $base16_obj_target "base16_target"
- crystal::debug 0 $base16_dispatch_data "base16_dispatch_data"
- ;# Throws the results to our morph
- lappend base16_morph_data $base16_obj_target $base16_dispatch_data
- }
- } ;# end switch
- } ;# end while
- return $base16_morph_data
- } ;# end proc
Add a comment