summaryrefslogtreecommitdiff
path: root/src/www/syntax-editor
diff options
context:
space:
mode:
authorjohn.j.camilleri <john.j.camilleri@chalmers.se>2012-11-27 10:09:40 +0000
committerjohn.j.camilleri <john.j.camilleri@chalmers.se>2012-11-27 10:09:40 +0000
commitb3c1177f9ed5a3eaff378671fa119be1c605498e (patch)
tree6c32e5fc86fd45b91a934b8d0fc6da2cf236ab8a /src/www/syntax-editor
parentdef375e58808ea431ef0d786ae0abb9de0a67155 (diff)
Syntax editor: improvements and fixes with grammar manager
Diffstat (limited to 'src/www/syntax-editor')
-rw-r--r--src/www/syntax-editor/README.md30
-rw-r--r--src/www/syntax-editor/ast.js6
-rw-r--r--src/www/syntax-editor/editor.html2
-rw-r--r--src/www/syntax-editor/editor.js39
-rw-r--r--src/www/syntax-editor/editor_menu.js12
-rw-r--r--src/www/syntax-editor/editor_online.js9
6 files changed, 34 insertions, 64 deletions
diff --git a/src/www/syntax-editor/README.md b/src/www/syntax-editor/README.md
index 62c7e32cd..8857bc46a 100644
--- a/src/www/syntax-editor/README.md
+++ b/src/www/syntax-editor/README.md
@@ -13,21 +13,21 @@ An improved version of the [old syntax editor][1].
## Available startup options
- var editor_options = {
- target: "editor",
- initial: {
- grammar: "http://localhost:41296/grammars/Foods.pgf",
- startcat: "Kind",
- languages: ["Eng","Swe","Mlt"],
- abstr: "Pred (That Fish) Expensive"
- },
- show: {
- grammar_menu: true,
- startcat_menu: true,
- to_menu: true,
- random_button: true
- }
- }
+|Options|Description|Default|
+|:------|:----------|:------|
+|target | |"editor"|
+|initial.grammar|Initial grammar URL, e.g. `"http://localhost:41296/grammars/Foods.pgf"`|-|
+|initial.startcat|Initial startcat|-|
+|initial.languages|Initial linearisation languages, e.g. `["Eng","Swe","Mlt"]`|-|
+|initial.abstr|Initial abstract tree (as string), e.g. `"Pred (That Fish) Expensive"`|-|
+|show.grammar_menu|Show grammar menu?|true|
+|show.startcat_menu|Show start category menu?|true|
+|show.to_menu|Show languages menu?|true|
+|show.random_button|Show random button?|true|
+
+## Example usage
+
+See `editor.html` and `editor_online.js`.
## TODO
diff --git a/src/www/syntax-editor/ast.js b/src/www/syntax-editor/ast.js
index 143b9836c..2cad53600 100644
--- a/src/www/syntax-editor/ast.js
+++ b/src/www/syntax-editor/ast.js
@@ -8,7 +8,7 @@ function NodeID(x) {
switch (typeof x) {
case "number": this.id = [x]; break;
case "string": this.id = map(function(s){return parseInt(s)}, x.split(",")); break;
- case "object": this.id = x.get().slice(); break; // another NodeID
+ case "object": this.id = Array.clone(x.get()); break; // another NodeID
}
}
@@ -101,7 +101,7 @@ function AST(fun, cat) {
// set tree at given id
this._setSubtree = function(id, subtree) {
- var lid = id.get().slice(); // clone NodeID array
+ var lid = Array.clone(id.get()); // clone NodeID array
var node = this.root;
if (lid.length==1)
@@ -124,7 +124,7 @@ function AST(fun, cat) {
switch (typeof id) {
case "number": lid = [id]; break;
case "string": lid = id.split(","); break;
- case "object": lid = id.get().slice(); break; // clone NodeID array
+ case "object": lid = Array.clone(id.get()); break; // clone NodeID array
}
var node = this.root;
if (lid[0] == 0) lid.shift();
diff --git a/src/www/syntax-editor/editor.html b/src/www/syntax-editor/editor.html
index 403b4bbeb..8105df60d 100644
--- a/src/www/syntax-editor/editor.html
+++ b/src/www/syntax-editor/editor.html
@@ -11,7 +11,7 @@
<h2>Syntax Editor</h2>
<div id="minibar"></div>
<div id="editor"></div>
- <noscript>This page doesn't works unless JavaScript is enabled.</noscript>
+ <noscript>This page doesn't work unless JavaScript is enabled.</noscript>
<hr />
<small class="modtime">
diff --git a/src/www/syntax-editor/editor.js b/src/www/syntax-editor/editor.js
index 031a461a2..41360c53f 100644
--- a/src/www/syntax-editor/editor.js
+++ b/src/www/syntax-editor/editor.js
@@ -1,20 +1,4 @@
/* --- 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(gm,opts) {
var t = this;
/* --- Configuration ---------------------------------------------------- */
@@ -64,11 +48,6 @@ function Editor(gm,opts) {
/* --- Register Grammar Manager hooks ----------------------------------- */
this.gm.register_action("change_grammar",function(grammar){
debug("Editor: change grammar");
- var startcat0 = t.options.initial.startcat;
- if (elem(startcat0, grammar.categories))
- t.startcat = startcat0;
- else
- t.startcat = null;
t.get_grammar_constructors(bind(t.start_fresh,t));
});
this.gm.register_action("change_startcat",function(startcat){
@@ -124,19 +103,19 @@ Editor.prototype.get_startcat=function() {
}
// TODO
-Editor.prototype.initialize_from=function(opts) {
- var t=this;
- if (opts.startcat)
- t.options.initial_startcat=opts.startcat;
- t.change_grammar();
- if (opts.abstr)
- t.import_ast(opts.abstr);
-}
+// Editor.prototype.initialize_from=function(opts) {
+// var t=this;
+// if (opts.startcat)
+// t.options.initial_startcat=opts.startcat;
+// t.change_grammar();
+// if (opts.abstr)
+// t.import_ast(opts.abstr);
+// }
// Called after changing grammar or startcat
Editor.prototype.start_fresh=function () {
var t = this;
- t.ast = new AST(null, t.get_startcat());
+ t.ast = new AST(null, t.get_startcat());
if (t.options.initial.abstr) {
t.import_ast(t.options.initial.abstr);
}
diff --git a/src/www/syntax-editor/editor_menu.js b/src/www/syntax-editor/editor_menu.js
index e207133e7..31927a26e 100644
--- a/src/www/syntax-editor/editor_menu.js
+++ b/src/www/syntax-editor/editor_menu.js
@@ -107,7 +107,7 @@ EditorMenu.prototype.hook_onload=function(dir,grammar_names,dir_count) {
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;
+ var grammar0=t.gm.options.initial.grammar;
if(!grammar0) grammar0=t.grammars[0];
t.ui.grammar_menu.value=grammar0;
// t.change_grammar();
@@ -139,16 +139,11 @@ EditorMenu.prototype.update_startcat_menu=function(grammar) {
menu.innerHTML="";
var cats=grammar.categories;
for(var cat in cats) menu.appendChild(option(cats[cat],cats[cat]))
-// var startcat=this.local.get("startcat") || grammar.startcat;
- var startcat0 = t.options.initial.startcat;
+ var startcat0 = t.gm.options.initial.startcat;
if (elem(startcat0, cats))
menu.value = startcat0;
else
menu.value = grammar.startcat;
- // else {
- // insertFirst(menu,option("Default",""));
- // menu.value="";
- // }
}
/* --- Langugage (to) menu -------------------------------------------------- */
@@ -168,9 +163,8 @@ EditorMenu.prototype.update_language_menu=function(menu,grammar) {
if(!hasPrefix(ln,"Disamb")) {
var lp=langpart(ln,grammar.name);
var opt=option(lp,ln);
- if (elem(lp, t.options.initial.languages)) {
+ if (elem(lp, t.gm.options.initial.languages)) {
opt.selected=true;
- t.editor.languages.push(opt.value);
}
menu.appendChild(opt);
}
diff --git a/src/www/syntax-editor/editor_online.js b/src/www/syntax-editor/editor_online.js
index 5ca81c9fa..56e8a9de3 100644
--- a/src/www/syntax-editor/editor_online.js
+++ b/src/www/syntax-editor/editor_online.js
@@ -4,12 +4,9 @@ var server_options = {
}
var editor_options = {
target: "editor",
- // initial: {
- // grammar: "http://localhost:41296/grammars/Phrasebook.pgf",
- // startcat: "Proposition",
- // languages: ["Eng","Swe","Ita"],
- // abstr: "PropOpenDate (SuperlPlace TheMostExpensive School) Tomorrow"
- // },
+ initial: {
+// abstr: "PropOpenDate (SuperlPlace TheMostExpensive School) Tomorrow"
+ },
show: {
grammar_menu: true,
startcat_menu: true,