31d53da78b83022ee8228f8193a893a169c3eb3d — Timur Ismagilov 5 years ago 76016fd
Add disbracket.agidel

An attempt to rewrite disbracket ST to Agidel/C. Not all macros in it
are implemented yet, but will be someday.
1 files changed, 44 insertions(+), 0 deletions(-)

A disbracket.agidel
A disbracket.agidel => disbracket.agidel +44 -0
@@ 0,0 1,44 @@
;; disbracket syntrans
;;   © 2019 Timur Ismagilov
;;   MIT License
;; [a b c] → (_bracket a b c)

(import stdbool.h unistd.h stdio.h)

  (in_string bool)
  (escaping_char bool)
  (pairs_in_search unsigned int)
  (ch char))

(defun (main int) ()
  (while (positive? [read STDIN_FILENO &ch 1])
    (if in_string
           [printf "\%c" ch]
           (set escaping_char false))
          ((eq? ch '\\')
           (set escaping_char true))
          ((eq? ch '\"')
           [printf "%c" ch]
           (set in_string false))
           [printf "%c" ch]))
          ((eq? ch '[')
           [printf "(_bracket "]
           (inc pairs_in_search))
          ((eq? ch ']')
           [printf ")"]
           (dec pairs_in_search))
          ((eq? ch '\"')
           (set in_string true)
           [printf "%c" ch])
           [printf "%c" ch]))))
  (when-not (zero? pairs_in_search)
      [fprintf stderr "Agidel: %d unmatched bracket pairs." pairs_in_search]
      (return 1))
  (return 0))