diff --git a/src/editor/simple/about.html b/src/editor/simple/about.html
index 050812ca3..a488c6e56 100644
--- a/src/editor/simple/about.html
+++ b/src/editor/simple/about.html
@@ -116,7 +116,8 @@ At the moment, the concrete syntax for a language L is limited to
linearizations for the functions in the abstract syntax,
parameter type definitions,
P = C1 | ... |Cn,
- and operation definitions, op = expr.
+ and operation definitions, op = expr,
+ op : type = expr,
Available editing operations:
@@ -146,8 +147,11 @@ Also,
Error checks:
- - The RHSs in the concrete syntax are not checked for errors. Arbitrary
- strings can be entered.
+
- The RHSs in the concrete syntax are checked
+ for syntactic correctness by the editor as they are entered.
+ (TODO: the syntax of parameter types is not check at the moment.)
+
- Duplicated definitions are highlighted. Checks for other
+ semantic errors are delayed until the grammar is compiled.
Compiling and testing grammars
@@ -164,7 +168,7 @@ cloud
While the editor normally stores grammars locally in the browser, it is also
possible to store grammars in the cloud. Grammars can be stored in the cloud
-just for backup, or to accessed them from multiple devices.
+just for backup, or to make them accessible from multiple devices.
There is no automatic synchronization between local grammars and the cloud.
@@ -197,14 +201,13 @@ devices, but not recommended for sharing grammars between multiple users.
Also note that each grammar is assigned a unique identity
-when it is created. Renaming a grammar does not change its identity. This means
-that name changes are propagated between devices like other changes.
+when it is first created. Renaming a grammar does not change its identity.
+This means that name changes are propagated between devices like other changes.
Future work
This prototype gives an idea of how a web based GF grammar editor could work.
-While this editor is implemented in JavaScript and runs entirely in the
-web browser,
+While this editor is implemented in JavaScript and runs in the web browser,
we do not expect to create a full implementation of GF that runs in the
web browser, but let the editor communicate with a server running GF.
@@ -214,7 +217,7 @@ to do proper error checking and make more of the existing GF shell functionality
accessible directly from the editor.
The current grammar cloud service is very primitive. In particular, it is not
-suitable for multiple users developing a grammar in collaboration.
+suitable for multiple users developing a grammar in collaboration.
Related documents
TH
diff --git a/src/editor/simple/cloud.js b/src/editor/simple/cloud.js
index cd2b9a442..fad66e1ff 100644
--- a/src/editor/simple/cloud.js
+++ b/src/editor/simple/cloud.js
@@ -136,6 +136,11 @@ function gfshell(cmd,cont) {
// Check the syntax of an expression
function check_exp(s,cont) {
- // Not implemented yet!!
- cont(null)
+ function check(gf_message) {
+ debug("cc "+s+" = "+gf_message);
+ cont(/parse error/.test(gf_message) ? "parse error" : null);
+ }
+ if(navigator.onLine)
+ ajax_http_get("upload.cgi?cc="+encodeURIComponent(s),check)
+ else cont(null)
}
diff --git a/src/editor/simple/editor.js b/src/editor/simple/editor.js
index bbd4b7c9b..ce6351367 100644
--- a/src/editor/simple/editor.js
+++ b/src/editor/simple/editor.js
@@ -671,39 +671,50 @@ function draw_oper(p,dp) {
return node("span",{},[check(ident(p.name)),text(" "),text(p.rhs)]);
}
+function check_oper(s,ok,err) {
+ var p=parse_oper(s);
+ function check2(msg) {
+ if(msg) err(msg);
+ else ok(p.ok)
+ }
+ if(p.ok) {
+ // Checking oper syntax by checking an expression with a local
+ // definition. Some valid opers will be rejected!!
+ var e=p.ok.name+" where { "+p.ok.name+" "+p.ok.rhs+" }";
+ check_exp(e,check2);
+ }
+ else
+ err(p.error);
+}
+
function add_oper(g,ci,el) {
- function add(s) {
- var p=parse_oper(s);
- if(p.ok) {
- g.concretes[ci].opers.push(p.ok);
+ function check(s,cont) {
+ function ok(oper) {
+ g.concretes[ci].opers.push(oper);
timestamp(g.concretes[ci]);
reload_grammar(g);
- return null;
+ cont(null);
}
- else
- return p.error
+ check_oper(s,ok,cont)
}
- string_editor(el,"",add);
+ string_editor(el,"",check,true);
}
function edit_oper(ci,i) {
return function (g,el) {
- function replace(s) {
- var p=parse_oper(s);
- if(p.ok) {
- g.concretes[ci].opers[i]=p.ok;
+ function check(s,cont) {
+ function ok(oper) {
+ g.concretes[ci].opers[i]=oper;
timestamp(g.concretes[ci]);
reload_grammar(g);
- return null;
+ cont(null);
}
- else
- return p.error;
+ check_oper(s,ok,cont)
}
- string_editor(el,show_oper(g.concretes[ci].opers[i]),replace);
+ string_editor(el,show_oper(g.concretes[ci].opers[i]),check,true);
}
}
-
function delete_oper(g,ci,ix) {
with(g.concretes[ci]) opers=delete_ix(opers,ix);
timestamp(g.concretes[ci]);
diff --git a/src/editor/simple/upload.cgi b/src/editor/simple/upload.cgi
index 3da386dd6..662a1d35d 100644
--- a/src/editor/simple/upload.cgi
+++ b/src/editor/simple/upload.cgi
@@ -219,6 +219,13 @@ case "$REQUEST_METHOD" in
*) error400
esac
;;
+ cc=*)
+ # Just to check an expression for syntax errors
+ exp=$(qparse "$QUERY_STRING" cc)
+ ContentType="text/plain; charset=$charset"
+ cgiheaders
+ echo "cc $exp" | GF_RESTRICTED=True gf -run
+ ;;
*) error400
esac
esac