summaryrefslogtreecommitdiff
path: root/src/editor/simple/editor.js
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2011-03-07 17:52:15 +0000
committerhallgren <hallgren@chalmers.se>2011-03-07 17:52:15 +0000
commit62c85f1bb6a56ba7236497a4e6dcd8457d9bdcd4 (patch)
tree3718bc8ec1688cf86a81c5c389c0fa13f5f0bc07 /src/editor/simple/editor.js
parentcfb5f6eb7e105e048abff5d99a5637bfa961cb9b (diff)
gfse: create a new concrete syntax by copying an existing one
When adding a new concrete syntax to a grammar, the currently open concrete syntax will be copied. If the abstract syntax is currently open, the new concrete syntax will start out empty.
Diffstat (limited to 'src/editor/simple/editor.js')
-rw-r--r--src/editor/simple/editor.js29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/editor/simple/editor.js b/src/editor/simple/editor.js
index 7154a6261..362eae6c6 100644
--- a/src/editor/simple/editor.js
+++ b/src/editor/simple/editor.js
@@ -164,6 +164,10 @@ function add_concrete(g,el) {
list.push(li([a(jsurl("add_concrete2("+g.index+",'"+c+"')"),
[text(l.name)])]));
}
+ var from= g.current>0
+ ? "a copy of "+langname[g.concretes[g.current-1].langcode]
+ :"scratch";
+ file.appendChild(p(text("You are about to create a new concrete syntax by starting from "+from+".")));
file.appendChild(p(text("Pick a language for the new concrete syntax:")));
file.appendChild(node("ul",{},list));
}
@@ -175,11 +179,26 @@ function new_concrete(code) {
function add_concrete2(ix,code) {
var g=local.get(ix);
var cs=g.concretes;
- var i;
- for(var i=0;i<cs.length;i++) if(cs[i].langcode==code) break;
- if(i==cs.length) cs.push(new_concrete(code))
- save_grammar(g);
- open_concrete(g,i);
+ var ci;
+ for(var ci=0;ci<cs.length;ci++) if(cs[ci].langcode==code) break;
+ if(ci==cs.length) {
+ if(g.current>0) {
+ cs.push(cs[g.current-1]); // old and new are shared at this point
+ save_grammar(g); // serialization loses sharing
+ g=local.get(ix); // old and new are separate now
+ var oldcode=cs[g.current-1].langcode;
+ var cnc=g.concretes[ci];
+ cnc.langcode=code;
+ for(var oi in cnc.opens)
+ for(var li in rgl_modules)
+ if(cnc.opens[oi]==rgl_modules[li]+oldcode)
+ cnc.opens[oi]=rgl_modules[li]+code;
+ }
+ else
+ cs.push(new_concrete(code))
+ save_grammar(g);
+ }
+ open_concrete(g,ci);
}
function open_abstract(g) { g.current=0; reload_grammar(g); }