| 1 |
(require 'cl-lib) |
| 2 |
|
| 3 |
(defun format-state (prefix state ⊤ ⊥) |
| 4 |
(cond ((string= state "⊥") ⊥) |
| 5 |
((string= state "⊤") ⊤) |
| 6 |
(t (format "%s%s" prefix state)))) |
| 7 |
|
| 8 |
(defun dh/orgtbl-to-dfa-binary-table (table params) |
| 9 |
(let* ((table (--filter (not (equal 'hline it)) table)) |
| 10 |
(rows (1- (length table))) |
| 11 |
(cols (1- (length (nth 0 table)))) |
| 12 |
(prefix (plist-get params :prefix)) |
| 13 |
(var (plist-get params :var)) |
| 14 |
(⊤ (plist-get params :⊤)) |
| 15 |
(⊥ (plist-get params :⊥))) |
| 16 |
|
| 17 |
(concat |
| 18 |
(if var (concat "var " var " = ") "") |
| 19 |
(format |
| 20 |
"dfa.BinaryTable(%s, map[[2]%s]%s{\n" |
| 21 |
⊤ prefix prefix) |
| 22 |
(mapconcat |
| 23 |
(lambda (rowIdx) |
| 24 |
(mapconcat |
| 25 |
(lambda (colIdx) |
| 26 |
(let* ((x (nth 0 (nth rowIdx table))) |
| 27 |
(y (nth colIdx (nth 0 table))) |
| 28 |
(z (nth colIdx (nth rowIdx table)))) |
| 29 |
(format "{%s, %s}: %s," (format-state prefix x ⊤ ⊥) (format-state prefix y ⊤ ⊥) (format-state prefix z ⊤ ⊥)))) |
| 30 |
(number-sequence 1 cols) |
| 31 |
"\n")) |
| 32 |
(number-sequence 1 rows) |
| 33 |
"\n\n") |
| 34 |
"\n})"))) |