diff --git a/src/www/gfse/editor.js b/src/www/gfse/editor.js index 34486f429..eafdf1d98 100644 --- a/src/www/gfse/editor.js +++ b/src/www/gfse/editor.js @@ -148,14 +148,16 @@ function edit_grammar(g) { function draw_grammar(g) { switch(g.view) { case "matrix": - var matrix=div_class("files",draw_matrix(g)) - return div_class("grammar",[draw_namebar(g,matrix),matrix]) + var files=div_class("files",draw_matrix(g)) + break; case "row": - /* ... */ + var files=div_class("files",draw_row(g)) + break; default: var files=div_class("files",[draw_filebar(g),draw_file(g)]); - return div_class("grammar",[draw_namebar(g,files),files]) + break; } + return div_class("grammar",[draw_namebar(g,files),files]) } function draw_namebar(g,files) { @@ -525,6 +527,7 @@ function add_concrete2(ix,code) { function open_abstract(g) { g.view="column"; g.current=0; reload_grammar(g); } function open_concrete(g,i) { g.view="column"; g.current=i+1; reload_grammar(g); } function open_matrix(g) { g.view="matrix"; reload_grammar(g); } +function open_row(g,fun) { g.view="row"; g.row=fun; reload_grammar(g); } function td_gap(c) {return wrap_class("td","gap",c); } function gap() { return td_gap(text(" ")); } @@ -550,11 +553,12 @@ function abs_tab_button(g) { return button("Abstract",function(){open_abstract(g);}) } -function conc_tab_button(g,ci) { +function conc_tab_button(g,ci,no_delete) { var cs=g.concretes function del() { delete_concrete(g,ci); } function open_conc() {open_concrete(g,1*ci); } - return deletable(del,button(concname(cs[ci].langcode),open_conc),"Delete this concrete syntax") + var b=button(concname(cs[ci].langcode),open_conc) + return no_delete ? b : deletable(del,b,"Delete this concrete syntax") } function draw_filebar(g) { @@ -1286,29 +1290,25 @@ function arg_names(type) { return map(unique,names); } -function draw_lins(g,ci) { +function draw_elin(g,igs,ci,f,dc,df) { + var fun=f.fun; var conc=g.concretes[ci]; - var igs=inherited_grammars(g) - var dc=defined_cats(g); - function edit(f) { - return function(g,el) { - function check(s,cont) { - function check2(msg) { - if(!msg) { - if(f.template) - conc.lins.push({fun:f.fun,args:f.args,lin:s}); - else { f.lin=s; f.eb_lin=null; } - reload_grammar(g); - } - cont(msg); + function edit(g,el) { + function check(s,cont) { + function check2(msg) { + if(!msg) { + if(f.template) + conc.lins.push({fun:f.fun,args:f.args,lin:s}); + else { f.lin=s; f.eb_lin=null; } + reload_grammar(g); } - check_exp(s,check2); + cont(msg); } - string_editor(el,f.lin,check,true) + check_exp(s,check2); } + string_editor(el,f.lin,check,true) } - function del(fun) { return function () { delete_lin(g,ci,fun); } } - function dl(f,cls) { + function dl(cls) { var fn=ident(f.fun) var fty=function_type(g,f.fun) var linty=fty && lintype(g,conc,igs,dc,fty) @@ -1323,28 +1323,39 @@ function draw_lins(g,ci) { l.push(an); } l.push(sep(" = ")); - var t=editable("span",text_ne(f.lin),g,edit(f),"Edit lin for "+f.fun); + var t=editable("span",text_ne(f.lin),g,edit,"Edit lin for "+f.fun); t.appendChild(exb_linbuttons(g,ci,f)); l.push(t); return node("span",{"class":cls},l); } + function del() { delete_lin(g,ci,fun); } + var l=dl(f.template ? "template" : "lin") + if(!f.template) { + l=deletable(del,l,"Delete this linearization function") + delete df[fun]; + } + return l; +} + +function lin_template(g,f) { + var args=arg_names(function_type(g,f)) + return {fun:f,args:args,lin:"",template:true} +} + +function draw_lins(g,ci) { + var conc=g.concretes[ci]; + var igs=inherited_grammars(g) + var dc=defined_cats(g); var df=locally_defined_funs(g,{}); function draw_lin(f) { - var fun=f.fun; - var err= !df[fun]; - var l= deletable(del(fun),dl(f,"lin"),"Delete this linearization function") - var l=ifError(err,"Function "+fun+" is not part of the abstract syntax",l); - delete df[fun]; - return node_sortable("lin",fun,[l]); - } - function largs(f) { - var funs=g.abstract.funs; - for(var i=0;i FunId -> Type -function function_type(g,fun) { +// Return the index of the function the given name in the abstract syntax +// find_function :: Grammar -> FunId -> (Int|null) +function fun_index(g,fun) { with(g.abstract) - for(var i in funs) if(funs[i].name==fun) return funs[i].type + for(var i in funs) if(funs[i].name==fun) return i return null; } +// Return the type of a named function in the abstract syntax +// function_type :: Grammar -> FunId -> (Type|null) +function function_type(g,fun) { + var ix=fun_index(g,fun) + return ix==null ? null : g.abstract.funs[ix].type +} + // Return the lincat defined in a given concrete syntax for an abstract category -// cat_lincat :: Concrete -> Cat -> Term +// cat_lincat :: Concrete -> Cat -> (Term|null) function cat_lincat(conc,cat) { with(conc) for(var i in lincats) if(lincats[i].cat==cat) return lincats[i].type @@ -87,14 +94,14 @@ function cat_lincat(conc,cat) { } // Return the lin defined in a given concrete syntax for an abstract function -// fun_lin :: Concrete -> FunId -> Lin +// fun_lin :: Concrete -> FunId -> (Lin|null) function fun_lin(conc,fun) { with(conc) for(var i in lins) if(lins[i].fun==fun) return lins[i] return null; } // Return the index of the concrete syntax with a given langcode -// conc_index :: Grammar -> Id -> Int +// conc_index :: Grammar -> Id -> (Int|null) function conc_index(g,langcode) { var c=g.concretes; for(var ix=0;ix