; bugs: ;#16> (fmt "{x} x {") ;exception! name 'ev' is not defined (func fmt :string (inp :string) ; need two variables ; 1. the current processed string ; 2. the neb code to run ; ; algorithm ; - read characters one by one, adding to result ; - if reach a { ; - read characters one by one, adding to neb code ; - when reach }, try to execute the neb code, ; then append to the end of the result ; - if the end of the string is successfully reached, return the result (def digits (split "0123456789")) (def aligns (split "^<>")) (func repeat (cnt) (def out "") (for-count cnt (redef out (concat out " "))) out) (func special-parse (str cur val) (if (eq? "}" (first-char str)) (block ; [align][width] (to start) (def align-width (if (in? (first-char cur) aligns) (list (first-char cur) (string->int (rest-char cur))) (list "<" (string->int cur)))) (branch ((>= (length val) (last align-width)) (list val (rest-char str))) ((eq? "<" (first align-width)) ; align left (list (concat val (repeat (- (last align-width) (length val)))) (rest-char str))) ((eq? ">" (first align-width)) ; align right (list (concat (repeat (- (last align-width) (length val))) val) (rest-char str))) (#true ; align center (block (def half (/ (- (last align-width) (length val)) 2)) (if (int? half) (list (concat (repeat half) val (repeat half)) (rest-char str)) (list (concat (repeat (floor half)) val (repeat (+ 1 (floor half)))) (rest-char str))))))) (special-parse (rest-char str) (concat cur (first-char str)) val))) (func brace-parse :[:string] (str :string cur :string) ; returns (remaining value) (branch ((eq? "}" (first-char str)) (list (rest-char str) (->string (eval (parse-neb cur))))) ((eq? "," (first-char str)) (special-parse (rest-char str) "" (->string (eval (parse-neb cur))))) (#true (brace-parse (rest-char str) (concat cur (first-char str)))))) (func inner-parse (str cur) (branch ((eq? 0 (length str)) cur) ((eq? "{" (first-char str)) (block (def tmp (brace-parse (rest-char str) "")) (inner-parse (first tmp) (concat cur (first (rest tmp)))))) (#true (inner-parse (rest-char str) (concat cur (first-char str)))))) (inner-parse inp ""))