summaryrefslogtreecommitdiff
path: root/src/editor
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2011-09-29 15:19:03 +0000
committerhallgren <hallgren@chalmers.se>2011-09-29 15:19:03 +0000
commitbb585fef2cf88eeac08ee6f77de1f0ea8130b396 (patch)
tree1de62be3ed42695635f9fe8654e54ea18ef8c11f /src/editor
parentad725d85310e0055b21bdde66bcc43c5cd68fa97 (diff)
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.
Diffstat (limited to 'src/editor')
-rw-r--r--src/editor/simple/editor.js2
-rw-r--r--src/editor/simple/example_based.js24
2 files changed, 18 insertions, 8 deletions
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)
}
}