flp-0.1.0.0: A layout spec language for memory managers implemented in Rust.

Copyright(c) Alec Theriault 2017-2018
LicenseBSD-style
Maintaineralec.theriault@gmail.com
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Language.Rust.Pretty

Contents

Description

This module provides functions for turning ASTs into values of type Token. These values can then be rendered into concrete string types using functions from the prettyprinter package. This has some advantages over printing plain old strings:

  • Backend independent: you can use a variety of existing backends to efficiently render to all sorts of formats like Text, String, HTML, and terminal.
  • Dynamic layouts: the AST will render differently depending on the desired page width

    >>> :set -XTypeApplications -XOverloadedStrings
    >>> import Language.Rust.Parser
    >>> import Data.Text.Prettyprint.Doc.Util ( putDocW )
    >>> let src = parse' @(SourceFile Span) "fn foo(x: i32, y: i32, z: i32) -> i32 { x - y + z }"
    >>> let doc = pretty' src <> "\n"
    >>> putDocW 80 doc
    fn foo(x: i32, y: i32, z: i32) -> i32 {
        x - y + z
    }
    >>> putDocW 10 doc
    fn foo(
      x: i32,
      y: i32,
      z: i32,
    ) -> i32 {
      x - y + z
    }
    
  • Annotations: Depending on the backend you are using to render the Token, annotations can determine colours, styling, links, etc.

The examples below assume the following GHCi flag and import:

>>> :set -XOverloadedStrings
>>> import Language.Rust.Syntax.AST
Synopsis

Printing

pretty :: (Resolve a, Pretty a) => a -> Either ResolveFail (Doc b) Source #

Resolve (see the Resolve typeclass) and pretty print something.

