From b58fc79908efb52320a38fdf6df96d8d0d067e73 Mon Sep 17 00:00:00 2001 From: hallgren Date: Fri, 29 Jul 2011 15:44:19 +0000 Subject: gfse: some correctness checks for concrete syntax The editor now calls the GF server to check the syntax of expressions that are part of concrete syntax (except for parameter types). This is currently done by using the cc command of the GF shell, which puts some unnecessary restricitons on operation definitions... --- src/editor/simple/editor.js | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'src/editor/simple/editor.js') 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]); -- cgit v1.2.3