|
|
|
|
@ -1936,43 +1936,11 @@ |
|
|
|
|
; Por ejemplo: |
|
|
|
|
; user=> (agregar-ptocoma (list 'fn 'main (symbol "(") (symbol ")") (symbol "{") 'if 'x '< '0 (symbol "{") 'x '= '- 'x (symbol ";") (symbol "}") 'renglon '= 'x (symbol ";") 'if 'z '< '0 (symbol "{") 'z '= '- 'z (symbol ";") (symbol "}") (symbol "}") 'fn 'foo (symbol "(") (symbol ")") (symbol "{") 'if 'y '> '0 (symbol "{") 'y '= '- 'y (symbol ";") (symbol "}") 'else (symbol "{") 'x '= '- 'y (symbol ";") (symbol "}") (symbol "}"))) |
|
|
|
|
; (fn main ( ) { if x < 0 { x = - x ; } ; renglon = x ; if z < 0 { z = - z ; } } fn foo ( ) { if y > 0 { y = - y ; } else { x = - y ; } }) |
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
|
|
(defn merits-comma [tokens ident_levels] |
|
|
|
|
(let [ |
|
|
|
|
token (nth tokens 0), |
|
|
|
|
next_token (nth tokens 1), |
|
|
|
|
token_il (nth ident_levels 0), |
|
|
|
|
next_token_il (nth ident_levels 1) |
|
|
|
|
] |
|
|
|
|
( and |
|
|
|
|
(= token (symbol "}")) |
|
|
|
|
(not= next_token (symbol "}")) |
|
|
|
|
(not= next_token (symbol ";")) |
|
|
|
|
(> next_token_il 0) |
|
|
|
|
(not (palabra-reservada? next_token)) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
(defn get-ident-levels [tokens] |
|
|
|
|
( |
|
|
|
|
let [contadores (hash-map (symbol "{") 1, (symbol "}") -1)] |
|
|
|
|
(reductions + (map #(get contadores %1 0) tokens)) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
(defn commas-to-add [tokens] |
|
|
|
|
(concat (map merits-comma (partition 2 1 tokens) (partition 2 1 (get-ident-levels tokens))) '(false)) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
(defn add-ptocomma [token add-comma?] |
|
|
|
|
(if add-comma? [token, (symbol ";")] token) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
(defn agregar-ptocoma [tokens] |
|
|
|
|
(flatten (map add-ptocomma tokens (commas-to-add tokens))) |
|
|
|
|
) |
|
|
|
|
; TODO |
|
|
|
|
;(defn agregar-ptocoma |
|
|
|
|
; |
|
|
|
|
;) |
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
|
|
; PALABRA-RESERVADA?: Recibe un elemento y devuelve true si es una palabra reservada de Rust; si no, false. |
|
|
|
|
|