2013-03-10 05:15:22 +01:00
|
|
|
; Copyright (c) Paul R. Tagliamonte <tag@pault.ag>, 2013 under the terms of
|
|
|
|
; hy.
|
|
|
|
|
2013-03-10 15:58:31 +01:00
|
|
|
(import-from flask
|
2013-03-12 00:14:20 +01:00
|
|
|
Flask render-template request make-response)
|
2013-03-10 15:58:31 +01:00
|
|
|
|
2013-03-12 00:14:20 +01:00
|
|
|
(import-from hy.errors HyError)
|
|
|
|
(import-from hy.lex LexException)
|
2013-03-10 15:58:31 +01:00
|
|
|
(import-from hy.importer import_string_to_ast)
|
2013-03-12 00:14:20 +01:00
|
|
|
|
2013-03-12 01:33:06 +01:00
|
|
|
(import autopep8)
|
2013-03-12 02:12:38 +01:00
|
|
|
(import astor.codegen)
|
2013-03-10 15:58:31 +01:00
|
|
|
|
2013-03-10 17:59:16 +01:00
|
|
|
|
|
|
|
(def app (Flask "__main__")) ; long story, needed hack
|
|
|
|
|
|
|
|
|
2013-03-12 01:33:06 +01:00
|
|
|
(defn hy-to-py [hython]
|
2013-03-12 02:12:38 +01:00
|
|
|
(.fix-string autopep8
|
|
|
|
(.to_source astor.codegen (import-string-to-ast hython))))
|
2013-03-12 01:33:06 +01:00
|
|
|
|
2013-03-12 00:14:20 +01:00
|
|
|
(defn err [msg] (make-response msg 500))
|
2013-03-10 05:15:22 +01:00
|
|
|
|
2013-03-10 04:45:08 +01:00
|
|
|
|
2013-03-10 15:58:31 +01:00
|
|
|
; view routes
|
2013-03-12 03:19:17 +01:00
|
|
|
(route "/" [] (render-template "repl.html"))
|
2013-03-12 03:02:30 +01:00
|
|
|
|
2013-03-12 00:14:20 +01:00
|
|
|
(post-route "/hy2py" []
|
2013-03-14 02:30:17 +01:00
|
|
|
(try
|
|
|
|
(hy-to-py (get request.form "code"))
|
|
|
|
(catch LexException (err "Incomplete Code."))
|
|
|
|
(catch HyError (err "Generic error during processing."))
|
|
|
|
(catch Exception (err "Erm, you broke something."))))
|