Compare commits

..

No commits in common. 'fe4e0d7e122d535c21c842cb99eb221e1b86d579' and '7379dcadae01ed43dc84f3923d472b996f443cb3' have entirely different histories.

  1. 49
      src/rustint/core.clj
  2. 81
      test/rustint/core_test.clj

@ -1900,35 +1900,10 @@
;
; nil
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(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)))
)
)
)
)
)
;TODO
;(defn listar
;
;)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 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).
@ -2071,18 +2046,10 @@
; user=> (ya-declarado-localmente? 'Write [[0 2] [['io ['lib '()] 0] ['Write ['lib '()] 0] ['entero_a_hexa ['fn [(list ['n (symbol ":") 'i64]) 'String]] 2]]])
; false
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn in?
"true if coll contains elm"
[coll elm]
(boolean (some #(= elm %) coll))
)
(defn ya-declarado-localmente? [ident ctx]
(let [inicio_scope_local (last (get ctx 0)),
scope_local (subvec (get ctx 1) inicio_scope_local),
identificadores_scope_local (map first scope_local)
] (in? identificadores_scope_local ident))
)
;TODO
;(defn ya-declarado-localmente?
;
;)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; CARGAR-CONST-EN-TABLA: Recibe un ambiente

@ -446,84 +446,3 @@
)
)
)
(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}"
)
)
)
)
)
(deftest test-ya-declarado-localmente-01
(testing "Test 01 ya-declarado-localmente?"
(is (= (ya-declarado-localmente?
'Write
[
[0]
[
['io ['lib '()] 0]
['Write ['lib '()] 0]
['entero_a_hexa ['fn [(list ['n (symbol ":") 'i64]) 'String]] 2]
]
]
) true))
)
)
(deftest test-ya-declarado-localmente-02
(testing "Test 02 ya-declarado-localmente?"
(is (= (ya-declarado-localmente?
'Read
[
[0]
[
['io ['lib '()] 0]
['Write ['lib '()] 0]
['entero_a_hexa ['fn [(list ['n (symbol ":") 'i64]) 'String]] 2]
]
]
)
false))
)
)
(deftest test-ya-declarado-localmente-03
(testing "Test 03 ya-declarado-localmente?"
(is (= (ya-declarado-localmente?
'Write
[
[0 1]
[
['io ['lib '()] 0]
['Write ['lib '()] 0]
['entero_a_hexa ['fn [(list ['n (symbol ":") 'i64]) 'String]] 2]
]
]
)
true))
)
)
(deftest test-ya-declarado-localmente-04
(testing "Test 04 ya-declarado-localmente?"
(is (= (ya-declarado-localmente?
'Write
[
[0 2]
[
['io ['lib '()] 0]
['Write ['lib '()] 0]
['entero_a_hexa ['fn [(list ['n (symbol ":") 'i64]) 'String]] 2]
]
]
)
false))
)
)

Loading…
Cancel
Save