Sha256: ce7d4552dfebb10290af2c152d258c86e95fea903a930d92244c8520c6d49ffe

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

(ns wisp.wisp
  "Wisp program that reads wisp code from stdin and prints
  compiled javascript code into stdout"
  (:require [fs :as fs]
            [path :as path])
  (:use [module :only [Module]]
        [wisp.repl :only [start]]
        [wisp.runtime :only [str]]
        [wisp.compiler :only [compile*]]
        [wisp.reader :only [read*]]))

(defn- exit
  "Takes care of exiting node and printing erros if encounted"
  [error]
  (if error
    (do
      (.error console error)
      (.exit process 1))
    (.exit process 0)))

(defn- compile
  "Compiles lispy from input and writes it to output"
  [input output uri]
  (def source "")
  (.on input :data
       (fn on-chunck
         "Accumulate text form input until it ends."
         [chunck]
         (set! source (str source chunck))))
  (.on input :end
       (fn on-read
         "Once input ends try to compile & write to output."
         []
         (try (.write output (compile* (read* source)))
           (catch error (exit error)))))
  (.on input :error exit)
  (.on output :error exit))


(defn main []
  (if (< process.argv.length 3)
    (do
      (.resume process.stdin)
      (.set-encoding process.stdin :utf8)
      ;; Compile stdin and write it to stdout.
      (compile process.stdin process.stdout (.cwd process))
      ;; If there is nothing is written to stdin within 20ms
      ;; start repl.
      (set-timeout
       (fn []
         (if (identical? process.stdin.bytes-read 0)
           (do
             (.remove-all-listeners process.stdin :data)
             (start))))
       20))
    ;; Loading module as main one, same way as nodejs does it:
    ;; https://github.com/joyent/node/blob/master/lib/module.js#L489-493
    (Module._load (.resolve path (get process.argv 2)) null true)))

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby-wisp-source-0.8.0 vendor/node_modules/wisp/src/wisp.wisp
ruby-wisp-source-0.7.0 vendor/src/wisp.wisp