mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-20 00:22:51 -06:00
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.home { padding: 5px; }
|
||||||
div.files { margin: 0 8px 8px 8px; }
|
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; }
|
pre.plain { border: 2px solid #009; }
|
||||||
div#file, pre.plain { background: white; padding: 0.6ex; }
|
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; }
|
.slideshow .hidden { display: none; }
|
||||||
|
|
||||||
img.cloud, img.right, div.right, div.modtime { float: right; }
|
img.cloud, img.right, div.right, div.modtime { float: right; }
|
||||||
|
|||||||
@@ -216,10 +216,66 @@ function compile_button(g,err_ind) {
|
|||||||
function minibar_button(g,files,err_ind) {
|
function minibar_button(g,files,err_ind) {
|
||||||
var b2;
|
var b2;
|
||||||
function show_editor() { edit_grammar(g); }
|
function show_editor() { edit_grammar(g); }
|
||||||
function goto_minibar(res) {
|
|
||||||
show_compile_error(res,err_ind);
|
function extend_grammar(cat0,fun_type0) {
|
||||||
if(res.errorcode=="OK") {
|
var fname0="New"+cat0;
|
||||||
//location.href=res.minibar_url;
|
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)]));
|
||||||
|
}
|
||||||
|
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);
|
clear(files);
|
||||||
files.appendChild(div_id("minibar"));
|
files.appendChild(div_id("minibar"));
|
||||||
var online_options={grammars_url: local.get("dir")+"/",
|
var online_options={grammars_url: local.get("dir")+"/",
|
||||||
@@ -231,6 +287,7 @@ function minibar_button(g,files,err_ind) {
|
|||||||
show_grouped_translations: false,
|
show_grouped_translations: false,
|
||||||
show_brackets: true,
|
show_brackets: true,
|
||||||
word_replacements: true,
|
word_replacements: true,
|
||||||
|
extend_grammar: extend_grammar,
|
||||||
default_source_language: "Eng",
|
default_source_language: "Eng",
|
||||||
try_google: true
|
try_google: true
|
||||||
}
|
}
|
||||||
@@ -242,11 +299,14 @@ function minibar_button(g,files,err_ind) {
|
|||||||
insertAfter(b2,b);
|
insertAfter(b2,b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function goto_minibar_if_ok(res) {
|
||||||
|
show_compile_error(res,err_ind);
|
||||||
|
if(res.errorcode=="OK") goto_minibar();
|
||||||
}
|
}
|
||||||
function compile() {
|
function compile() {
|
||||||
replaceInnerHTML(err_ind,"Compiling...");
|
replaceInnerHTML(err_ind,"Compiling...");
|
||||||
replaceInnerHTML(compiler_output,"<h3>Compiling...</h3>");
|
replaceInnerHTML(compiler_output,"<h3>Compiling...</h3>");
|
||||||
upload(g,goto_minibar);
|
upload(g,goto_minibar_if_ok);
|
||||||
}
|
}
|
||||||
var b=button("Minibar",compile);
|
var b=button("Minibar",compile);
|
||||||
b.title="Upload the grammar and test it in the minibar";
|
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) {
|
function browse1(fun_info) {
|
||||||
var fun_type = fun_info.def.split(":")[1];
|
var fun_type = fun_info.def.split(":")[1];
|
||||||
function browse2(cat_info) {
|
function browse2(cat_info) {
|
||||||
|
var extb=null;
|
||||||
function examine_replacement(rfun) {
|
function examine_replacement(rfun) {
|
||||||
function browse3(rfun_info) {
|
function browse3(rfun_info) {
|
||||||
var rfun_type=rfun_info.def.split(":")[1];
|
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);
|
t.replace_word(brackets,parent,rfun);
|
||||||
}
|
}
|
||||||
if(rfun_type==fun_type)
|
if(rfun_type==fun_type)
|
||||||
t.words.appendChild(button(rfun,replace))
|
t.words.insertBefore(button(rfun,replace),extb);
|
||||||
}
|
}
|
||||||
t.browse(rfun,browse3)
|
t.browse(rfun,browse3)
|
||||||
}
|
}
|
||||||
var ps=cat_info.producers;
|
var ps=cat_info.producers;
|
||||||
clear(t.words);
|
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)
|
if(ps)
|
||||||
for(var pi in ps)
|
for(var pi in ps)
|
||||||
if(ps[pi]!=fun) examine_replacement(ps[pi])
|
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 div_id(id,cs) { return node("div",{id:id},cs); }
|
||||||
function span_id(id) { return empty_id("span",id); }
|
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) {
|
function wrap_class(tag,cls,contents) {
|
||||||
return node(tag,{"class":cls},
|
return node(tag,{"class":cls},
|
||||||
|
|||||||
Reference in New Issue
Block a user