>Green Card directives

5. Green Card directives

Green Card pays attention only to Green Card directives, each of which starts with a ``%'' at the beginning of a line. All other lines are passed through to the output Haskell file unchanged.

The syntax of Green Card directives is as follows (the syntax for dis is given in Section 9.1):

Program  :  Declaration_1
            Declaration_n     n >= 1

Declaration : Procedure
            | '%const' [Var] [Var1 .. Varn]
            | '%enum'  [Var] Derivings
                      Type  [Var1 .. Varn]
            | '%dis' [Var1] [Var1 .. Varn] '=' dis
            | '%#include' Filename
            | '%prefix' Var
            | '%C' ccode

Procedure   : [Signature] [call] [ccode] [result]

Signature   : '%fun' Var :: Type

Type        : Var
            | Var Type
            | Type '->' Type
            | '(' Type_1, ... , Type_n ')'    n >= 1

Call        : '%call' Dis_1 ... Dis_n

Result      : '%fail' Cexp Cexp [Result]
            | '%end' Cexp
            | '%result' Dis

Cexp        : anything up until '}' is encountered.
            | Ccode

Ccode       : '%code' Var
            | '%safecode' Var

Filename    : '<' Var '>'
            | '"' Var '"'

Green Card understands the following directives:

A directive can span more than one line, but the continuation lines must each start with a % followed by some whitespace. For example:

%fun draw :: Int                -- Length in pixels
%           -> Maybe Int        -- Width in pixels
%           -> IO ()

Haskell-style comments are permitted in Green Card directives (except, for obvious reasons, ``%C''.)

A general principle we have followed is to define a single, explicit (and hence long-winded) general mechanism, that should deal with just about anything, and then define convenient abbreviations that save the programmer from writing out the general mechanism in many common cases. We have erred on the conservative side in defining such abbreviations; that is, we have only defined an abbreviation where doing without it seemed unreasonably long-winded, and where there seemed to be a systematic way of defining an abbreviation.