mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
Syntax editor: start with initial AST
Note that the argument has been renamed to initial.abstr (Where abstr means an abstract syntax tree in string form, NOT an AST object)
This commit is contained in:
@@ -19,8 +19,7 @@ An improved version of the [old syntax editor][1].
|
|||||||
grammar: "http://localhost:41296/grammars/Foods.pgf",
|
grammar: "http://localhost:41296/grammars/Foods.pgf",
|
||||||
startcat: "Kind",
|
startcat: "Kind",
|
||||||
languages: ["Eng","Swe","Mlt"],
|
languages: ["Eng","Swe","Mlt"],
|
||||||
ast: null,
|
abstr: "Pred (That Fish) Expensive"
|
||||||
node_id: null
|
|
||||||
},
|
},
|
||||||
show: {
|
show: {
|
||||||
grammar_menu: true,
|
grammar_menu: true,
|
||||||
@@ -33,7 +32,6 @@ An improved version of the [old syntax editor][1].
|
|||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
- Link to jump into minibar
|
- Link to jump into minibar
|
||||||
- Start with initial grammar, startcat, ast
|
|
||||||
- Compatibility with grammars with dependent category types
|
- Compatibility with grammars with dependent category types
|
||||||
- Clicking on tokens to select tree node
|
- Clicking on tokens to select tree node
|
||||||
- Use local caching
|
- Use local caching
|
||||||
|
|||||||
@@ -7,6 +7,22 @@
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
/* --- Main Editor object --------------------------------------------------- */
|
/* --- Main Editor object --------------------------------------------------- */
|
||||||
|
/* When creating the object, stuff gets called in this order:
|
||||||
|
new EditorMenu
|
||||||
|
server.get_grammarlists
|
||||||
|
EditorMenu.show_grammarlist
|
||||||
|
EditorMenu.change_grammar
|
||||||
|
server.switch_to_other_grammar
|
||||||
|
server.get_grammar_info
|
||||||
|
EditorMenu.update_startcat_menu
|
||||||
|
EditorMenu.update_language_menu
|
||||||
|
Editor.change_grammar
|
||||||
|
Editor.get_grammar_constructors
|
||||||
|
Editor.start_fresh
|
||||||
|
Editor.update_current_node();
|
||||||
|
Editor.redraw_tree();
|
||||||
|
Editor.get_refinements();
|
||||||
|
*/
|
||||||
function Editor(server,opts) {
|
function Editor(server,opts) {
|
||||||
var t = this;
|
var t = this;
|
||||||
/* --- Configuration ---------------------------------------------------- */
|
/* --- Configuration ---------------------------------------------------- */
|
||||||
@@ -18,7 +34,7 @@ function Editor(server,opts) {
|
|||||||
grammar: null,
|
grammar: null,
|
||||||
startcat: null,
|
startcat: null,
|
||||||
languages: null,
|
languages: null,
|
||||||
ast: null,
|
abstr: null,
|
||||||
node_id: null
|
node_id: null
|
||||||
},
|
},
|
||||||
show: {
|
show: {
|
||||||
@@ -98,19 +114,20 @@ Editor.prototype.change_grammar=function(grammar_info) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Editor.prototype.change_startcat=function(startcat) {
|
Editor.prototype.change_startcat=function(startcat) {
|
||||||
this.startcat = startcat;
|
var t = this;
|
||||||
this.start_fresh();
|
t.startcat = startcat;
|
||||||
|
t.start_fresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called after changing grammar or startcat
|
// Called after changing grammar or startcat
|
||||||
Editor.prototype.start_fresh=function () {
|
Editor.prototype.start_fresh=function () {
|
||||||
with(this) {
|
var t = this;
|
||||||
ast = new AST(null, get_startcat());
|
t.ast = new AST(null, t.get_startcat());
|
||||||
redraw_tree();
|
if (t.options.initial.abstr) {
|
||||||
update_current_node();
|
t.import_ast(t.options.initial.abstr);
|
||||||
get_refinements();
|
|
||||||
clear(ui.lin);
|
|
||||||
}
|
}
|
||||||
|
t.update_current_node();
|
||||||
|
clear(t.ui.lin);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- Functions for handling tree manipulation ----------------------------- */
|
/* --- Functions for handling tree manipulation ----------------------------- */
|
||||||
|
|||||||
@@ -59,9 +59,7 @@ function EditorMenu(editor,opts) {
|
|||||||
this.server = editor.server;
|
this.server = editor.server;
|
||||||
|
|
||||||
/* --- Main program, this gets things going ----------------------------- */
|
/* --- Main program, this gets things going ----------------------------- */
|
||||||
with(this) {
|
this.server.get_grammarlists(bind(this.show_grammarlist,this));
|
||||||
server.get_grammarlists(bind(show_grammarlist,this));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- Grammar menu --------------------------------------------------------- */
|
/* --- Grammar menu --------------------------------------------------------- */
|
||||||
@@ -75,25 +73,23 @@ EditorMenu.prototype.show_grammarlist=function(dir,grammar_names,dir_count) {
|
|||||||
t.grammars=[];
|
t.grammars=[];
|
||||||
t.grammar_dirs=[];
|
t.grammar_dirs=[];
|
||||||
}
|
}
|
||||||
with(t) {
|
t.grammar_dirs.push(dir);
|
||||||
grammar_dirs.push(dir);
|
t.grammars=t.grammars.concat(grammar_names.map(function(g){return dir+g}))
|
||||||
grammars=grammars.concat(grammar_names.map(function(g){return dir+g}))
|
function glabel(g) {
|
||||||
function glabel(g) {
|
return hasPrefix(dir,"/tmp/gfse.") ? "gfse: "+g : g
|
||||||
return hasPrefix(dir,"/tmp/gfse.") ? "gfse: "+g : g
|
|
||||||
}
|
|
||||||
function opt(g) { return option(glabel(g),dir+g); }
|
|
||||||
appendChildren(t.ui.grammar_menu,map(opt,grammar_names));
|
|
||||||
function pick_first_grammar() {
|
|
||||||
if(t.timeout) clearTimeout(t.timeout),t.timeout=null;
|
|
||||||
var grammar0=t.options.initial.grammar;
|
|
||||||
if(!grammar0) grammar0=t.grammars[0];
|
|
||||||
t.ui.grammar_menu.value=grammar0;
|
|
||||||
t.change_grammar();
|
|
||||||
}
|
|
||||||
// Wait at most 1.5s before showing the grammar menu.
|
|
||||||
if(first_time) t.timeout=setTimeout(pick_first_grammar,1500);
|
|
||||||
if(t.grammar_dirs.length>=dir_count) pick_first_grammar();
|
|
||||||
}
|
}
|
||||||
|
function opt(g) { return option(glabel(g),dir+g); }
|
||||||
|
appendChildren(t.ui.grammar_menu, map(opt, grammar_names));
|
||||||
|
function pick_first_grammar() {
|
||||||
|
if(t.timeout) clearTimeout(t.timeout),t.timeout=null;
|
||||||
|
var grammar0=t.options.initial.grammar;
|
||||||
|
if(!grammar0) grammar0=t.grammars[0];
|
||||||
|
t.ui.grammar_menu.value=grammar0;
|
||||||
|
t.change_grammar();
|
||||||
|
}
|
||||||
|
// Wait at most 1.5s before showing the grammar menu.
|
||||||
|
if(first_time) t.timeout=setTimeout(pick_first_grammar,1500);
|
||||||
|
if(t.grammar_dirs.length>=dir_count) pick_first_grammar();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copied from minibar.js
|
// Copied from minibar.js
|
||||||
@@ -102,8 +98,8 @@ EditorMenu.prototype.change_grammar=function() {
|
|||||||
var grammar_url = t.ui.grammar_menu.value;
|
var grammar_url = t.ui.grammar_menu.value;
|
||||||
t.server.switch_to_other_grammar(grammar_url, function() {
|
t.server.switch_to_other_grammar(grammar_url, function() {
|
||||||
t.server.grammar_info(function(grammar){
|
t.server.grammar_info(function(grammar){
|
||||||
t.update_language_menu(t.ui.to_menu, grammar);
|
|
||||||
t.update_startcat_menu(grammar);
|
t.update_startcat_menu(grammar);
|
||||||
|
t.update_language_menu(t.ui.to_menu, grammar);
|
||||||
|
|
||||||
// Call in main Editor object
|
// Call in main Editor object
|
||||||
t.editor.change_grammar(grammar);
|
t.editor.change_grammar(grammar);
|
||||||
|
|||||||
Reference in New Issue
Block a user