From 10effa476ed74e4b8a7709f681966ef0918cbab3 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Thu, 22 Nov 2018 14:45:55 -0800 Subject: jbo/la banbixicns: mi sabji lo tricu je lo .braxes. --- jbo/la-banbixsicns/main.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/jbo/la-banbixsicns/main.go b/jbo/la-banbixsicns/main.go index 07cd77d..c05e79d 100644 --- a/jbo/la-banbixsicns/main.go +++ b/jbo/la-banbixsicns/main.go @@ -9,6 +9,7 @@ import ( "github.com/eaburns/johaus/parser" _ "github.com/eaburns/johaus/parser/camxes" + "github.com/eaburns/johaus/pretty" _ "github.com/joho/godotenv/autoload" ) @@ -21,10 +22,34 @@ func main() { } log.Printf("Listening on http://0.0.0.0:%s", p) - http.ListenAndServe(":"+p, http.HandlerFunc(handle)) + + http.DefaultServeMux.HandleFunc("/tree", tree) + http.DefaultServeMux.HandleFunc("/braces", braces) + + http.ListenAndServe(":"+p, nil) } -func handle(w http.ResponseWriter, r *http.Request) { +func braces(w http.ResponseWriter, r *http.Request) { + data, err := ioutil.ReadAll(r.Body) + if err != nil { + http.Error(w, "can't parse: "+err.Error(), http.StatusBadRequest) + return + } + + tree, err := parser.Parse(dialect, string(data)) + if err != nil { + http.Error(w, "can't parse: "+err.Error(), http.StatusBadRequest) + return + } + + parser.RemoveMorphology(tree) + parser.AddElidedTerminators(tree) + parser.RemoveSpace(tree) + parser.CollapseLists(tree) + + pretty.Braces(w, tree) +} +func tree(w http.ResponseWriter, r *http.Request) { data, err := ioutil.ReadAll(r.Body) if err != nil { http.Error(w, "can't parse: "+err.Error(), http.StatusBadRequest) -- cgit v1.2.3