summaryrefslogtreecommitdiff
path: root/src/runtime/javascript/minibar/pgf_offline.js
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2011-10-12 17:03:54 +0000
committerhallgren <hallgren@chalmers.se>2011-10-12 17:03:54 +0000
commit44d1a5a9f71b03d9aceeccd760a63fcdc45f8bad (patch)
treed51076a708997d6f1af6ac0deefd535bbc25f804 /src/runtime/javascript/minibar/pgf_offline.js
parent0aba45560d2033c37c3d2e876e6f3ef89e1554d6 (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/runtime/javascript/minibar/pgf_offline.js')
-rw-r--r--src/runtime/javascript/minibar/pgf_offline.js96
1 files changed, 0 insertions, 96 deletions
diff --git a/src/runtime/javascript/minibar/pgf_offline.js b/src/runtime/javascript/minibar/pgf_offline.js
deleted file mode 100644
index cd2d40b1c..000000000
--- a/src/runtime/javascript/minibar/pgf_offline.js
+++ /dev/null
@@ -1,96 +0,0 @@
-// Assumes that Services.js has been loaded
-
-function pgf_offline(options) {
- var server = {
- // State variables (private):
- grammars_url: "",
- grammar_list: ["Foods.pgf"],
-
- current_grammar_url: null,
- pgf : null,
-
- // Methods:
- switch_grammar: function(grammar_url,cont) {
- //debug("switch_grammar ");
- var new_grammar_url=this.grammars_url+grammar_url;
- var self=this;
- var update_pgf=function(pgfbinary) {
- debug("Got "+new_grammar_url+", length="
- +pgfbinary.length+", parsing... ");
- self.pgf = {v: Services_decodePGF.v({v:pgfbinary}) }
- //debug("done")
- self.current_grammar_url=new_grammar_url;
- cont();
- }
- ajax_http_get_binary(new_grammar_url,update_pgf);
- },
- get_grammarlist: function(cont) { cont([this.grammar_list]); },
-
- get_languages: function(cont) {
- cont(fromJSValue(Services_grammar.v(this.pgf)))
- },
- grammar_info: function(cont) {
- cont(fromJSValue(Services_grammar.v(this.pgf)))
- },
-
- get_random: function(cont) {
- alert("Random generation not supported yet in the offline version");
- },
- linearize: function(args,cont) {
- cont(fromJSValue(Services_linearize.v(this.pgf)(v(args.tree))(v(args.to))));
- },
- complete: function(args,cont) {
- cont(fromJSValue(Services_complete.v(this.pgf)(v(args.from))(v(args.input))));
- },
- parse: function(args,cont) {
- cont(fromJSValue(Services_parse.v(this.pgf)(v(args.from))(v(args.input))));
- },
- translate: function(args,cont) {
- cont(fromJSValue(Services_translate.v(this.pgf)(v(args.from))(v(args.input))));
- },
- translategroup: function(args,cont) {
- cont(fromJSValue(Services_translategroup.v(this.pgf)(v(args.from))(v(args.input))));
- }
- };
- for(var o in options) server[o]=options[o];
- return server;
-};
-
-
-
-// See https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest
-function ajax_http_get_binary(url,callback) {
- var http=GetXmlHttpObject()
- if (http==null) {
- alert ("Browser does not support HTTP Request")
- return
- }
- var statechange=function() {
- if (http.readyState==4 || http.readyState=="complete") {
- if(http.status==200) {
- var buffer=http.mozResponseArrayBuffer;
- if(buffer) callback(bufferToString(buffer)) // Gecko 2 (Firefox 4)
- else callback(http.responseText); // other browsers
- }
- else alert("Request for "+url+" failed: "
- +http.status+" "+http.statusText);
- }
- }
- http.onreadystatechange=statechange;
- http.open("GET",url,true);
- http.overrideMimeType('text/plain; charset=x-user-defined');
- http.send(null);
- //dump("http get "+url+"\n")
- return http;
-}
-
-function bufferToString(buffer) {
- // This function converts to the current representation of ByteString,
- // but it would be better to use binary buffers for ByteStrings as well.
- debug("bufferToString");
- var u=new Uint8Array(buffer);
- var a=new Array(u.length);
- for(var i=0;i<u.length;i++)
- a[i]=String.fromCharCode(u[i]);
- return a.join("");
-}