hy/demo/app.py

28 lines
552 B
Python
Raw Normal View History

2012-12-24 19:41:29 +01:00
from hy.compiler.ast27 import forge_ast
from hy.lex.tokenize import tokenize
import codegen
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/translate', methods=['POST'])
def translate():
lines = request.form['code']
try:
code = tokenize(lines)
ast = forge_ast("stdin", code)
return codegen.to_source(ast)
except Exception as e:
return str(e)
if __name__ == '__main__':
app.run(debug=True)