From 62c85f1bb6a56ba7236497a4e6dcd8457d9bdcd4 Mon Sep 17 00:00:00 2001 From: hallgren Date: Mon, 7 Mar 2011 17:52:15 +0000 Subject: 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. --- src/editor/simple/editor.js | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'src/editor/simple/editor.js') 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;i0) { + 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); } -- cgit v1.2.3