diff options
| author | hallgren <hallgren@chalmers.se> | 2011-10-12 17:03:54 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2011-10-12 17:03:54 +0000 |
| commit | 44d1a5a9f71b03d9aceeccd760a63fcdc45f8bad (patch) | |
| tree | d51076a708997d6f1af6ac0deefd535bbc25f804 /src/www/minibar/pgf_online.js | |
| parent | 0aba45560d2033c37c3d2e876e6f3ef89e1554d6 (diff) | |
Improvements of "gf -server" mode and related setup
"gf -server" mode now contains everything needed to run the minibar and
the grammar editor (including example-based grammar writing).
The Setup.hs script installs the required files where gf -server can find them.
These files have been moved to a new directory: src/www.
The separate server program pgf-http is now obsolete.
Diffstat (limited to 'src/www/minibar/pgf_online.js')
| -rw-r--r-- | src/www/minibar/pgf_online.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/www/minibar/pgf_online.js b/src/www/minibar/pgf_online.js new file mode 100644 index 000000000..ac6620ee5 --- /dev/null +++ b/src/www/minibar/pgf_online.js @@ -0,0 +1,52 @@ + +/* --- Grammar access object ------------------------------------------------ */ + +function pgf_online(options) { + var server = { + // State variables (private): + grammars_url: "/grammars/", + grammar_list: null, + current_grammar_url: null, + + // Methods: + switch_grammar: function(grammar_url,cont) { + this.current_grammar_url=this.grammars_url+grammar_url; + if(cont) cont(); + }, + get_grammarlist: function(cont) { + http_get_json(this.grammars_url+"grammars.cgi",cont); + }, + pgf_call: function(cmd,args,cont) { + var url=this.current_grammar_url+"?command="+cmd+encodeArgs(args) + http_get_json(url,cont); + }, + + get_languages: function(cont) { this.pgf_call("grammar",{},cont); }, + grammar_info: function(cont) { this.pgf_call("grammar",{},cont); }, + + get_random: function(args,cont) { // cat, limit + args.random=Math.random(); // side effect!! + this.pgf_call("random",args,cont); + }, + linearize: function(args,cont) { // tree, to + this.pgf_call("linearize",args,cont); + }, + complete: function(args,cont) { // from, input, cat, limit + this.pgf_call("complete",args,cont); + }, + parse: function(args,cont) { // from, input, cat + this.pgf_call("parse",args,cont); + }, + translate: function(args,cont) { // from, input, cat, to + this.pgf_call("translate",args,cont); + }, + translategroup: function(args,cont) { // from, input, cat, to + this.pgf_call("translategroup",args,cont); + } + + }; + for(var o in options) server[o]=options[o]; + if(server.grammar_list && server.grammar_list.length>0) + server.switch_grammar(server.grammar_list[0]); + return server; +}
\ No newline at end of file |
