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