Chapter 3. Invoking Happy

An invocation of Happy has the following syntax:

happy [ options ] filename [ options ]

All the command line options are optional (!) and may occur either before or after the input file name.

There are two types of grammar files, file.y and file.ly, with the latter observing the reverse comment (or literate) convention (i.e. each code line must begin with the character >, lines which don't begin with > are treated as comments). The examples distributed with Happy are all of the .ly form.

The flags accepted by Happy are as follows:

-a | --arrays

Instructs Happy to generate a parser using an array-based shift reduce parser. When used in conjunction with -g, the arrays will be encoded as strings, resulting in faster parsers. Without -g, standard Haskell arrays will be used.

-g | --ghc

Instructs Happy to generate a parser that uses GHC-specific extensions to obtain faster code.

-c | --coerce

Use GHC's unsafeCoerce# extension to generate smaller faster parsers. Type-safety isn't compromised.

This option may only be used in conjuction with -g.

-d | --debug

Generate a parser that will print debugging information to stderr at run-time, including all the shifts, reductions, state transitions and token inputs performed by the parser.

This option can only be used in conjunction with -a.

-i[<filename>] | --info[=<filename>]

Directs Happy to produce an info file containing detailed information about the grammar, parser states, parser actions, and conflicts. Info files are vital during the debugging of grammars. The filename argument is optional (note that there's no space between -i and the filename in the short version), and if omitted the info file will be written to <file>.info (where <file>; is the input file name with any extension removed).

-o <filename> | --outfile=<filename>

Specifies the destination of the generated parser module. If omitted, the parser will be placed in <file>.hs, where <file> is the name of the input file with any extension removed.

-m <name> | --magic-name=<name>

Happy prefixes all the symbols it uses internally with either happy or Happy. To use a different string, for example if the use of happy is conflicting with one of your own functions, specify the prefix using the -m option.

-v | --version

Print version information on standard output then exit successfully.

-t <directory> | --template <directory>

Instructs Happy to use this directory when looking for template files: these files contain the static code that Happy includes in every generated parser. You shouldn't need to use this option if Happy is properly configured for your computer.