forked from GitHub/gf-core
gfse&minibar: work in progress on grammar extension fromminibar
This commit is contained in:
@@ -17,10 +17,16 @@ div.home, div.grammar { border: 1px solid black; background: #9df; }
|
||||
div.home { padding: 5px; }
|
||||
div.files { margin: 0 8px 8px 8px; }
|
||||
|
||||
div#file { border: 2px solid #009; border-top-width: 0; }
|
||||
div#file, table.extension td, table.extension th { border: 2px solid #009 }
|
||||
div#file { border-top-width: 0; }
|
||||
pre.plain { border: 2px solid #009; }
|
||||
div#file, pre.plain { background: white; padding: 0.6ex; }
|
||||
|
||||
table.extension { border-collapse: collapse; background: white; }
|
||||
table.extension td, table.extension th { padding: 1ex; }
|
||||
table.extension th { border-right-width: 0; color: #009; }
|
||||
table.extension td { border-left-width: 0; }
|
||||
|
||||
.slideshow .hidden { display: none; }
|
||||
|
||||
img.cloud, img.right, div.right, div.modtime { float: right; }
|
||||
|
||||
@@ -216,37 +216,97 @@ function compile_button(g,err_ind) {
|
||||
function minibar_button(g,files,err_ind) {
|
||||
var b2;
|
||||
function show_editor() { edit_grammar(g); }
|
||||
function goto_minibar(res) {
|
||||
show_compile_error(res,err_ind);
|
||||
if(res.errorcode=="OK") {
|
||||
//location.href=res.minibar_url;
|
||||
clear(files);
|
||||
files.appendChild(div_id("minibar"));
|
||||
var online_options={grammars_url: local.get("dir")+"/",
|
||||
grammar_list: [g.basename+".pgf"]}
|
||||
var pgf_server=pgf_online(online_options)
|
||||
var minibar_options= {
|
||||
show_abstract: true,
|
||||
show_trees: true,
|
||||
show_grouped_translations: false,
|
||||
show_brackets: true,
|
||||
word_replacements: true,
|
||||
default_source_language: "Eng",
|
||||
try_google: true
|
||||
|
||||
function extend_grammar(cat0,fun_type0) {
|
||||
var fname0="New"+cat0;
|
||||
var fun=parse_fun(fname0+" : " + fun_type0).ok;
|
||||
var lins=[];
|
||||
var dc=defined_cats(g),df=inherited_funs(g);
|
||||
var cs=g.concretes
|
||||
|
||||
function draw_extension() {
|
||||
var cat=fun.type[fun.type.length-1]
|
||||
files.innerHTML="<h4>Extending "+cat+"</h4>"
|
||||
var ef=editable("span",draw_fun(g,fun,dc,df),g,edit_fun,
|
||||
"Edit this function")
|
||||
var tbl=empty_class("table","extension");
|
||||
tbl.appendChild(tr([th(text("Abstract")),td([kw("fun "),ef])]));
|
||||
var anames=arg_names(fun.type);
|
||||
for(var i in cs) {
|
||||
var lc=cs[i].langcode;
|
||||
var l=[kw("lin "),ident(fun.name)];
|
||||
for(var j in anames) { l.push(text(" ")); l.push(ident(anames[j]));}
|
||||
l.push(sep(" = "))
|
||||
l.push(editable("span",text(lins[lc] || "..."),g,edit_lin(lc),
|
||||
"Edit this linearization"))
|
||||
tbl.appendChild(tr([th(text(concname(cs[i].langcode))),td(l)]));
|
||||
}
|
||||
var minibar=new Minibar(pgf_server,minibar_options);
|
||||
b.style.display="none";
|
||||
if(b2) b2.style.display="";
|
||||
else {
|
||||
b2=button("Show editor",show_editor);
|
||||
insertAfter(b2,b);
|
||||
files.appendChild(tbl);
|
||||
files.appendChild(button("OK",save_extension))
|
||||
files.appendChild(button("Cancel",cancel_extension))
|
||||
}
|
||||
function edit_fun(g,el) {
|
||||
function replace(s) {
|
||||
var p=parse_fun(s);
|
||||
if(p.ok) {
|
||||
fun=p.ok;
|
||||
draw_extension();
|
||||
return null;
|
||||
}
|
||||
else
|
||||
return p.error;
|
||||
}
|
||||
string_editor(el,show_fun(fun),replace);
|
||||
}
|
||||
function edit_lin(lc) {
|
||||
return function (g,el) {
|
||||
function replace(s) {
|
||||
lins[lc]=s;
|
||||
draw_extension();
|
||||
return null;
|
||||
}
|
||||
string_editor(el,lins[lc] || "",replace);
|
||||
}
|
||||
}
|
||||
function save_extension() { }
|
||||
function cancel_extension() {
|
||||
goto_minibar();
|
||||
}
|
||||
draw_extension();
|
||||
}
|
||||
|
||||
function goto_minibar() {
|
||||
clear(files);
|
||||
files.appendChild(div_id("minibar"));
|
||||
var online_options={grammars_url: local.get("dir")+"/",
|
||||
grammar_list: [g.basename+".pgf"]}
|
||||
var pgf_server=pgf_online(online_options)
|
||||
var minibar_options= {
|
||||
show_abstract: true,
|
||||
show_trees: true,
|
||||
show_grouped_translations: false,
|
||||
show_brackets: true,
|
||||
word_replacements: true,
|
||||
extend_grammar: extend_grammar,
|
||||
default_source_language: "Eng",
|
||||
try_google: true
|
||||
}
|
||||
var minibar=new Minibar(pgf_server,minibar_options);
|
||||
b.style.display="none";
|
||||
if(b2) b2.style.display="";
|
||||
else {
|
||||
b2=button("Show editor",show_editor);
|
||||
insertAfter(b2,b);
|
||||
}
|
||||
}
|
||||
function goto_minibar_if_ok(res) {
|
||||
show_compile_error(res,err_ind);
|
||||
if(res.errorcode=="OK") goto_minibar();
|
||||
}
|
||||
function compile() {
|
||||
replaceInnerHTML(err_ind,"Compiling...");
|
||||
replaceInnerHTML(compiler_output,"<h3>Compiling...</h3>");
|
||||
upload(g,goto_minibar);
|
||||
upload(g,goto_minibar_if_ok);
|
||||
}
|
||||
var b=button("Minibar",compile);
|
||||
b.title="Upload the grammar and test it in the minibar";
|
||||
|
||||
@@ -363,6 +363,7 @@ Input.prototype.show_replacements=function(brackets,parent) {
|
||||
function browse1(fun_info) {
|
||||
var fun_type = fun_info.def.split(":")[1];
|
||||
function browse2(cat_info) {
|
||||
var extb=null;
|
||||
function examine_replacement(rfun) {
|
||||
function browse3(rfun_info) {
|
||||
var rfun_type=rfun_info.def.split(":")[1];
|
||||
@@ -370,12 +371,17 @@ Input.prototype.show_replacements=function(brackets,parent) {
|
||||
t.replace_word(brackets,parent,rfun);
|
||||
}
|
||||
if(rfun_type==fun_type)
|
||||
t.words.appendChild(button(rfun,replace))
|
||||
t.words.insertBefore(button(rfun,replace),extb);
|
||||
}
|
||||
t.browse(rfun,browse3)
|
||||
}
|
||||
var ps=cat_info.producers;
|
||||
clear(t.words);
|
||||
if(t.options.extend_grammar) {
|
||||
extb=button("New "+cat+"...",
|
||||
function() { t.options.extend_grammar(cat,fun_type)})
|
||||
t.words.appendChild(extb)
|
||||
}
|
||||
if(ps)
|
||||
for(var pi in ps)
|
||||
if(ps[pi]!=fun) examine_replacement(ps[pi])
|
||||
|
||||
@@ -146,7 +146,9 @@ function empty_class(tag,cls) { return empty(tag,"class",cls); }
|
||||
function div_id(id,cs) { return node("div",{id:id},cs); }
|
||||
function span_id(id) { return empty_id("span",id); }
|
||||
|
||||
function wrap(tag,contents) { return node(tag,{},[contents]); }
|
||||
function wrap(tag,contents) {
|
||||
return node(tag,{},Array.isArray(contents) ? contents : [contents]);
|
||||
}
|
||||
|
||||
function wrap_class(tag,cls,contents) {
|
||||
return node(tag,{"class":cls},
|
||||
|
||||
Reference in New Issue
Block a user