master
CrossNox 3 years ago
parent 7379dcadae
commit f54204b01b
  1. 33
      src/rustint/core.clj
  2. 14
      test/rustint/core_test.clj

@ -1900,10 +1900,35 @@
;
; nil
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;TODO
;(defn listar
;
;)
(defn flistar [ilevel t nxt]
(cond
(string? t) (format "\"%s\" " t)
(= t (symbol "{")) (clojure.string/join
(cons "\n{\n" (repeat (* ilevel 2) " "))
)
(= t (symbol "}")) "\n}"
(and (not= nxt (symbol "{")) (not= nxt (symbol "}"))) (format "%s " t)
:else (format "%s" t)
)
)
(defn listar [l]
(let [contadores (hash-map (symbol "{") 1, (symbol "}") -1),
ident_levels (reductions + (map #(get contadores %1 0) l)),
]
(dorun
(
map
print
(map
#(apply flistar (cons %1 %2))
ident_levels
(partition 2 1 (concat l '(nil)))
)
)
)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; AGREGAR-PTOCOMA: Recibe una lista con los tokens de un programa en Rust y la devuelve con un token ; insertado a continuacion de ciertas } (llaves de cierre, pero no a continuacion de todas ellas).

@ -446,3 +446,17 @@
)
)
)
(deftest test-listar-01
(testing "Test 01 listar"
(let [
printed (with-out-str (listar (list 'fn 'main (symbol "(") (symbol ")") (symbol "{") 'println! (symbol "(") "Hola, mundo!" (symbol ")") (symbol "}"))))
]
(is (=
printed
"fn main ( )\n{\n println! ( \"Hola, mundo!\" )\n}"
)
)
)
)
)

Loading…
Cancel
Save