# GF online editor for simple multilingual grammars

## Introduction

Traditionally, GF grammars are created in a text editor and tested in the GF shell. Text editors know very little (if anything) about the syntax of GF grammars, and thus provide little guidance for novice GF users. Also, the grammar author has to download and install the GF software on his/her own computer.

In contrast, the GF online editor for simple multilingual grammars is available online, making it easier to get started. All that is needed is a reasonably modern web browser. Even Android and iOS devices can be used.

The editor also guides the grammar author by showing a skeleton grammar file and hinting how the parts should be filled in. When a new part is added to the grammar, it is immediately checked for errors.

Editing operations are accessed by clicking on editing symbols embedded in the grammar display: +=Add an item, ×=Delete an item, %=Edit an item. These are revealed when hovering over items. On touch devices, hovering is in some cases simulated by tapping, but there is also a button at the bottom of the display to "Enable editing on touch devices" that reveals all editing symbols.

In spite of its name, the core of the editor runs in the web browser, so once you have opened the web page, you can continue editing grammars even while you are offline. Grammar compilation & testing and some error checking is done by the GF server and is not available while offline.

### Current status

At the moment, the editor supports only a small subset of the GF grammar notation. Proper error checking is done for abstract syntax, but not (yet) for concrete syntax.

The grammars created with this editor always consists of one file for the abstract syntax, and one file for each concrete syntax.

#### Abstract syntax

The supported abstract syntax corresponds to context-free grammars (no dependent types). The definition of an abstract syntax is limited to

- a list of inherited abstract syntaxes,
- a list of category names, Cat1 ; ... ; Catn,
- a list of functions of the form Fun : Cat1 -> ... -> Catn,
- and a start category.

Available editing operations:

- Inherited abstract syntaxes can be added and removed.
- Categories can be added, removed and renamed. When renaming a category, occurences of it in function types will be updated accordingly.
- Functions can be added, removed and edited. Concrete syntaxes are updated to reflect changes.
- Functions can be reordered using drag-and-drop.

Error checks:

- Syntactically incorrect function definitions are refused.
- Semantic problem such as duplicated definitions or references to undefined categories, are highlighted.

#### Concrete syntax

At the moment, the concrete syntax for a language L is limited to

- inheriting the concrete syntax GiL for each Gi inherited by the abstract syntax.
- opening a selection of the Resource Grammar Library modules `Syntax` L, `Paradigms` L, `Lexicon` L, `Symbolic` L and `Extra` L,
- linearization types for the categories in the abstract syntax,
- linearizations for the functions in the abstract syntax,
- parameter type definitions, P = C1 | ... |Cn,
- and operation definitions, op = expr, op : type = expr,

Available editing operations:

- Modules can be added and removed from the list of opened Resource Grammar Library modules.
- The LHSs of the linearization types and linearizations are determined by the abstract syntax and do not need to be entered manually. The RHSs can be edited.
- Parameter types can be added, removed and edited.
- Operation definitons can be added, removed and edited.
- Definitions can be reordered (using drag-and-drop).

Also,

- 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.)
- When adding a new concrete syntax, you normally pick one of the supported languages from a list. The language code and the file name is determined automatically. But you can also pick Other from the list and change the language code afterwards to add a concrete syntax for a language that is not in the list.

Error checks:

- The RHSs in the concrete syntax are checked for syntactic correctness by the editor as they are entered. (TODO: the syntax of parameter types is not check at the moment.)
- Duplicated definitions are highlighted. Checks for other semantic errors are delayed until the grammar is compiled.

### Grammar views

The editor supports three ways to view a grammar:

- Column view: this is the traditional view where you see one complete grammar module at a time. i.e. either the abstract syntax or one of the concrete syntaxes in the grammar.
- Matrix view: this presents an overview of the grammar where columns correspond to the abstract and concrete syntax modules and rows correspond to the categories and functions in the grammar.
- Row view: this view shows one function form the abstract syntax and the corresponding linearization functions from all the concrete syntaxes.

### Compiling and testing grammars

When pressing the Compile button, the grammar will be compiled with GF, and any errors not detected by the editor will be reported. The grammar will also be compiled when pressing the Minibar and Quiz buttons before opening the grammar for testing in the Minibar or the Translation Quiz, respectively.

### Grammars in the cloud

While the editor normally stores grammars locally in the browser, it is also possible to store grammars in the cloud. Grammars can be stored in the cloud just for backup, or to make them accessible from multiple devices.

There is no automatic synchronization between local grammars and the cloud. Instead, the user should press to upload the grammars to the cloud, and press to download grammars from the cloud. In both cases, complete grammars are copied and older versions at the destination will be overwritten. When a grammar is deleted, both the local copy and the copy in the cloud is deleted.

Each device is initially assigned to its own unique cloud. Each device can thus have its own set of grammars that are not available on other devices. It is also possible to merge clouds and share a common set of grammars between multiple devices: when uploading grammars to the cloud, a link to this grammar cloud appears. Accessing this link from another device will cause the clouds of the two devices to be merged. After this, grammars uploaded from one of the devices can be downloaded on the other devices. Any number devices can join the same grammar cloud in this way.

Note that while it is possible to copy grammars between multiple devices, there is no way to merge concurrent edits from multiple devices. If the same grammar is uploaded to the cloud from multiple devices, the last upload wins. Thus the current implementation is suitable for a single user switching between different devices, but not recommended for sharing grammars between multiple users.

Also note that each grammar is assigned a unique identity when it is first created. Renaming a grammar does not change its identity. This means that name changes are propagated between devices like other changes.

#### Public grammars

> [October 2012: this is an experimental feature that might be replaced by an incompatible grammar sharing mechanism in the future.]

The grammar cloud also includes a list of public grammars. Grammars can be added to the public list by pressing the Publish button shown next to the grammars in the list of your grammars.

The Publish button creates copy of your grammar. If you continue to edit your grammar, the changes will be local only. You can press the Publish button again to update the public copy.

You can remove a grammar from the public list by pressing the × button next to the grammar in the public list. You can not remove grammars published by other users.

When you open a public grammar published by another user, a copy of the grammar is added to the list of your grammars. Any changes will be made in your own copy of the grammar. If you publish your copy of the grammar, it will appear separately in the list of public grammars. You can not overwrite grammars published by other users, even if they have the same name.

TODO: Publishing grammars that inherit form other grammars is not recommended. There is no way to indicate which of several grammars with the same name is being inherited.

TODO: There should probably be a way to identify who published a grammar and when. Maybe the publish button should be restricted to registered users...

### Example-based grammar writing

We experimented with this in 2011. It is currently not included, but it might return in a future version...

### Future work

This prototype gives an idea of how a web based GF grammar editor could work. While this editor is implemented in JavaScript and runs 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.

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 and make more of the existing GF shell functionality accessible directly from the editor.

The current grammar cloud service is very primitive. In particular, it is not suitable for multiple users developing a grammar in collaboration.

### Related documents

- GF Grammar Development Tools. Slides from a presentation at the MOLTO meeting in Göteborg, March 2011.
- The GF Grammar IDE. MOLTO deliverable.
- The GF Grammar Compiler API. MOLTO deliverable.

Last modified: Tue Oct 9 16:52:47 CEST 2012