language-rust: Parsing and pretty printing of Rust code

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.


Language Rust is a library for the analysis of Rust code. It includes a complete, well tested parser and pretty printer.

[Skip to ReadMe]


Dependenciesarray (==0.5.*), base (>=4.8 && <5.0), bytestring (>=0.10), deepseq (>=1.1), prettyprinter (>=1.0), semigroups (>=0.18), template-haskell (>=2.10), transformers (>=0.4 && <0.6), utf8-string (>=1.0) [details]
Copyright(c) 2017-2018 Alec Theriault
AuthorAlec Theriault
Home page
Bug tracker
Source repositoryhead: git clone
UploadedFri Mar 2 04:34:55 UTC 2018 by harpocrates





Use ByteString instead of String as InputStream datatype


Provide the experimental Language.Rust.Quote module


Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info


Maintainers' corner

For package maintainers and hackage trustees

Readme for language-rust-

[back to package description]

Parser and pretty printer for Rust Build Status Windows build status

language-rust aspires to efficiently and accurately parse and pretty print the Rust language. The underlying AST structures are also intended to be as similar as possible to the libsyntax AST rustc uses itself. When language-rust and rustc have diverging AST, the divergence should be detailed in the documentation.

A typical use looks like:

>>> :set -XTypeApplications +t
>>> import Language.Rust.Syntax

>>> -- Sample use of the parser
>>> import Language.Rust.Parser
>>> let inp = inputStreamFromString "fn main () { println!(\"Hello world!\"); }"
inp :: InputStream
>>> let sourceFile = parse' @(SourceFile Span) inp
sourceFile :: SourceFile Span

>>> -- Sample use of the pretty printer
>>> import Language.Rust.Pretty
>>> pretty' sourceFile
fn main() {
  println!("Hello world!");
it :: Doc b



With Cabal and GHC, run

cabal install happy --constraint 'happy >= 1.19.8'
cabal install alex
cabal configure
cabal build


With the Stack tool installed, run

stack init
stack build

The second command is responsible for pulling in all of the dependencies (including executable tools like Alex, Happy, and GHC itself) and then compiling everything. If Stack complains about the version of Happy installed, you can explicitly install a recent one with stack install happy-1.19.8.

Evolution of Rust

As Rust evolves, so will language-rust. We will make a best effort to support unstable features from nightly as they come out, but in general will only target compatibility with stable.


Please report any bugs to the github issue tracker.


Any difference between what is accepted by the rustc parser and the language-rust parser indicates

If the AST/parser of rustc changes, the rustc-tests test suite should start failing - it compares the JSON AST debug output of rustc to our parsed AST.

Pretty printer

For the pretty printer, bugs are a bit tougher to list exhaustively. Suggestions for better layout algorithms are most welcome! The fmt-rfcs repo is loosely used as the reference for "correct" pretty printing.