Advertisement
Guest User

languages.boot

a guest
Aug 4th, 2017
196
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Clojure 1.05 KB | None
  1. #!/usr/bin/env boot
  2.  
  3. (merge-env! :dependencies
  4.             '[[cheshire "5.7.1"]
  5.               [clj-yaml "0.4.0"]])
  6.  
  7. (require '[cheshire.core :as json]
  8.          '[clj-yaml.core :as yaml]
  9.          '[clojure.string :as str])
  10.  
  11. (import (java.nio.charset StandardCharsets))
  12.  
  13. (defn keywords [entry]
  14.   (let [[language {ace-mode "ace_mode" :strs [aliases]}] entry]
  15.     (into (sorted-set) (conj aliases (str/lower-case language) ace-mode))))
  16.  
  17. (defn keyword-map [language-map]
  18.   (into (sorted-map) (for [[language :as entry] language-map]
  19.                        [language (keywords entry)])))
  20.  
  21. (defn bytes->str [b]
  22.   (String. b StandardCharsets/UTF_8))
  23.  
  24. (defn str->bytes [s]
  25.   (.getBytes s StandardCharsets/UTF_8))
  26.  
  27. (defn process [b]
  28.   (-> b
  29.       bytes->str
  30.       (yaml/parse-string false)
  31.       keyword-map
  32.       (json/generate-string {:pretty true})
  33.       (str "\n")
  34.       str->bytes))
  35.  
  36. (defn stdin []
  37.   (byte-array (take-while pos? (repeatedly #(.read System/in)))))
  38.  
  39. (defn stdout [b]
  40.   (.write System/out b))
  41.  
  42. (stdout (process (stdin)))
Advertisement
RAW Paste Data Copied
Advertisement