diff options
| author | john.j.camilleri <john.j.camilleri@chalmers.se> | 2012-11-21 11:22:35 +0000 |
|---|---|---|
| committer | john.j.camilleri <john.j.camilleri@chalmers.se> | 2012-11-21 11:22:35 +0000 |
| commit | 051b7b0d21ad8ac1fe42dfd09cd773b48b8fd8ea (patch) | |
| tree | ebec3f36d657b73844925b2a638348fd45c2acf2 /src/www/syntax-editor/editor.js | |
| parent | 0f59b25d8a311d513387a6eb7772613a3d19e0a8 (diff) | |
Syntax editor: start with initial grammar, startcat, to: languages
Diffstat (limited to 'src/www/syntax-editor/editor.js')
| -rw-r--r-- | src/www/syntax-editor/editor.js | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/src/www/syntax-editor/editor.js b/src/www/syntax-editor/editor.js index 33b8b496c..9fa7ad737 100644 --- a/src/www/syntax-editor/editor.js +++ b/src/www/syntax-editor/editor.js @@ -13,7 +13,20 @@ function Editor(server,opts) { // default values for options: this.options={ - target: "editor" + target: "editor", + initial: { + grammar: null, + startcat: null, + languages: null, + ast: null, + node_id: null + }, + show: { + grammar_menu: true, + startcat_menu: true, + to_menu: true, + random_button: true + } } // Apply supplied options @@ -35,11 +48,14 @@ function Editor(server,opts) { this.server = server; this.ast = null; this.grammar = null; + this.startcat = null; this.languages = []; - this.local = {}; // local settings which may override grammar /* --- Main program, this gets things going ----------------------------- */ - this.menu = new EditorMenu(this); + this.menu = new EditorMenu(this, this.options); + + /* --- Apply supplied initial settings (if any) ------------------------- */ +// if (this.options.initial.grammar) } @@ -65,24 +81,25 @@ Editor.prototype.get_ast=function() { } Editor.prototype.get_startcat=function() { - return this.local.startcat || this.grammar.startcat; + return this.startcat || this.grammar.startcat; } /* --- These get called from EditorMenu, or some custom code */ Editor.prototype.change_grammar=function(grammar_info) { - with(this) { - grammar = grammar_info; - local.startcat = null; - get_grammar_constructors(bind(start_fresh,this)); - } + var t = this; + t.grammar = grammar_info; + var startcat0 = t.options.initial.startcat + if (elem(startcat0, grammar_info.categories)) + t.startcat = startcat0; + else + t.startcat = null; + t.get_grammar_constructors(bind(t.start_fresh,t)); } Editor.prototype.change_startcat=function(startcat) { - with(this) { - local.startcat = startcat; - start_fresh(); - } + this.startcat = startcat; + this.start_fresh(); } // Called after changing grammar or startcat |
