diff --git a/src/www/syntax-editor/README.md b/src/www/syntax-editor/README.md index 5da1f507f..04ae031b6 100644 --- a/src/www/syntax-editor/README.md +++ b/src/www/syntax-editor/README.md @@ -19,8 +19,7 @@ An improved version of the [old syntax editor][1]. grammar: "http://localhost:41296/grammars/Foods.pgf", startcat: "Kind", languages: ["Eng","Swe","Mlt"], - ast: null, - node_id: null + abstr: "Pred (That Fish) Expensive" }, show: { grammar_menu: true, @@ -33,7 +32,6 @@ An improved version of the [old syntax editor][1]. ## TODO - Link to jump into minibar -- Start with initial grammar, startcat, ast - Compatibility with grammars with dependent category types - Clicking on tokens to select tree node - Use local caching diff --git a/src/www/syntax-editor/editor.js b/src/www/syntax-editor/editor.js index 9fa7ad737..df2a49da8 100644 --- a/src/www/syntax-editor/editor.js +++ b/src/www/syntax-editor/editor.js @@ -7,6 +7,22 @@ // } /* --- 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) { var t = this; /* --- Configuration ---------------------------------------------------- */ @@ -18,7 +34,7 @@ function Editor(server,opts) { grammar: null, startcat: null, languages: null, - ast: null, + abstr: null, node_id: null }, show: { @@ -98,19 +114,20 @@ Editor.prototype.change_grammar=function(grammar_info) { } Editor.prototype.change_startcat=function(startcat) { - this.startcat = startcat; - this.start_fresh(); + var t = this; + t.startcat = startcat; + t.start_fresh(); } // Called after changing grammar or startcat Editor.prototype.start_fresh=function () { - with(this) { - ast = new AST(null, get_startcat()); - redraw_tree(); - update_current_node(); - get_refinements(); - clear(ui.lin); + var t = this; + t.ast = new AST(null, t.get_startcat()); + if (t.options.initial.abstr) { + t.import_ast(t.options.initial.abstr); } + t.update_current_node(); + clear(t.ui.lin); } /* --- Functions for handling tree manipulation ----------------------------- */ diff --git a/src/www/syntax-editor/editor_menu.js b/src/www/syntax-editor/editor_menu.js index 3d813a79b..2caa5a658 100644 --- a/src/www/syntax-editor/editor_menu.js +++ b/src/www/syntax-editor/editor_menu.js @@ -59,9 +59,7 @@ function EditorMenu(editor,opts) { this.server = editor.server; /* --- Main program, this gets things going ----------------------------- */ - with(this) { - server.get_grammarlists(bind(show_grammarlist,this)); - } + this.server.get_grammarlists(bind(this.show_grammarlist,this)); } /* --- Grammar menu --------------------------------------------------------- */ @@ -75,25 +73,23 @@ EditorMenu.prototype.show_grammarlist=function(dir,grammar_names,dir_count) { t.grammars=[]; t.grammar_dirs=[]; } - with(t) { - grammar_dirs.push(dir); - grammars=grammars.concat(grammar_names.map(function(g){return dir+g})) - function glabel(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(); + t.grammar_dirs.push(dir); + t.grammars=t.grammars.concat(grammar_names.map(function(g){return dir+g})) + function glabel(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(); } // Copied from minibar.js @@ -102,8 +98,8 @@ EditorMenu.prototype.change_grammar=function() { var grammar_url = t.ui.grammar_menu.value; t.server.switch_to_other_grammar(grammar_url, function() { t.server.grammar_info(function(grammar){ - t.update_language_menu(t.ui.to_menu, grammar); t.update_startcat_menu(grammar); + t.update_language_menu(t.ui.to_menu, grammar); // Call in main Editor object t.editor.change_grammar(grammar);