Happy is a parser generator for Haskell


Version on this page:
LTS Haskell 22.29:
Stackage Nightly 2024-07-20:
Latest on Hackage:1.21.0@rev:1

See all snapshots happy appears in

BSD-2-Clause licensed by Andy Gill and Simon Marlow
Maintained by https://github.com/haskell/happy
This version can be pinned in stack with:happy-,5811

Module documentation for

There are no documented modules for this package.

Depends on 4 packages(full list with versions):

Happy is a parser generator for Haskell. Given a grammar specification in BNF, Happy generates Haskell code to parse the grammar. Happy works in a similar way to the yacc tool for C.


Revision history for Happy


  • Fix for building with mtl-2.3.1 (GHC 9.6)


  • Fix #121: the -i flag produces an .info file even if the %expect pragma is violated
  • Fix #131: qualify uses of Prelude functions in generated code
  • Fix #161: drop fewer parse items when generating an .info file
  • Introduce the %shift directive to resolve shift/reduce conflicts explicitly, useful in conjunction with %expect 0
  • Remove the deprecated build configuration flag small_base


  • Fix for building with GHC 8.8.x
  • Move custom Setup preprocessing steps into a separate executable, like Alex


  • Fix for building with GHC 8.6.x


  • Fix polymorphic (rank-n) non-terminals
  • Fix for GHC 8.8.1


  • Fix cabal warnings
  • Bump upper bounds
  • Fix build with GHC 8.4.1-alpha


  • Fix issue #94 (some grammars don’t compile due to new type signatures introduced to allow overloading to be used)


  • Fix missing test suite files in the sdist


  • Manually generate Parser.hs using Makefile before sdist, to fix bootstrapping problems with cabal sandboxes & new-build
  • Documentation fixes
  • Fixed GLR support
  • New option -p/--pretty prints the grammar rules (only) to a file
  • Added generation of additional type signatures to enable use of typeclasses in monadic parsers.



  • Fix for GHC 7.10 (Applicative/Monad, #19, #21)


  • Fix for GHC 7.2 (#16)


  • Fixes for clang (XCode 5)


  • Repackaged to build with GHC 7.7+


  • Necessary changes to work with GHC 7.8


  • Fix build with GHC 7.6


  • Fix a packaging bug (cabal-install-0.10.2 didn’t put the Happy-generated files in the sdist)


  • Fix a bug in error handling when using %monad without %lexer

1.18.5 — 17 Jun 2010

1.18.4 — 23 April 2009

1.18.2 — 5 November 2008

1.18.1 — 14 October 2008

1.18 — 13 October 2008

  • New feature: EBNF-style paramterized macros, thanks to Iavor Diatchki.
  • Works with Cabal 1.2, 1.4 and 1.6
  • A few minor bugfixes

1.17 — 22 October 2007

  • Cabal 1.2 is required
  • Works with upcoming GHC 6.8.1
  • Fix the parE bug (poor error message for errors in the grammar)
  • Some performance improvements to Happy itself

1.16 — 8 January 2007

  • Switch to a Cabal build system: you need a recent version of Cabal (1.1.6 or later). If you have GHC 6.4.2, then you need to upgrade Cabal before building Happy. GHC 6.6 is fine.

  • New %error directive

  • New production forms: {%% .. } and {%^ .. }

  • Added Attribute Grammar support, by Robert Dockins

1.15 — 14 January 2005

  • New %expect directive
  • The list of tokens passed to happyError now includes the current token (not %lexer).
  • Added support for ambiguous grammars via Generalized LR parsing
  • Added %partial to indicate a parser that can return a result before EOF is reached.

1.14 — 14 April 2004

  • New meta-variable $> represents the rightmost token.

  • Happy’s OPTIONS pragma is merged with an existing one in the grammar file, if any.

1.13 — 19 June 2002

  • Support for newer versions of GHC (>= 5.04).

  • Addition of an experimental flag: --strict.

1.11 — 25 September 2001

  • Tokens no longer have a default precedence — if you want a token to have a precedence, you have to declare it.

  • Bugfix to templates for GHC on 64-bit platforms.


  • Bugfixes, and minor performance improvements,

  • Most of the examples work again.


  • A grammar may now contain several entry points, allowing several parsers to share parts of the grammar.

  • Some bugfixes.


  • Parser table compression, and more efficient table encoding when used with GHC. Large grammars can now be compiled in much less time/space than before using GHC.

  • Yacc-style operator precedence, thanks to patches from Hermann Oliveira Rodrigues [email protected] and Josef Svenningsson [email protected].

  • A debug option which causes the generated parser to print tracing information at each step during parsing.


  • Now written in, and generates, Haskell 98.

  • Several bug fixes.

  • A new option, -c, generates parsers that use GHC’s unsafeCoerce# primitive to speed up parsing and cut down the binary size. The -c option can only be used with the -g (GHC extensions) option.

  • Parsers generated with the -g option will compile to smaller binaries now — some sources of parser-bloat were identified and squished.

  • Happy has a new Open Source license, based on the BSD license.

  • A sample Haskell parser using Happy is included.


  • Many bug fixes to the error recovery support, found by experimenting with the Haskell grammar and layout.

  • Happy is about 5 times faster on large examples, due to some changes in the LALR(1) algorithms.

As of version 1.5, Happy is capable of parsing full Haskell. We have a Haskell parser that uses Happy, which will shortly be part of the library collection distributed with GHC.


  • Supports Haskell 1.4

  • Lots of bugs fixed

  • Performance: the parser generator is at least 20% faster, and generated parsers should be faster due to the replacement of a data type with a newtype.

  • Simple error recovery: designed to be enough to implement the Haskell layout rule.

  • Revamped monad support: the monad can now be threaded through the lexer, enabling passing of state between the parser and the lexer (handy for the Haskell layout rule), and consistent error handling.

  • The %newline feature is removed, the same effect can be achieved using the new monad support.


  • Happy should be much faster than before.

  • Generated parsers will be 5-10% smaller.

  • Happy now compiles with ghc-0.26.

  • Support for monadic parsers via %monad (see the documentation).

  • New syntax: previously

    f :: { <type> }
    f : ...
      | ...

    can now be written

    f :: { <type> }
      : ...
      | ...

    (i.e. omit the extra f. It was always ignored anyway :-)

  • Miscellaneous bug fixes.