>>> let one = Lit [] (Int Dec 1 Unsuffixed ()) ()
>>> let two = Lit [] (Int Dec 2 Unsuffixed ()) ()
>>> let three = Lit [] (Int Dec 3 Unsuffixed ()) ()
>>> let bogusVar = PathExpr [] Nothing (Path False [PathSegment "let" Nothing ()] ()) ()
>>> pretty (Binary [] MulOp (Binary [] AddOp one two ()) three ())
Right (1 + 2) * 3
>>> pretty (Binary [] AddOp one bogusVar ())
Left (invalid AST (identifier `let' is a keyword))

pretty' :: (Resolve a, Pretty a) => a -> Doc b Source #

Same as pretty, but throws a ResolveFail exception on invalid ASTs. This function is intended for situations in which you are already stuck catching exceptions - otherwise you should prefer pretty.

>>> let one = Lit [] (Int Dec 1 Unsuffixed ()) ()
>>> let two = Lit [] (Int Dec 2 Unsuffixed ()) ()
>>> let three = Lit [] (Int Dec 3 Unsuffixed ()) ()
>>> let bogusVar = PathExpr [] Nothing (Path False [PathSegment "let" Nothing ()] ()) ()
>>> pretty' (Binary [] MulOp (Binary [] AddOp one two ()) three ())
(1 + 2) * 3
>>> pretty' (Binary [] AddOp one bogusVar ())
*** Exception: invalid AST (identifier `let' is a keyword))

prettyAnnotated :: (Resolve (f a), PrettyAnnotated f) => f a -> Either ResolveFail (Doc a) Source #

Resolve (see the Resolve typeclass) and pretty print something with annotations. Read more about annotations in Data.Text.Prettyprint.Doc.

fmap Data.Text.Prettyprint.Doc.noAnnotate . prettyAnnotated = pretty

prettyAnnotated' :: (Resolve (f a), PrettyAnnotated f) => f a -> Doc a Source #

Same as prettyAnnotated, but throws a ResolveFail exception on invalid ASTs. This function is intended for situations in which you are already stuck catching exceptions - otherwise you should prefer prettyAnnotated.

Data.Text.Prettyprint.Doc.noAnnotate . prettyAnnotated' = pretty'

writeSourceFile :: (Monoid a, Typeable a) => Handle -> SourceFile a -> IO () Source #

Given a handle to a file, write a SourceFile in with a desired width of 100 characters.

writeTokens :: Handle -> [Spanned Token] -> IO () Source #

Given a handle to a file, write a SourceFile in with a desired width of 100 characters.

The Span associated with the tokens (if present) will be used as a hint for laying out and spacing the tokens.

class Pretty a where Source #

Describes things that can be pretty printed.

Methods

prettyUnresolved :: a -> Doc b Source #

Pretty print the given value without resolving it.

Instances
Pretty Ident Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty Span Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty Position Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty Token Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty LitTok Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty Unsafety Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty UnOp Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty TokenTree Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty TokenStream Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty RangeLimits Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty Mutability Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty Suffix Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty ImplPolarity Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty BindingMode Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty BinOp Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty Abi Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (WherePredicate a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (WhereClause a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (Visibility a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (UseTree a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (Variant a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (TyParamBound a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (TyParam a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (Ty a) Source # 
Instance details

Defined in Language.Rust.Pretty

Methods

prettyUnresolved :: Ty a -> Doc b Source #

Pretty (TraitRef a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (TraitItem a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (StructField a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (Stmt a) Source # 
Instance details

Defined in Language.Rust.Pretty

Methods

prettyUnresolved :: Stmt a -> Doc b Source #

Pretty (PolyTraitRef a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (Path a) Source # 
Instance details

Defined in Language.Rust.Pretty

Methods

prettyUnresolved :: Path a -> Doc b Source #

Pretty (Pat a) Source # 
Instance details

Defined in Language.Rust.Pretty

Methods

prettyUnresolved :: Pat a -> Doc b Source #

Pretty (Nonterminal a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (Mac a) Source # 
Instance details

Defined in Language.Rust.Pretty

Methods

prettyUnresolved :: Mac a -> Doc b Source #

Pretty (Lit a) Source # 
Instance details

Defined in Language.Rust.Pretty

Methods

prettyUnresolved :: Lit a -> Doc b Source #

Pretty (SourceFile a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (LifetimeDef a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (Lifetime a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (Item a) Source # 
Instance details

Defined in Language.Rust.Pretty

Methods

prettyUnresolved :: Item a -> Doc b Source #

Pretty (ImplItem a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (Generics a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (ForeignItem a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (FnDecl a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (FieldPat a) Source # 
Instance details

Defined in Language.Rust.Pretty

Pretty (Field a) Source # 
Instance details

Defined in Language.Rust.Pretty

Methods

prettyUnresolved :: Field a -> Doc b Source #

Pretty (Expr a) Source # 
Instance details

Defined in Language.Rust.Pretty

Methods

prettyUnresolved :: Expr a -> Doc b Source #

Pretty (Block a) Source # 
Instance details

Defined in Language.Rust.Pretty

Methods

prettyUnresolved :: Block a -> Doc b Source #

Pretty (Attribute a) Source # 
Instance details

Defined in Language.Rust.Pretty

class PrettyAnnotated p where Source #

Similar to Pretty, but for types which are parametrized over an annotation type.

Methods

prettyAnnUnresolved :: p a -> Doc a Source #

Pretty print the given value without resolving it, adding annotations in the Token whenever possible.

Instances
PrettyAnnotated WherePredicate Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated WhereClause Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated Visibility Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated UseTree Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated Variant Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated TyParamBound Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated TyParam Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated Ty Source # 
Instance details

Defined in Language.Rust.Pretty

Methods

prettyAnnUnresolved :: Ty a -> Doc a Source #

PrettyAnnotated TraitRef Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated TraitItem Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated StructField Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated Stmt Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated PolyTraitRef Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated Path Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated Pat Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated Nonterminal Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated Mac Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated Lit Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated SourceFile Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated LifetimeDef Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated Lifetime Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated Item Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated ImplItem Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated Generics Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated ForeignItem Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated FnDecl Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated FieldPat Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated Field Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated Expr Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated Block Source # 
Instance details

Defined in Language.Rust.Pretty

PrettyAnnotated Attribute Source #

This instance prints attributes inline

Instance details

Defined in Language.Rust.Pretty

data Doc ann #

The abstract data type Doc ann represents pretty documents that have been annotated with data of type ann.

More specifically, a value of type Doc represents a non-empty set of possible layouts of a document. The layout functions select one of these possibilities, taking into account things like the width of the output document.

The annotation is an arbitrary piece of data associated with (part of) a document. Annotations may be used by the rendering backends in order to display output differently, such as

  • color information (e.g. when rendering to the terminal)
  • mouseover text (e.g. when rendering to rich HTML)
  • whether to show something or not (to allow simple or detailed versions)

The simplest way to display a Doc is via the Show class.

>>> putStrLn (show (vsep ["hello", "world"]))
hello
world
Instances
Functor Doc

Alter the document’s annotations.

This instance makes Doc more flexible (because it can be used in Functor-polymorphic values), but fmap is much less readable compared to using reAnnotate in code that only works for Doc anyway. Consider using the latter when the type does not matter.

Instance details

Defined in Data.Text.Prettyprint.Doc.Internal

Methods

fmap :: (a -> b) -> Doc a -> Doc b #

(<$) :: a -> Doc b -> Doc a #

Show (Doc ann)

(show doc) prettyprints document doc with defaultLayoutOptions, ignoring all annotations.

Instance details

Defined in Data.Text.Prettyprint.Doc.Internal

Methods

showsPrec :: Int -> Doc ann -> ShowS #

show :: Doc ann -> String #

showList :: [Doc ann] -> ShowS #

IsString (Doc ann)
>>> pretty ("hello\nworld")
hello
world

This instance uses the Pretty Doc instance, and uses the same newline to line conversion.

Instance details

Defined in Data.Text.Prettyprint.Doc.Internal

Methods

fromString :: String -> Doc ann #

Generic (Doc ann) 
Instance details

Defined in Data.Text.Prettyprint.Doc.Internal

Associated Types

type Rep (Doc ann) :: Type -> Type #

Methods

from :: Doc ann -> Rep (Doc ann) x #

to :: Rep (Doc ann) x -> Doc ann #

Semigroup (Doc ann)
x <> y = hcat [x, y]
>>> "hello" <> "world" :: Doc ann
helloworld
Instance details

Defined in Data.Text.Prettyprint.Doc.Internal

Methods

(<>) :: Doc ann -> Doc ann -> Doc ann #

sconcat :: NonEmpty (Doc ann) -> Doc ann #

stimes :: Integral b => b -> Doc ann -> Doc ann #

Monoid (Doc ann)
mempty = emptyDoc
mconcat = hcat
>>> mappend "hello" "world" :: Doc ann
helloworld
Instance details

Defined in Data.Text.Prettyprint.Doc.Internal

Methods

mempty :: Doc ann #

mappend :: Doc ann -> Doc ann -> Doc ann #

mconcat :: [Doc ann] -> Doc ann #

type Rep (Doc ann) 
Instance details

Defined in Data.Text.Prettyprint.Doc.Internal

type Rep (Doc ann) = D1 (MetaData "Doc" "Data.Text.Prettyprint.Doc.Internal" "prettyprinter-1.2.1.1-G1ohLXOgHGIVWiPQmSHwO" False) (((C1 (MetaCons "Fail" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "Empty" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Char" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Char)))) :+: (C1 (MetaCons "Text" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Int) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Text)) :+: (C1 (MetaCons "Line" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "FlatAlt" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Doc ann)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Doc ann)))))) :+: ((C1 (MetaCons "Cat" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Doc ann)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Doc ann))) :+: (C1 (MetaCons "Nest" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Int) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Doc ann))) :+: C1 (MetaCons "Union" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Doc ann)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Doc ann))))) :+: ((C1 (MetaCons "Column" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Int -> Doc ann))) :+: C1 (MetaCons "WithPageWidth" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (PageWidth -> Doc ann)))) :+: (C1 (MetaCons "Nesting" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Int -> Doc ann))) :+: C1 (MetaCons "Annotated" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 ann) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Doc ann)))))))

Resolving

class Resolve a where Source #

Since it is possible to have well-typed Haskell expressions which represent invalid Rust ASTs, it is convenient to fix, warn, or fail ASTs before printing them. The Resolve typeclass provides such a facility.

A non-exhaustive list of the more obvious issues it covers:

  • missing parens
  • invalid identifiers
  • invalid paths (for example, generic arguments on a module path)
  • inner attributes on things that support only outer attributes (and vice-versa)

Minimal complete definition

resolveM

Methods

resolve :: a -> Either ResolveFail a Source #

Convert some value to its resolved form. Informally, resolving a value involves checking that its invariants hold and, if they don't, report an error message or adjust the value so that the invariant holds.

A value of a type satsifying Parse and Pretty is resolved if parse . pretty is an identity operation on it. We further expect that resolve be an identity operation on any output of parse.

resolve' :: a -> a Source #

Same as resolve, but throws a ResolveFail exception if it cannot resolve. Although this function should not be used, it summarizes nicely the laws around Resolve:

parse' . pretty' . resolve' == id
resolve' . parse' = parse'

resolveVerbose :: a -> (a, Severity, [Issue]) Source #

Run resolution and get back the altered syntax tree, the highest Severity of issues, and the list of issues found. This allows you to see what corrections were applied to the tree. If the output severity is Error, the syntax tree returned will still be invalid.

Instances
Resolve Ident Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

Resolve TokenTree Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

Resolve TokenStream Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (WherePredicate a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (WhereClause a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (Visibility a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (UseTree a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (VariantData a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (Variant a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (TyParamBound a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (TyParam a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (Ty a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

Methods

resolve :: Ty a -> Either ResolveFail (Ty a) Source #

resolve' :: Ty a -> Ty a Source #

resolveVerbose :: Ty a -> (Ty a, Severity, [Issue]) Source #

resolveM :: Ty a -> ResolveM (Ty a)

(Typeable a, Monoid a) => Resolve (TraitRef a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (TraitItem a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (StructField a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (Stmt a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

Methods

resolve :: Stmt a -> Either ResolveFail (Stmt a) Source #

resolve' :: Stmt a -> Stmt a Source #

resolveVerbose :: Stmt a -> (Stmt a, Severity, [Issue]) Source #

resolveM :: Stmt a -> ResolveM (Stmt a)

(Typeable a, Monoid a) => Resolve (QSelf a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (PolyTraitRef a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (PathParameters a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (Path a) Source #

There are three potential instances for resolving a path (depending on what type it is). The Resolve instance for Path will let through any path.

Instance details

Defined in Language.Rust.Pretty.Resolve

Methods

resolve :: Path a -> Either ResolveFail (Path a) Source #

resolve' :: Path a -> Path a Source #

resolveVerbose :: Path a -> (Path a, Severity, [Issue]) Source #

resolveM :: Path a -> ResolveM (Path a)

(Typeable a, Monoid a) => Resolve (Pat a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

Methods

resolve :: Pat a -> Either ResolveFail (Pat a) Source #

resolve' :: Pat a -> Pat a Source #

resolveVerbose :: Pat a -> (Pat a, Severity, [Issue]) Source #

resolveM :: Pat a -> ResolveM (Pat a)

(Typeable a, Monoid a) => Resolve (MethodSig a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (Mac a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

Methods

resolve :: Mac a -> Either ResolveFail (Mac a) Source #

resolve' :: Mac a -> Mac a Source #

resolveVerbose :: Mac a -> (Mac a, Severity, [Issue]) Source #

resolveM :: Mac a -> ResolveM (Mac a)

Resolve (Lit a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

Methods

resolve :: Lit a -> Either ResolveFail (Lit a) Source #

resolve' :: Lit a -> Lit a Source #

resolveVerbose :: Lit a -> (Lit a, Severity, [Issue]) Source #

resolveM :: Lit a -> ResolveM (Lit a)

(Typeable a, Monoid a) => Resolve (SourceFile a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (LifetimeDef a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

Typeable a => Resolve (Lifetime a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (Item a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

Methods

resolve :: Item a -> Either ResolveFail (Item a) Source #

resolve' :: Item a -> Item a Source #

resolveVerbose :: Item a -> (Item a, Severity, [Issue]) Source #

resolveM :: Item a -> ResolveM (Item a)

(Typeable a, Monoid a) => Resolve (ImplItem a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (Generics a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (ForeignItem a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (FnDecl a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (FieldPat a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (Field a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (Expr a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

Methods

resolve :: Expr a -> Either ResolveFail (Expr a) Source #

resolve' :: Expr a -> Expr a Source #

resolveVerbose :: Expr a -> (Expr a, Severity, [Issue]) Source #

resolveM :: Expr a -> ResolveM (Expr a)

(Typeable a, Monoid a) => Resolve (Block a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (Attribute a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

(Typeable a, Monoid a) => Resolve (Arm a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

Methods

resolve :: Arm a -> Either ResolveFail (Arm a) Source #

resolve' :: Arm a -> Arm a Source #

resolveVerbose :: Arm a -> (Arm a, Severity, [Issue]) Source #

resolveM :: Arm a -> ResolveM (Arm a)

(Typeable a, Monoid a) => Resolve (Arg a) Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

Methods

resolve :: Arg a -> Either ResolveFail (Arg a) Source #

resolve' :: Arg a -> Arg a Source #

resolveVerbose :: Arg a -> (Arg a, Severity, [Issue]) Source #

resolveM :: Arg a -> ResolveM (Arg a)

Error reporting

data ResolveFail Source #

Exceptions that occur during resolving. Unlike parse errors, we don't have positional information. Instead, we try to provide some context via a list of syntax trees which let you "zoom out" from the problematic node.

Constructors

ResolveFail [Dynamic] String 

data Issue Source #

Localized information about an issue in a syntax tree.

Constructors

Issue 

Fields

  • description :: String

    Description of the issue

  • severity :: !Severity

    Severity of the issue

  • location :: [Dynamic]

    The first element in this list is the syntax tree where the issue occurs. The next elements are increasingly zoomed out syntax trees centered on the first element. In lieu of positional information, this provides a next best way of debugging exactly where the problem is.

Instances
Show Issue Source # 
Instance details

Defined in Language.Rust.Pretty.Resolve

Methods

showsPrec :: Int -> Issue -> ShowS #

show :: Issue -> String #

showList :: [Issue] -> ShowS #

data Severity Source #

Diagnostic for how severe an Issue is.

Constructors

Clean

Everything is normal (this variant is returned when there was nothing to resolve)

Warning

There is something fishy looking (AST is valid, but may not be what you expect)

Correction

The AST was invalid, but in a way that could be corrected

Error

The AST was invalid in some way that could not be automatically fixed