From bb585fef2cf88eeac08ee6f77de1f0ea8130b396 Mon Sep 17 00:00:00 2001 From: hallgren Date: Thu, 29 Sep 2011 15:19:03 +0000 Subject: Example-based grammar writing: fix problems caused by the use of exprToAPI The editor needs to keep track of both the raw term and the nice term returned by exprToAPI. (Manually constructed linearization rules will now have the raw term and can not be tested.) Also replace metavariables in generalized terms with the apropriate parameter from the linearization rule. Also fix communication problems caused by inconsistent use of show/read vs showExpr/readExpr. --- src/editor/simple/editor.js | 2 +- src/editor/simple/example_based.js | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'src/editor') diff --git a/src/editor/simple/editor.js b/src/editor/simple/editor.js index 1a3dabf92..a2ddc80b3 100644 --- a/src/editor/simple/editor.js +++ b/src/editor/simple/editor.js @@ -790,7 +790,7 @@ function draw_lins(g,ci) { if(!msg) { if(f.template) conc.lins.push({fun:f.fun,args:f.args,lin:s}); - else f.lin=s; + else { f.lin=s; f.eb_lin=null; } reload_grammar(g); } cont(msg); diff --git a/src/editor/simple/example_based.js b/src/editor/simple/example_based.js index 20c9d2ade..f38f657c7 100644 --- a/src/editor/simple/example_based.js +++ b/src/editor/simple/example_based.js @@ -20,7 +20,7 @@ function exb_state(g,ci) { return "("+lincat.cat+","+lincat.type+")" } function show_lin(lin) { - return "("+lin.fun+","+lin.lin+")" + return "("+lin.fun+","+(lin.eb_lin||"?")+")" } function show_funs(funs) { return show_list(show_fun,funs) } function show_lincats(lincats) { return show_list(show_lincat,lincats); } @@ -88,11 +88,19 @@ function exb_linbuttons(g,ci,f) { var fun=f.fun; var eb=example_based[ci]; var exb_output; - function fill_example(tree) { - exb_output.innerHTML=""; - if(f.template) conc.lins.push({fun:f.fun,args:f.args,lin:tree}); - else f.lin=s; - ask_possibilities(g,ci) + function fill_example(maybetree) { + var tree=maybetree.Just + if(tree) { + if(f.template) + conc.lins.push({fun:f.fun,args:f.args, + lin:tree[0],eb_lin:tree[1]}); + else { + f.lin=tree[0]; + f.eb_lin=tree[1]; + } + ask_possibilities(g,ci) + } + else exb_output.innerHTML="Bug: no tree found" } function show_example(example){ exb_output.innerHTML=""; @@ -104,7 +112,9 @@ function exb_linbuttons(g,ci,f) { exb_output.innerHTML="..."; //server.parse({from:"ParseEng",cat:cat,input:s},fill_example) exb_call(g,ci,"abstract_example", - {cat:cat,input:s,abstract:example[0]}, + {cat:cat,input:s, + params:"["+f.args.join(",")+"]", + abstract:example[0]}, fill_example) } } -- cgit v1.2.3