diff options
| author | hallgren <hallgren@chalmers.se> | 2011-07-29 15:44:19 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2011-07-29 15:44:19 +0000 |
| commit | b58fc79908efb52320a38fdf6df96d8d0d067e73 (patch) | |
| tree | 606e81246df1d5befe3f80905100bd7ef155dbfe /src/editor/simple/editor.js | |
| parent | 7c6f6110ebf8ebf446b8414e035b1118908d5bed (diff) | |
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...
Diffstat (limited to 'src/editor/simple/editor.js')
| -rw-r--r-- | src/editor/simple/editor.js | 45 |
1 files changed, 28 insertions, 17 deletions
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]); |
