Skip to topic | Skip to bottom
Home
Transformers
Transformers.BoxedSDFr1.10 - 25 Jan 2006 - 10:31 - RenaudDurlintopic end

Start of topic | Skip to actions

BoxedSDF

Introduction

When working on transformation, like Transformers, we want to work on the abstract syntax tree. The action to transform concrete syntax to abstract syntax tree is called parsing. But after transformation we want to get the corresponding concrete syntax... it has to be unparsed. This action is called pretty-print.

Pretty-print is not so simple. It tries to print out a beautiful concrete syntax code with indentations, alignments, etc. There is a tool for this into the StrategoXT package, it is called Generic Pretty Printer (GPP).

GPP uses a pretty-print table, but the pretty-print table looks linked to the grammar. BoxedSDF is a bundle of tools to put pretty-print informations into the grammar.

How does it work?

If you have already used Projects.SDF grammars and the Generic Pretty Printer, you should know that a pretty-print table is tedious to write and not so easy to maintain.

BoxedSDF is an extended grammar of Projects.SDF where you can specify directly pretty-print information into it. It makes the pretty-print table easier to write and more modular.

If you have already written your Projects.SDF grammar and the corresponding PP table, do not worry ! There is a tool to merge Pretty-print table into the corresponding Sdf.

Usage

A common use is:

$ pack-boxedsdf -i MyGrammar.ppsdf | \ 
  asfix-yield -o MyGrammar.ppdef

$ parse-boxedsdf -i MyGrammar.ppdef | \ 
  boxed2sdf | \ 
  pp-sdf -o MyGrammar.def

$ parse-boxedsdf -i MyGrammar.ppdef | \ 
  boxed2pp-table | \ 
  pp-pp-table -o MyGrammar.pp

Note: if you have to use sdf-cons on your grammar, you should do it before the boxed2* filters.

Using old grammars

If you want to use an already written grammar, you can merge PP information into the Sdf grammar. Let's suppose having MyOldGrammar.def and MyOldGrammar.pp

$ parse-sdf -i MyOldGrammar.def | \ 
  boxedsdf-merge -p MyOldGrammar.pp | \ 
  pp-boxedsdf -o MyOldGrammar.ppdef

If you want to get modular files, you can use the unpack-sdf of the StrategoXT package.

Updating grammars

Sometimes, when updating grammar, it is possible to forget to change some pp entries. boxedsdf-update is a tool that can test it. If the pp entries were not modified, it is deleted so as to be regenerated by boxed2pp-table.

$ parse-boxedsdf -i MyUpdatedGrammar.ppdef | \ 
  boxedsdf-update -d MuOldGrammar.ppdef --verbose 1 | \ 
  pp-boxedsdf -o MyCorrectedGrammar.ppdef
Production has changed, but not the pp. Reseting it: "constructor1"
Production has changed, but not the pp. Reseting it: "constructor2"
$

Using your own grammar

pack-boxedsdf and boxedsdf-update load and parse concrete syntax files. If you want to use your own grammar, you just have to use the -s/--syntax option.

example of use:

$ pack-boxedsdf -I /path/to/your/syntax -s YourSdfSyntax -i YourGrammar | \ 
  implode-asfix | \ 
  YourSdfSyntax-to-BoxedSDF | \ 
  boxed2pp-table | \ 
  pp-pp-table -o YourGrammar.pp

Writing in BoxedSDF

To specify pp entries to a production rule, you have to use the pp() attribute. When writing severals pp entries for one rule, these entries has to be seperated by a comma. The path (optional) of a entry precedes it separated by a equal symbol.

module Example
exports
  context-free syntax
    Blah Blih? -> Bloh {pp(V vs=1[_1 _2], .2:opt=H hs=0[_1])

When a pp entry is not specified, boxed2pp-table will generate the default one (with ppgen). So, many production do not have to have pp entries.

Installation

Dependencies

You need StrategoXT 0.9.1.

Download

You can download the last tarball at: boxedsdf-0.2.tar.bz2: BoxedSDF v0.2

Older versions

boxedsdf-0.1.tar.bz2: BoxedSDF v0.1

Compilation

Untar the tarball. Then in the tarball directory, type:

$ ./configure --with-xt=<PATH> --prefix=<PATH>
$ make
$ make install

Do not forget to change "<PATH>" to your values.

Misc.

Documentation

Here is an oral presentation of the work on BoxedSDF:


to top

Transformers.BoxedSDF moved from Transformers.BoxedSdf on 22 Nov 2005 - 18:48 by NicolasPouillard? - put it back
You are here: Transformers > BoxedSDF

to top

Copyright © 1999-2010 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback