hy/demo/app.py

34 lines
642 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
import sys
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
2012-12-27 05:08:09 +01:00
@app.route('/popup')
def popup():
return render_template('popover.html')
2012-12-24 19:41:29 +01:00
@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)