README 2.62 KB
Newer Older
1
2
3
BoxedSdf
--------

4
This package is to make easier the writing of Pretty-Print tables for Generic
5
6
Pretty-Printer.

7
Author: Valentin David <valentin@lrde.epita.fr>
8
9
10
11

Requirements
------------

12
StrategoXT 0.9.1 or above (http://www.stratego-language.org/)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

Installation
------------

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

Working with BoxedSdf grammar
-----------------------------

A common using is:

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

$ parse-boxedsdf -i MyGrammar.ppdef | \
  boxed2sdf | \
31
  pp-sdf -o MyGrammar.def
32
33
34
35
36

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

37
38
Note: if you have to use sdf-cons on your grammar, you should do it before the
      boxed2* filters.
39
40
41
42

Using old grammars
------------------

43
If you want to use an already written grammar, you can merge PP information
44
into the Sdf grammar. Let's suppose having MyOldGrammar.def and MyOldGrammar.pp
45
46
47
48
49
50
51

$ 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.
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

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.def | \
  boxedsdf-merge -d MuOldGrammar.def --verbose 1 -o MyCorrectedGrammar.def
Production has changed, but not the pp. Reseting it: "constructor1"
Production has changed, but not the pp. Reseting it: "constructor2"
$

Note that your grammar must have constructor's names on the productions.

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-PureSdf | \
  boxed2pp-table | \
  pp-pp-table

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.