1
0
forked from GitHub/gf-core

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.
This commit is contained in:
hallgren
2011-03-07 17:52:15 +00:00
parent cfb5f6eb7e
commit 62c85f1bb6
3 changed files with 48 additions and 17 deletions

View File

@@ -20,7 +20,8 @@
suggestions)
+ Try grammars in the Translation Quiz
+ Show lincat and lin before params and opers below
- Create a new concrete syntax by copying an existing one.
+ Create a new concrete syntax by copying an existing one.
- Easy access to compute_concrete from the editor
+ compile only the uploaded grammar even if other grammars are present
+ 'flags startcat' is needed for grammars with only one category (since the

View File

@@ -107,16 +107,15 @@ Error checks:
<h4>Concrete syntax</h4>
At the moment, concrete syntax definitions are limited to
At the moment, the concrete syntax for a language <var>L</var> is limited to
<ul>
<li>opening the Resource Grammar Library modules
<code>Syntax</code><var>L</var> and <code>Paradigms</code><var>L</var>
for the appropriate language <var>L</var>,
<code>Syntax</code><var>L</var> and <code>Paradigms</code><var>L</var>,
<li><em>linearization types</em> for the categories in the abstract syntax,
<li><em>linearizations</em> for the functions in the abstract syntax,
<li><em>parameter type definitions</em>,
<var>P</var> = <var>C<sub>1</sub></var> | ... |<var>C<sub>n</sub></var>,
<li><em>linearization types</em> for the categories in the abstract syntax,
<li><em>operation definitions</em>, <var>op</var> = <var>expr</var>,
<li>and <em>linearizations</em> for the functions in the abstract syntax.
<li>and <em>operation definitions</em>, <var>op</var> = <var>expr</var>.
</ul>
Available editing operations:
@@ -129,6 +128,15 @@ Available editing operations:
<li>Operation definitons can be added, removed and edited.
<li>Definitions can be reordered (using drag-and-drop)
</ul>
Also,
<ul>
<li>When a new concrete syntax is added to the grammar, a copy of the
currently open concrete syntax is created, since copying and modifying
is usually easier than creating something new from scratch.
(If the abstract syntax is currently open, the new conrete syntax will
start out empty.)
</ul>
Error checks:
<ul>
@@ -140,20 +148,23 @@ Error checks:
By pressing the <strong>Upload</strong> button, a grammar can be uploaded to
the GF server.
It will then be compiled with GF, and any errors not checked by the editor
will be detected and reported. If the grammar is free from errors, the user
It will then be compiled with GF, and any errors not detected by the editor
will be reported. If the grammar is free from errors, the user
can test the grammar by clicking on links to the online GF shell, the Minibar
or the Translation Quiz.
<h3>Future work</h3>
This prototype gives an idea of how a web based GF grammar editor could work.
We do not expect to create a full implementation of GF that runs in the
While this editor is implemented in JavaScript and runs entirely 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.
<p>
By developing a GF server with an appropriate API, it should
be possible to extend the editor to support a larger fragment of GF,
to do proper error checking.
to do proper error checking and make more of the existing GF shell functionality
accessible directly from the editor.
<p>
Grammars are currently stored locally in the browser, but a future version
could allow grammars to be stored "in the cloud", allowing the same grammars
@@ -161,7 +172,7 @@ to be accessed from multiple devices.
<hr>
<div class=modtime><small>
<!-- hhmts start --> Last modified: Mon Feb 28 17:44:19 CET 2011 <!-- hhmts end -->
<!-- hhmts start --> Last modified: Mon Mar 7 18:46:49 CET 2011 <!-- hhmts end -->
</small></div>
<address>
<a href="http://www.cse.chalmers.se/~hallgren/">TH</a>

View File

@@ -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); }