-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Parsing and pretty printing of Rust code -- -- Language Rust is a library for the analysis of Rust code. It includes -- a complete, well tested parser and pretty printer. @package language-rust @version 0.2.0.27 -- | Data structure behind identifiers. module Language.Rust.Data.Ident -- | An identifier data Ident Ident :: Name -> Bool -> {-# UNPACK #-} !Int -> Ident -- | payload of the identifier [name] :: Ident -> Name -- | whether the identifier is raw [raw] :: Ident -> Bool -- | hash for quick comparision [hash] :: Ident -> {-# UNPACK #-} !Int -- | Smart constructor for making an Ident. mkIdent :: String -> Ident -- | The payload of an identifier type Name = String instance Control.DeepSeq.NFData Language.Rust.Data.Ident.Ident instance GHC.Generics.Generic Language.Rust.Data.Ident.Ident instance Data.Data.Data Language.Rust.Data.Ident.Ident instance GHC.Show.Show Language.Rust.Data.Ident.Ident instance Data.String.IsString Language.Rust.Data.Ident.Ident instance GHC.Classes.Eq Language.Rust.Data.Ident.Ident instance GHC.Classes.Ord Language.Rust.Data.Ident.Ident instance GHC.Base.Monoid Language.Rust.Data.Ident.Ident instance Data.Semigroup.Semigroup Language.Rust.Data.Ident.Ident -- | These are the only functions that need to be implemented in order to -- use the parser. Whether this wraps ByteString or String -- depends on whether the useByteStrings option is on or not (it -- is by default). Using ByteString means better handling of weird -- characters (takeByte for plain String fails badly if you -- try to take a byte that doesn't fall on a character boundary), but it -- means incurring a dependency on the utf8-string package. module Language.Rust.Data.InputStream -- | Opaque input type. data InputStream -- | Returns the number of text lines in the given InputStream -- --
-- >>> countLines "" -- 0 ---- --
-- >>> countLines "foo" -- 1 ---- --
-- >>> countLines "foo\n\nbar" -- 3 ---- --
-- >>> countLines "foo\n\nbar\n" -- 3 --countLines :: InputStream -> Int -- | Return True if the given input stream is empty. -- --
-- >>> inputStreamEmpty "" -- True ---- --
-- >>> inputStreamEmpty "foo" -- False --inputStreamEmpty :: InputStream -> Bool -- | Read an encoded file into an InputStream readInputStream :: FilePath -> IO InputStream -- | Read an InputStream from a Handle hReadInputStream :: Handle -> IO InputStream -- | Convert a String to an InputStream. inputStreamFromString :: String -> InputStream -- | Convert InputStream to String. inputStreamToString :: InputStream -> String -- | Read the first byte from an InputStream and return that byte -- with what remains of the InputStream. Behaviour is undefined -- when inputStreamEmpty returns True. -- --
-- >>> takeByte "foo bar" -- (102, "oo bar") ---- --
-- >>> takeByte "Ĥăƨĸëļļ" -- (196, "\ETX\168\&8\235<<") --takeByte :: InputStream -> (Word8, InputStream) -- | Read the first character from an InputStream and return that -- Char with what remains of the InputStream. Behaviour is -- undefined when inputStreamEmpty returns True. -- --
-- >>> takeChar "foo bar"
-- ('f', "oo bar")
--
--
--
-- >>> takeChar "Ĥăƨĸëļļ"
-- ('Ĥ', "ăƨĸëļļ")
--
takeChar :: InputStream -> (Char, InputStream)
-- | Returns the first n characters of the given input stream,
-- without removing them.
--
-- -- >>> peekChars 5 "foo bar" -- "foo ba" ---- --
-- >>> peekChars 5 "foo" -- "foo" ---- --
-- >>> peekChars 3 "Ĥăƨĸëļļ" -- "Ĥăƨ" --peekChars :: Int -> InputStream -> String instance GHC.Classes.Ord Language.Rust.Data.InputStream.InputStream instance GHC.Classes.Eq Language.Rust.Data.InputStream.InputStream instance Data.String.IsString Language.Rust.Data.InputStream.InputStream instance GHC.Show.Show Language.Rust.Data.InputStream.InputStream -- | Everything to do with describing a position or a contiguous region in -- a file. module Language.Rust.Data.Position -- | A position in a source file. The row and column information is kept -- only for its convenience and human-readability. Analogous to the -- information encoded in a cursor. data Position Position :: {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> Position -- | absolute offset the source file. [absoluteOffset] :: Position -> {-# UNPACK #-} !Int -- | row (line) in the source file. [row] :: Position -> {-# UNPACK #-} !Int -- | column in the source file. [col] :: Position -> {-# UNPACK #-} !Int NoPosition :: Position -- | Pretty print a Position prettyPosition :: Position -> String -- | Maximum of two positions, bias for actual positions. -- --
-- >>> maxPos (Position 30 5 8) (Position 37 5 15) -- Position 37 5 15 ---- --
-- >>> maxPos NoPosition (Position 30 5 8) -- Position 30 5 8 --maxPos :: Position -> Position -> Position -- | Maximum and minimum positions, bias for actual positions. -- --
-- >>> minPos (Position 30 5 8) (Position 37 5 15) -- Position 30 5 8 ---- --
-- >>> minPos NoPosition (Position 30 5 8) -- Position 30 5 8 --minPos :: Position -> Position -> Position -- | Starting position in a file. initPos :: Position -- | Advance column a certain number of times. incPos :: Position -> Int -> Position -- | Advance to the next line. retPos :: Position -> Position -- | Advance only the absolute offset, not the row and column information. -- Only use this if you know what you are doing! incOffset :: Position -> Int -> Position -- | Spans represent a contiguous region of code, delimited by two -- Positions. The endpoints are inclusive. Analogous to the -- information encoded in a selection. data Span Span :: !Position -> Span [lo, hi] :: Span -> !Position -- | Extract the wrapped value from Spanned unspan :: Spanned a -> a -- | Pretty print a Span prettySpan :: Span -> String -- | Check if a span is a subset of another span subsetOf :: Span -> Span -> Bool -- | Convenience function lifting <> to work on all -- Located things (#) :: (Located a, Located b) => a -> b -> Span -- | A "tagging" of something with a Span that describes its extent. data Spanned a Spanned :: a -> {-# UNPACK #-} !Span -> Spanned a -- | Describes nodes that can be located - their span can be extracted from -- them. In general, we expect that for a value constructed as Con x -- y z where Con is an arbitrary constructor -- --
-- (spanOf x <> spanOf y <> spanOf z) `subsetOf` spanOf (Con x y z) == True --class Located a spanOf :: Located a => a -> Span instance Control.DeepSeq.NFData a => Control.DeepSeq.NFData (Language.Rust.Data.Position.Spanned a) instance GHC.Generics.Generic (Language.Rust.Data.Position.Spanned a) instance Data.Data.Data a => Data.Data.Data (Language.Rust.Data.Position.Spanned a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Language.Rust.Data.Position.Spanned a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Language.Rust.Data.Position.Spanned a) instance Control.DeepSeq.NFData Language.Rust.Data.Position.Span instance GHC.Generics.Generic Language.Rust.Data.Position.Span instance Data.Data.Data Language.Rust.Data.Position.Span instance GHC.Classes.Ord Language.Rust.Data.Position.Span instance GHC.Classes.Eq Language.Rust.Data.Position.Span instance Control.DeepSeq.NFData Language.Rust.Data.Position.Position instance GHC.Generics.Generic Language.Rust.Data.Position.Position instance Data.Data.Data Language.Rust.Data.Position.Position instance GHC.Classes.Ord Language.Rust.Data.Position.Position instance GHC.Classes.Eq Language.Rust.Data.Position.Position instance Language.Rust.Data.Position.Located Language.Rust.Data.Position.Span instance Language.Rust.Data.Position.Located (Language.Rust.Data.Position.Spanned a) instance Language.Rust.Data.Position.Located a => Language.Rust.Data.Position.Located (GHC.Base.Maybe a) instance Language.Rust.Data.Position.Located a => Language.Rust.Data.Position.Located [a] instance Language.Rust.Data.Position.Located a => Language.Rust.Data.Position.Located (Data.List.NonEmpty.NonEmpty a) instance GHC.Base.Functor Language.Rust.Data.Position.Spanned instance GHC.Base.Applicative Language.Rust.Data.Position.Spanned instance GHC.Base.Monad Language.Rust.Data.Position.Spanned instance GHC.Show.Show a => GHC.Show.Show (Language.Rust.Data.Position.Spanned a) instance GHC.Show.Show Language.Rust.Data.Position.Span instance Data.Semigroup.Semigroup Language.Rust.Data.Position.Span instance GHC.Base.Monoid Language.Rust.Data.Position.Span instance GHC.Show.Show Language.Rust.Data.Position.Position -- | This module defines Haskell data types corresponding to the abstract -- syntax tree(s) of the Rust language, based on the definitions -- rustc uses (defined in libsyntax) whenever possible. -- Unfortunately, since the internals of rustc are not exposed, -- there are no official docs. -- https://manishearth.github.io/rust-internals-docs/syntax/ast/index.html -- are the unofficial docs. module Language.Rust.Syntax -- | This is the fundamental unit of parsing - it represents the contents -- of one source file. It is composed of an optional shebang line, inner -- attributes that follow, and then the module items. -- -- Example: -- --
-- #!/usr/bin/env rust
--
-- #![allow(dead_code)]
--
-- fn main() {
-- println!("Hello world")
-- }
--
data SourceFile a
SourceFile :: (Maybe Name) -> [Attribute a] -> [Item a] -> SourceFile a
-- | Encodes whether something can be updated or changed
-- (syntax::ast::Mutability).
data Mutability
Mutable :: Mutability
Immutable :: Mutability
-- | Qualifies whether something is using unsafe Rust or not
-- (syntax::ast::Unsafety). Note that we also use this to
-- describe whether a Block is unsafe or not, while Rust has a
-- seperate structure (syntax::ast::BlockCheckMode) for that.
-- This is because they also need to keep track of whether an unsafe
-- block is compiler generated.
data Unsafety
Unsafe :: Unsafety
Normal :: Unsafety
-- | An argument in a function header (syntax::ast::Arg, except
-- with SelfKind and ExplicitSelf inlined).
--
-- Example: x: usize, self, mut self,
-- &self, &'lt mut self, mut self: Foo
-- as in
--
--
-- trait Foo {
-- // Regular argument
-- fn new(x: usize) -> Foo;
--
-- // Self argument, by value
-- fn foo(self) -> i32;
-- fn bar(mut self);
--
-- // Self argument, by reference
-- fn baz(&self) -> Bar<'lt>;
-- fn qux(&'lt mut self) -> Bar<'lt>;
--
-- // Explicit self argument
-- fn quux(mut self: Foo);
-- }
--
data Arg a
-- | Regular argument
Arg :: (Maybe (Pat a)) -> (Ty a) -> a -> Arg a
-- | Self argument, by value
SelfValue :: Mutability -> a -> Arg a
-- | Self argument, by reference
SelfRegion :: (Maybe (Lifetime a)) -> Mutability -> a -> Arg a
-- | Explicit self argument
SelfExplicit :: (Ty a) -> Mutability -> a -> Arg a
-- | Header (not the body) of a function declaration
-- (syntax::ast::FnDecl). The Bool argument indicates
-- whether the header is variadic (so whether the argument list ends in
-- ...).
--
-- Example: (bar: i32) -> i32 as in
--
--
-- fn foo(bar: i32) -> i32 {
-- bar + 2
-- }
--
data FnDecl a
FnDecl :: [Arg a] -> (Maybe (Ty a)) -> Bool -> a -> FnDecl a
-- | Everything in Rust is namespaced using nested modules. A Path
-- represents a path into nested modules, possibly instantiating type
-- parameters along the way (syntax::ast::Path). Much like file
-- paths, these paths can be relative or absolute (global) with respect
-- to the crate root.
--
-- Paths are used to identify expressions (see PathExpr), types
-- (see PathTy), and modules (indirectly through ViewPath
-- and such).
--
-- The Bool argument identifies whether the path is relative or
-- absolute.
--
-- Example: std::cmp::PartialEq
data Path a
Path :: Bool -> [PathSegment a] -> a -> Path a
-- | Parameters on a path segment (syntax::ast::PathParameters).
data PathParameters a
-- | Parameters in a chevron comma-delimited list
-- (syntax::ast::AngleBracketedParameterData). Note that
-- lifetimes must come before types, which must come before bindings.
-- Bindings are equality constraints on associated types (example:
-- Foo<A=Bar>)
--
-- Example: <'a,A,B,C=i32> in a path segment like
-- foo::<'a,A,B,C=i32>
AngleBracketed :: [Lifetime a] -> [Ty a] -> [(Ident, Ty a)] -> a -> PathParameters a
-- | Parameters in a parenthesized comma-delimited list, with an optional
-- output type (syntax::ast::ParenthesizedParameterData).
--
-- Example: (A,B) -> C in a path segment Foo(A,B) ->
-- C
Parenthesized :: [Ty a] -> (Maybe (Ty a)) -> a -> PathParameters a
-- | Segment of a path (syntax::ast::PathSegment).
data PathSegment a
PathSegment :: Ident -> (Maybe (PathParameters a)) -> a -> PathSegment a
-- | The explicit Self type in a "qualified path". The actual
-- path, including the trait and the associated item, is stored
-- separately. The first argument is the type given to Self and
-- the second is the index of the associated qualified with this
-- Self type
data QSelf a
QSelf :: (Ty a) -> Int -> QSelf a
-- | Attributes are annotations for other AST nodes
-- (syntax::ast::Attribute). Note that doc-comments are promoted
-- to attributes.
--
-- Example: #[derive(Copy,Clone)] as in
--
--
-- #[derive(Clone, Copy)]
-- struct Complex { re: f32, im: f32 }
--
data Attribute a
-- | Regular attributes of the form #[...]
Attribute :: AttrStyle -> (Path a) -> TokenStream -> a -> Attribute a
-- | Doc comment attributes. The Bool argument identifies if the
-- comment is inline or not, and the Name contains the actual doc
-- comment content.
SugaredDoc :: AttrStyle -> Bool -> Name -> a -> Attribute a
-- | Distinguishes between attributes that are associated with the node
-- that follows them and attributes that are associated with the node
-- that contains them (syntax::ast::AttrStyle). These two cases
-- need to be distinguished only for pretty printing - they are otherwise
-- fundamentally equivalent.
--
-- Example: #[repr(C)] is an outer attribute while
-- #![feature(slice_patterns)] is an inner one
data AttrStyle
Outer :: AttrStyle
Inner :: AttrStyle
-- | Literals in Rust (syntax::ast::Lit). As discussed in
-- Suffix, Rust AST is designed to parse suffixes for all
-- literals, even if they are currently only valid on Int and
-- Float literals.
data Lit a
-- | string (example: "foo")
Str :: String -> StrStyle -> Suffix -> a -> Lit a
-- | byte string (example: b"foo")
ByteStr :: [Word8] -> StrStyle -> Suffix -> a -> Lit a
-- | character (example: 'a')
Char :: Char -> Suffix -> a -> Lit a
-- | byte (example: b'f')
Byte :: Word8 -> Suffix -> a -> Lit a
-- | integer (example: 1i32)
Int :: IntRep -> Integer -> Suffix -> a -> Lit a
-- | float (example: 1.12e4)
Float :: Double -> Suffix -> a -> Lit a
-- | boolean (example: true)
Bool :: Bool -> Suffix -> a -> Lit a
-- | Smart constructor for ByteStr.
byteStr :: String -> StrStyle -> Suffix -> a -> Lit a
-- | The suffix on a literal (unifies syntax::ast::LitIntType,
-- syntax::ast::IntTy, syntax::ast::UintTy, and
-- syntax::ast::FloatTy). As of today, only numeric types can
-- have suffixes, but the possibility of adding more (possibly arbitrary)
-- suffixes to literals in general is being kept open intentionally.
-- RFC about future-proofing literal suffixes
--
-- Examples: i32, isize, and f32
data Suffix
Unsuffixed :: Suffix
Is :: Suffix
I8 :: Suffix
I16 :: Suffix
I32 :: Suffix
I64 :: Suffix
I128 :: Suffix
Us :: Suffix
U8 :: Suffix
U16 :: Suffix
U32 :: Suffix
U64 :: Suffix
U128 :: Suffix
F32 :: Suffix
F64 :: Suffix
-- | Extract the suffix from a Lit.
suffix :: Lit a -> Suffix
-- | The base of the number in an Int literal can be binary (e.g.
-- 0b1100), octal (e.g. 0o14), decimal (e.g.
-- 12), or hexadecimal (e.g. 0xc).
data IntRep
Bin :: IntRep
Oct :: IntRep
Dec :: IntRep
Hex :: IntRep
-- | Style of a string literal (syntax::ast::StrStyle).
data StrStyle
-- | regular strings (example: "foo")
Cooked :: StrStyle
-- | raw strings, with the number of # delimiters (example:
-- r##)
Raw :: Int -> StrStyle
-- | Expression (syntax::ast::Expr). Note that Rust pushes into
-- expressions an unusual number of constructs including if,
-- while, match, etc.
data Expr a
-- | box expression (example: box x)
Box :: [Attribute a] -> (Expr a) -> a -> Expr a
-- | in-place expression - first Expr is the place, second one is
-- the value (example: x <- y)
InPlace :: [Attribute a] -> (Expr a) -> (Expr a) -> a -> Expr a
-- | array literal (example: [a, b, c, d])
Vec :: [Attribute a] -> [Expr a] -> a -> Expr a
-- | function call where the first Expr is the function itself, and
-- the [Expr] is the list of arguments (example:
-- foo(1,2,x))
Call :: [Attribute a] -> (Expr a) -> [Expr a] -> a -> Expr a
-- | method call where the first Expr is the receiver, Ident
-- is the method name, Maybe [Ty] the list of type
-- arguments and '[Expr]' the arguments to the method. (example:
-- x.foo::<Bar, Baz>(a, b, c, d)
MethodCall :: [Attribute a] -> (Expr a) -> Ident -> (Maybe [Ty a]) -> [Expr a] -> a -> Expr a
-- | tuple (example: (a, b, c ,d))
TupExpr :: [Attribute a] -> [Expr a] -> a -> Expr a
-- | binary operation (example: a + b, a * b)
Binary :: [Attribute a] -> BinOp -> (Expr a) -> (Expr a) -> a -> Expr a
-- | unary operation (example: !x, *x)
Unary :: [Attribute a] -> UnOp -> (Expr a) -> a -> Expr a
-- | literal (example: 1, "foo")
Lit :: [Attribute a] -> (Lit a) -> a -> Expr a
-- | cast (example: foo as f64)
Cast :: [Attribute a] -> (Expr a) -> (Ty a) -> a -> Expr a
-- | type annotation (example: x: i32)
TypeAscription :: [Attribute a] -> (Expr a) -> (Ty a) -> a -> Expr a
-- | if expression, with an optional else block. In the case the
-- else block is missing, the type of the if is
-- inferred to be (). (example: if 1 == 2 { (1,1) } else {
-- (2,2) }
If :: [Attribute a] -> (Expr a) -> (Block a) -> (Maybe (Expr a)) -> a -> Expr a
-- | if-let expression with an optional else block (example: if let
-- Some(x) = None { () })
IfLet :: [Attribute a] -> (NonEmpty (Pat a)) -> (Expr a) -> (Block a) -> (Maybe (Expr a)) -> a -> Expr a
-- | while loop, with an optional label (example: 'lbl: while 1 == 1 {
-- break 'lbl })
While :: [Attribute a] -> (Expr a) -> (Block a) -> (Maybe (Label a)) -> a -> Expr a
-- | while-let loop, with an optional label (example: while let Some(x)
-- = None { x })
WhileLet :: [Attribute a] -> (NonEmpty (Pat a)) -> (Expr a) -> (Block a) -> (Maybe (Label a)) -> a -> Expr a
-- | for loop, with an optional label (example: for i in 1..10 {
-- println!("{}",i) })
ForLoop :: [Attribute a] -> (Pat a) -> (Expr a) -> (Block a) -> (Maybe (Label a)) -> a -> Expr a
-- | conditionless loop (can be exited with Break, Continue,
-- or Ret)
Loop :: [Attribute a] -> (Block a) -> (Maybe (Label a)) -> a -> Expr a
-- | match block
Match :: [Attribute a] -> (Expr a) -> [Arm a] -> a -> Expr a
-- | closure (example: move |a, b, c| { a + b + c })
Closure :: [Attribute a] -> Movability -> CaptureBy -> (FnDecl a) -> (Expr a) -> a -> Expr a
-- | (possibly unsafe) block (example: unsafe { 1 })
BlockExpr :: [Attribute a] -> (Block a) -> a -> Expr a
-- | a catch block (example: do catch { 1 })
Catch :: [Attribute a] -> (Block a) -> a -> Expr a
-- | assignment (example: a = foo())
Assign :: [Attribute a] -> (Expr a) -> (Expr a) -> a -> Expr a
-- | assignment with an operator (example: a += 1)
AssignOp :: [Attribute a] -> BinOp -> (Expr a) -> (Expr a) -> a -> Expr a
-- | access of a named struct field (example: obj.foo)
FieldAccess :: [Attribute a] -> (Expr a) -> Ident -> a -> Expr a
-- | access of an unnamed field of a struct or tuple-struct (example:
-- foo.0)
TupField :: [Attribute a] -> (Expr a) -> Int -> a -> Expr a
-- | indexing operation (example: foo[2])
Index :: [Attribute a] -> (Expr a) -> (Expr a) -> a -> Expr a
-- | range (examples: 1..2, 1.., ..2,
-- 1...2, 1..., ...2)
Range :: [Attribute a] -> (Maybe (Expr a)) -> (Maybe (Expr a)) -> RangeLimits -> a -> Expr a
-- | variable reference
PathExpr :: [Attribute a] -> (Maybe (QSelf a)) -> (Path a) -> a -> Expr a
-- | referencing operation (example: &a or &mut a)
AddrOf :: [Attribute a] -> Mutability -> (Expr a) -> a -> Expr a
-- | break with an optional label and expression denoting what to
-- break out of and what to return (example: break 'lbl 1)
Break :: [Attribute a] -> (Maybe (Label a)) -> (Maybe (Expr a)) -> a -> Expr a
-- | continue with an optional label (example: continue)
Continue :: [Attribute a] -> (Maybe (Label a)) -> a -> Expr a
-- | return with an optional value to be returned (example:
-- return 1)
Ret :: [Attribute a] -> (Maybe (Expr a)) -> a -> Expr a
-- | macro invocation before expansion
MacExpr :: [Attribute a] -> (Mac a) -> a -> Expr a
-- | struct literal expression (examples: Foo { x: 1, y: 2 } or
-- Foo { x: 1, ..base })
Struct :: [Attribute a] -> (Path a) -> [Field a] -> (Maybe (Expr a)) -> a -> Expr a
-- | array literal constructed from one repeated element (example: [1;
-- 5])
Repeat :: [Attribute a] -> (Expr a) -> (Expr a) -> a -> Expr a
-- | no-op: used solely so we can pretty print faithfully
ParenExpr :: [Attribute a] -> (Expr a) -> a -> Expr a
-- | sugar for error handling with Result (example:
-- parsed_result?)
Try :: [Attribute a] -> (Expr a) -> a -> Expr a
-- | yield with an optional value to yield (example: yield
-- 1)
Yield :: [Attribute a] -> (Maybe (Expr a)) -> a -> Expr a
-- | ABIs support by Rust's foreign function interface
-- (syntax::abi::Abi). Note that of these, only Rust,
-- C, System, RustIntrinsic, RustCall, and
-- PlatformIntrinsic and Unadjusted are cross-platform -
-- all the rest are platform-specific.
--
-- Example: "C" as in extern "C" fn foo(x: i32);
data Abi
Cdecl :: Abi
Stdcall :: Abi
Fastcall :: Abi
Vectorcall :: Abi
Aapcs :: Abi
Win64 :: Abi
SysV64 :: Abi
PtxKernel :: Abi
Msp430Interrupt :: Abi
X86Interrupt :: Abi
Rust :: Abi
C :: Abi
System :: Abi
RustIntrinsic :: Abi
RustCall :: Abi
PlatformIntrinsic :: Abi
Unadjusted :: Abi
-- | An arm of a Match expression (syntax::ast::Arm). An
-- arm has at least one patten, possibly a guard expression, and a body
-- expression.
--
-- Example: n if n % 4 == 3 => { println!("{} % 4 = 3", n) }
-- as in
--
--
-- match n {
-- n if n % 4 == 3 => { println!("{} % 4 = 3", n) }
-- n if n % 4 == 1 => { println!("{} % 4 = 1", n) }
-- _ => println!("{} % 2 = 0", n)
-- }
--
data Arm a
Arm :: [Attribute a] -> (NonEmpty (Pat a)) -> (Maybe (Expr a)) -> (Expr a) -> a -> Arm a
-- | Unary operators, used in the Unary constructor of Expr
-- (syntax::ast::UnOp).
--
-- Example: ! as in !true
data UnOp
-- | * operator (dereferencing)
Deref :: UnOp
-- | ! operator (logical inversion)
Not :: UnOp
-- | - operator (negation)
Neg :: UnOp
-- | Binary operators, used in the Binary and AssignOp
-- constructors of Expr (syntax::ast::BinOp).
--
-- Example: + as in 1 + 1 or 1 += 1
data BinOp
-- | + operator (addition)
AddOp :: BinOp
-- | - operator (subtraction)
SubOp :: BinOp
-- | * operator (multiplication)
MulOp :: BinOp
-- | / operator (division)
DivOp :: BinOp
-- | % operator (modulus)
RemOp :: BinOp
-- | && operator (logical and)
AndOp :: BinOp
-- | || operator (logical or)
OrOp :: BinOp
-- | ^ operator (bitwise xor)
BitXorOp :: BinOp
-- | & operator (bitwise and)
BitAndOp :: BinOp
-- | | operator (bitwise or)
BitOrOp :: BinOp
-- | << operator (shift left)
ShlOp :: BinOp
-- | >> operator (shift right)
ShrOp :: BinOp
-- | == operator (equality)
EqOp :: BinOp
-- | < operator (less than)
LtOp :: BinOp
-- | <= operator (less than or equal to)
LeOp :: BinOp
-- | != operator (not equal to)
NeOp :: BinOp
-- | >= operator (greater than or equal to)
GeOp :: BinOp
-- | > operator (greater than)
GtOp :: BinOp
-- | Used to annotate loops, breaks, continues, etc.
data Label a
Label :: Name -> a -> Label a
-- | Describes how a Closure should close over its free variables
-- (syntax::ast::CaptureBy).
data CaptureBy
-- | make copies of free variables closed over (move closures)
Value :: CaptureBy
-- | borrow free variables closed over
Ref :: CaptureBy
-- | The movability of a generator / closure literal
-- (syntax::ast::Movability).
data Movability
Immovable :: Movability
Movable :: Movability
-- | Field in a struct literal expression (syntax::ast::Field).
--
-- Example: x: 1 in Point { x: 1, y: 2 }
data Field a
Field :: Ident -> (Maybe (Expr a)) -> a -> Field a
-- | Limit types of a Range
data RangeLimits
-- | Inclusive at the beginning, exclusive at the end
HalfOpen :: RangeLimits
-- | Inclusive at the beginning and end
Closed :: RangeLimits
-- | Types (syntax::ast::Ty).
data Ty a
-- | variable length slice (example: [T])
Slice :: (Ty a) -> a -> Ty a
-- | fixed length array (example: [T; n])
Array :: (Ty a) -> (Expr a) -> a -> Ty a
-- | raw pointer (example: *const T or *mut T)
Ptr :: Mutability -> (Ty a) -> a -> Ty a
-- | reference (example: &'a T or &'a mut T)
Rptr :: (Maybe (Lifetime a)) -> Mutability -> (Ty a) -> a -> Ty a
-- | bare function (example: fn(usize) -> bool)
BareFn :: Unsafety -> Abi -> [LifetimeDef a] -> (FnDecl a) -> a -> Ty a
-- | never type: !
Never :: a -> Ty a
-- | tuple (example: (i32, i32))
TupTy :: [Ty a] -> a -> Ty a
-- | path type (examples: std::math::pi, <Vec<T> as
-- SomeTrait>::SomeType).
PathTy :: (Maybe (QSelf a)) -> (Path a) -> a -> Ty a
-- | trait object type (example: Bound1 + Bound2 + Bound3)
TraitObject :: (NonEmpty (TyParamBound a)) -> a -> Ty a
-- | impl trait type (see the RFC) (example: impl Bound1 +
-- Bound2 + Bound3).
ImplTrait :: (NonEmpty (TyParamBound a)) -> a -> Ty a
-- | no-op; kept solely so that we can pretty print faithfully
ParenTy :: (Ty a) -> a -> Ty a
-- | typeof, currently unsupported in rustc (example:
-- typeof(1))
Typeof :: (Expr a) -> a -> Ty a
-- | inferred type: _
Infer :: a -> Ty a
-- | generated from a call to a macro (example: HList![i32,(),u8])
MacTy :: (Mac a) -> a -> Ty a
-- | Represents lifetimes and type parameters attached to a declaration of
-- a functions, enums, traits, etc. (syntax::ast::Generics).
-- Note that lifetime definitions are always required to be before the
-- type parameters.
--
-- This one AST node is also a bit weird: it is the only node whose
-- source representation is not compact - the lifetimes and type
-- parameters occur by themselves between < and >
-- then a bit further the where clause occurs after a where.
--
-- Example: <'a, 'b: 'c, T: 'a> and where
-- Option<T>: Copy as in
--
-- fn nonsense<'a, 'b: 'c, T: 'a>(x: i32) -> i32 where
-- Option<T>: Copy { 1 }.
data Generics a
Generics :: [LifetimeDef a] -> [TyParam a] -> (WhereClause a) -> a -> Generics a
-- | A lifetime is a name for a scope in a program
-- (syntax::ast::Lifetime). One of the novel features of Rust is
-- that code can be parametrized over lifetimes. Syntactically, they are
-- like regular identifiers, but start with a tick ' mark. The
-- Name argument is not supposed to include that tick.
--
-- Examples: 'a or 'static
data Lifetime a
Lifetime :: Name -> a -> Lifetime a
-- | A lifetime definition, introducing a lifetime and the other lifetimes
-- that bound it (syntax::ast::LifetimeDef).
--
-- Example: 'a: 'b + 'c + 'd
data LifetimeDef a
LifetimeDef :: [Attribute a] -> (Lifetime a) -> [Lifetime a] -> a -> LifetimeDef a
-- | Type parameter definition used in Generics
-- (syntax::ast::TyParam). Note that each parameter can have any
-- number of (lifetime or trait) bounds, as well as possibly a default
-- type.
data TyParam a
TyParam :: [Attribute a] -> Ident -> [TyParamBound a] -> (Maybe (Ty a)) -> a -> TyParam a
-- | Bounds that can be placed on types
-- (syntax::ast::TyParamBound). These can be either traits or
-- lifetimes.
data TyParamBound a
-- | trait bound
TraitTyParamBound :: (PolyTraitRef a) -> TraitBoundModifier -> a -> TyParamBound a
-- | lifetime bound
RegionTyParamBound :: (Lifetime a) -> a -> TyParamBound a
-- | Partition a list of TyParamBound into a tuple of the
-- TraitTyParamBound and RegionTyParamBound variants.
partitionTyParamBounds :: [TyParamBound a] -> ([TyParamBound a], [TyParamBound a])
-- | A where clause in a definition, where one can apply a series
-- of constraints to the types introduced and used by a Generic
-- clause (syntax::ast::WhereClause). In many cases,
-- where is the only way to express certain bounds (since
-- those bounds may not be immediately on a type defined in the generic,
-- but on a type derived from types defined in the generic).
--
-- Note that while WhereClause is a field of Generic, not
-- all uses of generics are coupled with a where clause. In those cases,
-- we leave the list of predicates empty.
--
-- Example: where Option<T>: Debug as in
--
--
-- impl<T> PrintInOption for T where Option<T>: Debug { }
--
data WhereClause a
WhereClause :: [WherePredicate a] -> a -> WhereClause a
-- | Extract the where clause from a Generics.
whereClause :: Generics a -> WhereClause a
-- | An individual predicate in a WhereClause
-- (syntax::ast::WherePredicate).
data WherePredicate a
-- | type bound (syntax::ast::WhereBoundPredicate) (example:
-- for<'c> Foo: Send+Clone+'c)
BoundPredicate :: [LifetimeDef a] -> (Ty a) -> [TyParamBound a] -> a -> WherePredicate a
-- | lifetime predicate (syntax::ast::WhereRegionPredicate)
-- (example: 'a: 'b+'c)
RegionPredicate :: (Lifetime a) -> [Lifetime a] -> a -> WherePredicate a
-- | equality predicate (syntax::ast::WhereEqPredicate) (example:
-- T=int). Note that this is not currently supported.
EqPredicate :: (Ty a) -> (Ty a) -> a -> WherePredicate a
-- | Trait ref parametrized over lifetimes introduced by a for
-- (syntax::ast::PolyTraitRef).
--
-- Example: for<'a,'b> Foo<&'a Bar>
data PolyTraitRef a
PolyTraitRef :: [LifetimeDef a] -> (TraitRef a) -> a -> PolyTraitRef a
-- | A TraitRef is a path which identifies a trait
-- (syntax::ast::TraitRef).
newtype TraitRef a
TraitRef :: (Path a) -> TraitRef a
-- | Modifier on a bound, currently this is only used for ?Sized,
-- where the modifier is Maybe. Negative bounds should also be
-- handled here.
data TraitBoundModifier
None :: TraitBoundModifier
Maybe :: TraitBoundModifier
-- | Patterns (syntax::ast::Pat).
data Pat a
-- | wildcard pattern: _
WildP :: a -> Pat a
-- | identifier pattern - either a new bound variable or a unit (tuple)
-- struct pattern, or a const pattern. Disambiguation cannot be done with
-- parser alone, so it happens during name resolution. (example: mut
-- x)
IdentP :: BindingMode -> Ident -> (Maybe (Pat a)) -> a -> Pat a
-- | struct pattern. The Bool signals the presence of a ...
-- (example: Variant { x, y, .. })
StructP :: (Path a) -> [FieldPat a] -> Bool -> a -> Pat a
-- | tuple struct pattern. If the .. pattern is present, the
-- 'Maybe Int' denotes its position. (example: Variant(x, y, ..,
-- z))
TupleStructP :: (Path a) -> [Pat a] -> (Maybe Int) -> a -> Pat a
-- | path pattern (example A::B::C)
PathP :: (Maybe (QSelf a)) -> (Path a) -> a -> Pat a
-- | tuple pattern. If the .. pattern is present, the 'Maybe Int'
-- denotes its position. (example: (a, b))
TupleP :: [Pat a] -> (Maybe Int) -> a -> Pat a
-- | box pattern (example: box _)
BoxP :: (Pat a) -> a -> Pat a
-- | reference pattern (example: &mut (a, b))
RefP :: (Pat a) -> Mutability -> a -> Pat a
-- | literal (example: 1)
LitP :: (Expr a) -> a -> Pat a
-- | range pattern (example: 1...2)
RangeP :: (Expr a) -> (Expr a) -> a -> Pat a
-- | slice pattern where, as per this RFC, the pattern is split into
-- the patterns before/after the .. and the pattern at the
-- ... (example: [a, b, ..i, y, z])
SliceP :: [Pat a] -> (Maybe (Pat a)) -> [Pat a] -> a -> Pat a
-- | generated from a call to a macro (example:
-- LinkedList!(1,2,3))
MacP :: (Mac a) -> a -> Pat a
-- | Describes how a value bound to an identifier in a pattern is going to
-- be borrowed (syntax::ast::BindingMode).
--
-- Example: &mut in |&mut x: i32| -> { x += 1
-- }
data BindingMode
ByRef :: Mutability -> BindingMode
ByValue :: Mutability -> BindingMode
-- | Field in a struct literal pattern (syntax::ast::FieldPat).
-- The field name Ident is optional but, when it is
-- Nothing, the pattern the field is destructured to must be
-- IdentP.
--
-- Example: x in Point { x, y }
data FieldPat a
FieldPat :: (Maybe Ident) -> (Pat a) -> a -> FieldPat a
-- | A statement (syntax::ast::Stmt). Rust has relatively few
-- types of statements by turning both expressions (sometimes with a
-- required semicolon at the end) and items into statements.
data Stmt a
-- | A local let binding (syntax::ast::Local) (example:
-- let x: i32 = 1;)
Local :: (Pat a) -> (Maybe (Ty a)) -> (Maybe (Expr a)) -> [Attribute a] -> a -> Stmt a
-- | Item definition (example: fn foo(x: i32) { return x + 1 })
ItemStmt :: (Item a) -> a -> Stmt a
-- | Expression without a trailing semicolon (example: x + 1)
NoSemi :: (Expr a) -> a -> Stmt a
-- | Expression with a trailing semicolon (example: x + 1;)
Semi :: (Expr a) -> a -> Stmt a
-- | A macro call (example: println!("hello world"))
MacStmt :: (Mac a) -> MacStmtStyle -> [Attribute a] -> a -> Stmt a
-- | A top-level item, possibly in a Mod or a ItemStmt
-- (syntax::ast::Item with syntax::ast::ItemKind
-- inlined).
--
-- Example: fn main() { return; }
data Item a
-- | extern crate item, with optional original crate name. Examples:
-- extern crate foo or extern crate foo_bar as foo
ExternCrate :: [Attribute a] -> (Visibility a) -> Ident -> (Maybe Ident) -> a -> Item a
-- | use declaration (use or pub use) item. Examples:
-- use foo;, use foo::bar;, or use foo::bar as
-- FooBar;
Use :: [Attribute a] -> (Visibility a) -> (UseTree a) -> a -> Item a
-- | static item (static or pub static). Examples:
-- static FOO: i32 = 42; or static FOO: &'static str =
-- "bar";
Static :: [Attribute a] -> (Visibility a) -> Ident -> (Ty a) -> Mutability -> (Expr a) -> a -> Item a
-- | constant item (const or pub const). Example:
-- const FOO: i32 = 42;
ConstItem :: [Attribute a] -> (Visibility a) -> Ident -> (Ty a) -> (Expr a) -> a -> Item a
-- | function declaration (fn or pub fn). Example: fn
-- foo(bar: usize) -> usize { .. }
Fn :: [Attribute a] -> (Visibility a) -> Ident -> (FnDecl a) -> Unsafety -> Constness -> Abi -> (Generics a) -> (Block a) -> a -> Item a
-- | module declaration (mod or pub mod)
-- (syntax::ast::Mod). Example: mod foo; or mod foo
-- { .. }
Mod :: [Attribute a] -> (Visibility a) -> Ident -> (Maybe [Item a]) -> a -> Item a
-- | external module (extern or pub extern)
-- (syntax::ast::ForeignMod). Example: extern { .. } or
-- extern "C" { .. }
ForeignMod :: [Attribute a] -> (Visibility a) -> Abi -> [ForeignItem a] -> a -> Item a
-- | type alias (type or pub type). Example: type Foo
-- = Bar<u8>;
TyAlias :: [Attribute a] -> (Visibility a) -> Ident -> (Ty a) -> (Generics a) -> a -> Item a
-- | enum definition (enum or pub enum)
-- (syntax::ast::EnumDef). Example: enum Foo<A, B> {
-- C(A), D(B) }
Enum :: [Attribute a] -> (Visibility a) -> Ident -> [Variant a] -> (Generics a) -> a -> Item a
-- | struct definition (struct or pub struct). Example:
-- struct Foo<A> { x: A }
StructItem :: [Attribute a] -> (Visibility a) -> Ident -> (VariantData a) -> (Generics a) -> a -> Item a
-- | union definition (union or pub union). Example:
-- union Foo<A, B> { x: A, y: B }
Union :: [Attribute a] -> (Visibility a) -> Ident -> (VariantData a) -> (Generics a) -> a -> Item a
-- | trait declaration (trait or pub trait). Example:
-- trait Foo { .. } or trait Foo<T> { .. }
Trait :: [Attribute a] -> (Visibility a) -> Ident -> Bool -> Unsafety -> (Generics a) -> [TyParamBound a] -> [TraitItem a] -> a -> Item a
-- | trait alias Example: trait Foo = Bar + Quux;
TraitAlias :: [Attribute a] -> (Visibility a) -> Ident -> (Generics a) -> (NonEmpty (TyParamBound a)) -> a -> Item a
-- | implementation Example: impl<A> Foo<A> { .. } or
-- impl<A> Trait for Foo<A> { .. }
Impl :: [Attribute a] -> (Visibility a) -> Defaultness -> Unsafety -> ImplPolarity -> (Generics a) -> (Maybe (TraitRef a)) -> (Ty a) -> [ImplItem a] -> a -> Item a
-- | generated from a call to a macro Example: foo!{ .. }
MacItem :: [Attribute a] -> (Maybe Ident) -> (Mac a) -> a -> Item a
-- | definition of a macro via macro_rules Example:
-- macro_rules! foo { .. }
MacroDef :: [Attribute a] -> Ident -> TokenStream -> a -> Item a
-- | An item within an extern block (syntax::ast::ForeignItem with
-- syntax::ast::ForeignItemKind inlined).
--
-- Example: static ext: u8 in extern "C" { static ext: u8
-- }
data ForeignItem a
-- | Foreign function
--
-- Example: fn foo(x: i32); in extern "C" { fn foo(x: i32);
-- }
ForeignFn :: [Attribute a] -> (Visibility a) -> Ident -> (FnDecl a) -> (Generics a) -> a -> ForeignItem a
-- | Foreign static variable, optionally mutable
--
-- Example: static mut bar: i32; in extern "C" { static mut
-- bar: i32; }
ForeignStatic :: [Attribute a] -> (Visibility a) -> Ident -> (Ty a) -> Mutability -> a -> ForeignItem a
-- | Foreign type
--
-- Example: type Boo;
ForeignTy :: [Attribute a] -> (Visibility a) -> Ident -> a -> ForeignItem a
-- | An item within an impl (syntax::ast::ImplItem with
-- syntax::ast::ImplItemKind inlined).
--
-- Examples:
--
--
-- impl MyTrait {
-- // Associated constant
-- const ID: i32 = 1;
--
-- // Method
-- fn area(&self) -> f64 { 1f64 }
--
-- // Associated type
-- type N = i32;
--
-- // Call to a macro
-- foo!{}
-- }
--
data ImplItem a
-- | Associated constant
ConstI :: [Attribute a] -> (Visibility a) -> Defaultness -> Ident -> (Ty a) -> (Expr a) -> a -> ImplItem a
-- | Method
MethodI :: [Attribute a] -> (Visibility a) -> Defaultness -> Ident -> (Generics a) -> (MethodSig a) -> (Block a) -> a -> ImplItem a
-- | Associated type
TypeI :: [Attribute a] -> (Visibility a) -> Defaultness -> Ident -> (Ty a) -> a -> ImplItem a
-- | Macro call
MacroI :: [Attribute a] -> Defaultness -> (Mac a) -> a -> ImplItem a
-- | Item declaration within a trait declaration
-- (syntax::ast::TraitItem with
-- syntax::ast::TraitItemKind inlined), possibly including a
-- default implementation. A trait item is either required (meaning it
-- doesn't have an implementation, just a signature) or provided (meaning
-- it has a default implementation).
--
-- Examples:
--
--
-- trait MyTrait {
-- // Associated constant
-- const ID: i32 = 1;
--
-- // Method
-- fn area(&self) -> f64;
--
-- // Associated type
-- type N: fmt::Display;
--
-- // Call to a macro
-- foo!{}
-- }
--
data TraitItem a
-- | Associated constants
ConstT :: [Attribute a] -> Ident -> (Ty a) -> (Maybe (Expr a)) -> a -> TraitItem a
-- | Method with optional body
MethodT :: [Attribute a] -> Ident -> (Generics a) -> (MethodSig a) -> (Maybe (Block a)) -> a -> TraitItem a
-- | Possibly abstract associated types
TypeT :: [Attribute a] -> Ident -> [TyParamBound a] -> (Maybe (Ty a)) -> a -> TraitItem a
-- | Call to a macro
MacroT :: [Attribute a] -> (Mac a) -> a -> TraitItem a
-- | An ImplItem can be marked default
-- (syntax::ast::Defaultness).
data Defaultness
Default :: Defaultness
Final :: Defaultness
-- | For traits with a default impl, one can "opt out" of that impl with a
-- negative impl, by adding ! mark before the trait name. RFC
-- on builtin traits
--
-- Example: ! as in impl !Trait for Foo { }
data ImplPolarity
Positive :: ImplPolarity
Negative :: ImplPolarity
-- | Field of a struct (syntax::ast::StructField) used in
-- declarations
--
-- Example: bar: usize as in struct Foo { bar: usize }
data StructField a
StructField :: (Maybe Ident) -> (Visibility a) -> (Ty a) -> [Attribute a] -> a -> StructField a
-- | A variant in Rust is a constructor (either in a StructItem,
-- Union, or Enum) which groups together fields
-- (syntax::ast::Variant). In the case of a unit variant, there
-- can also be an explicit discriminant expression.
data Variant a
Variant :: Ident -> [Attribute a] -> (VariantData a) -> (Maybe (Expr a)) -> a -> Variant a
-- | Main payload in a Variant (syntax::ast::VariantData).
--
-- Examples:
--
--
-- enum Foo {
-- // Struct variant
-- Bar { x: f64 },
--
-- // Tuple variant
-- Baz(i32, i32),
--
-- // Unit variant
-- Qux,
-- }
--
data VariantData a
-- | Struct variant
StructD :: [StructField a] -> a -> VariantData a
-- | Tuple variant
TupleD :: [StructField a] -> a -> VariantData a
-- | Unit variant
UnitD :: a -> VariantData a
-- | Paths used in Use items (ast::syntax::UseTree).
--
-- Examples:
--
--
-- // Simple use paths
-- use foo::bar::baz as quux;
-- use foo::bar::baz;
--
-- // Glob use paths
-- use foo::bar::*;
--
-- // Nested use paths
-- use foo::bar::{a, b, c::quux as d}
--
data UseTree a
-- | Simple path, optionally ending in an as
UseTreeSimple :: (Path a) -> (Maybe Ident) -> a -> UseTree a
-- | Path ending in a glob pattern
UseTreeGlob :: (Path a) -> a -> UseTree a
-- | Path ending in a list of more paths
UseTreeNested :: (Path a) -> [UseTree a] -> a -> UseTree a
-- | The visibility modifier dictates from where one can access something
-- (ast::syntax::Visibility). RFC about adding restricted
-- visibility
data Visibility a
-- | pub is accessible from everywhere
PublicV :: Visibility a
-- | pub(crate) is accessible from within the crate
CrateV :: Visibility a
-- | for some path p, pub(p) is visible at that path
RestrictedV :: (Path a) -> Visibility a
-- | if no visbility is specified, this is the default
InheritedV :: Visibility a
-- | Const annotation to specify if a function or method is allowed to be
-- called in constants context with constant arguments
-- (syntax::ast::Constness). Relevant RFC
--
-- Example: const in const fn inc(x: i32) -> i32 { x + 1
-- }
data Constness
Const :: Constness
NotConst :: Constness
-- | Represents a method's signature in a trait declaration, or in an
-- implementation.
data MethodSig a
MethodSig :: Unsafety -> Constness -> Abi -> (FnDecl a) -> MethodSig a
-- | A curly brace delimited sequence of statements
-- (syntax::ast::Block). The last statement in the block can
-- always be a NoSemi expression.
--
-- Example: { let x = 1; return x + y } as in fn foo() { let
-- x = 1; return x + y }
data Block a
Block :: [Stmt a] -> Unsafety -> a -> Block a
-- | When the parser encounters a macro call, it parses what follows as a
-- Delimited token tree. Basically, token trees let you store raw
-- tokens or Sequence forms inside of balanced parens, braces,
-- or brackets. This is a very loose structure, such that all sorts of
-- different AST-fragments can be passed to syntax extensions using a
-- uniform type.
data TokenTree
-- | A single token
Token :: Span -> Token -> TokenTree
-- | A delimited sequence of tokens
-- (syntax::tokenstream::Delimited) Example: { [->+<]
-- } in brainfuck!{ [->+<] };
Delimited :: Span -> Delim -> TokenStream -> TokenTree
[span] :: TokenTree -> Span
-- | type of delimiter
[delim] :: TokenTree -> Delim
-- | delimited sequence of tokens
[tts] :: TokenTree -> TokenStream
-- | An abstract sequence of tokens, organized into a sequence (e.g.
-- stream) of TokenTree, each of which is a single Token or
-- a Delimited subsequence of tokens.
data TokenStream
-- | a single token or a single set of delimited tokens
Tree :: TokenTree -> TokenStream
-- | stream of streams of tokens
Stream :: [TokenStream] -> TokenStream
-- | A TokenStream is at its core just a stream of TokenTree.
-- This function lets you get at that directly. For example, you can use
-- 'Data.List.unfoldr unconsTokenStream' to convert between a
-- TokenStream and '[TokenTree]'.
unconsTokenStream :: TokenStream -> Maybe (TokenTree, TokenStream)
-- | For interpolation during macro expansion
-- (syntax::ast::NonTerminal).
data Nonterminal a
NtItem :: (Item a) -> Nonterminal a
NtBlock :: (Block a) -> Nonterminal a
NtStmt :: (Stmt a) -> Nonterminal a
NtPat :: (Pat a) -> Nonterminal a
NtExpr :: (Expr a) -> Nonterminal a
NtTy :: (Ty a) -> Nonterminal a
NtIdent :: Ident -> Nonterminal a
NtPath :: (Path a) -> Nonterminal a
NtTT :: TokenTree -> Nonterminal a
NtArm :: (Arm a) -> Nonterminal a
NtImplItem :: (ImplItem a) -> Nonterminal a
NtTraitItem :: (TraitItem a) -> Nonterminal a
NtGenerics :: (Generics a) -> Nonterminal a
NtWhereClause :: (WhereClause a) -> Nonterminal a
NtArg :: (Arg a) -> Nonterminal a
NtLit :: (Lit a) -> Nonterminal a
-- | Represents a macro invocation (syntax::ast::Mac). The
-- Path indicates which macro is being invoked, and the
-- TokenStream contains the source of the macro invocation.
data Mac a
Mac :: (Path a) -> TokenStream -> a -> Mac a
-- | Style of the macro statement (syntax::ast::MacStmtStyle).
data MacStmtStyle
-- | trailing semicolon (example: foo! { ... };,
-- foo!(...);, and foo![...];)
SemicolonMac :: MacStmtStyle
-- | braces (example: foo! { ... })
BracesMac :: MacStmtStyle
-- | A general token (based on syntax::parse::token::Token).
--
-- Unlike its libsyntax counterpart, Token has folded in
-- syntax::parse::token::BinOpToken and
-- syntax::parse::token::BinOpEqToken as regular tokens.
data Token
-- | = token
Equal :: Token
-- | < token
Less :: Token
-- | > token
Greater :: Token
-- | & token
Ampersand :: Token
-- | | token
Pipe :: Token
-- | ! token
Exclamation :: Token
-- | ~ token
Tilde :: Token
-- | + token
Plus :: Token
-- | - token
Minus :: Token
-- | * token
Star :: Token
-- | / token
Slash :: Token
-- | % token
Percent :: Token
-- | ^ token
Caret :: Token
-- | >= token
GreaterEqual :: Token
-- | >>= token
GreaterGreaterEqual :: Token
-- | && token
AmpersandAmpersand :: Token
-- | || token
PipePipe :: Token
-- | << token
LessLess :: Token
-- | >> token
GreaterGreater :: Token
-- | == token
EqualEqual :: Token
-- | != token
NotEqual :: Token
-- | <= token
LessEqual :: Token
-- | <<= token
LessLessEqual :: Token
-- | -= token
MinusEqual :: Token
-- | &= token
AmpersandEqual :: Token
-- | |= token
PipeEqual :: Token
-- | += token
PlusEqual :: Token
-- | *= token
StarEqual :: Token
-- | /= token
SlashEqual :: Token
-- | ^= token
CaretEqual :: Token
-- | %= token
PercentEqual :: Token
-- | @ token
At :: Token
-- | . token
Dot :: Token
-- | .. token
DotDot :: Token
-- | ..= token
DotDotEqual :: Token
-- | ... token
DotDotDot :: Token
-- | , token
Comma :: Token
-- | ; token
Semicolon :: Token
-- | : token
Colon :: Token
-- | :: token
ModSep :: Token
-- | -> token
RArrow :: Token
-- | <- token
LArrow :: Token
-- | => token
FatArrow :: Token
-- | # token
Pound :: Token
-- | $ token
Dollar :: Token
-- | ? token
Question :: Token
-- | One of (, [, {
OpenDelim :: !Delim -> Token
-- | One of ), ], }
CloseDelim :: !Delim -> Token
-- | a literal token with an optional suffix (something like i32)
LiteralTok :: LitTok -> (Maybe Name) -> Token
-- | an arbitrary identifier (something like x or foo or
-- and_then)
IdentTok :: Ident -> Token
-- | a lifetime (something like 'a or 'static)
LifetimeTok :: Ident -> Token
-- | whitespace
Space :: Space -> Name -> Token
-- | doc comment with its contents, whether it is outer/inner, and whether
-- it is inline or not
Doc :: String -> !AttrStyle -> !Bool -> Token
-- | #! shebang token
Shebang :: Token
-- | end of file token
Eof :: Token
-- | can be expanded into several tokens in macro-expansion
Interpolated :: (Nonterminal Span) -> Token
-- | Check whether a space is needed between two tokens to avoid confusion.
spaceNeeded :: Token -> Token -> Bool
-- | Rust is whitespace independent. Short of providing space between
-- tokens, whitespace is all the same to the parser.
data Space
-- | usual white space: [\ \t\n\f\v\r]+
Whitespace :: Space
-- | comment (either inline or not)
Comment :: Space
-- | A delimiter token (syntax::parse::token::DelimToken).
data Delim
-- | round parenthesis: ( or )
Paren :: Delim
-- | square bracket: [ or ]
Bracket :: Delim
-- | curly brace: { or }
Brace :: Delim
-- | empty delimiter
NoDelim :: Delim
-- | A literal token (syntax::parse::token::Lit)
data LitTok
-- | byte
ByteTok :: Name -> LitTok
-- | character
CharTok :: Name -> LitTok
-- | integral literal (could have type i32, int,
-- u128, etc.)
IntegerTok :: Name -> LitTok
-- | floating point literal (could have type f32, f64,
-- etc.)
FloatTok :: Name -> LitTok
-- | string literal
StrTok :: Name -> LitTok
-- | raw string literal and the number of # marks around it
StrRawTok :: Name -> !Int -> LitTok
-- | byte string literal
ByteStrTok :: Name -> LitTok
-- | raw byte string literal and the number of # marks around it
ByteStrRawTok :: Name -> !Int -> LitTok
-- | Distinguishes between attributes that are associated with the node
-- that follows them and attributes that are associated with the node
-- that contains them (syntax::ast::AttrStyle). These two cases
-- need to be distinguished only for pretty printing - they are otherwise
-- fundamentally equivalent.
--
-- Example: #[repr(C)] is an outer attribute while
-- #![feature(slice_patterns)] is an inner one
data AttrStyle
Outer :: AttrStyle
Inner :: AttrStyle
-- | Both the lexer and the parser run inside of the P monad. As
-- detailed in the section on on threaded-lexers in Happy's
-- instruction manual, the benefits of this are that:
--
-- >>> :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 } -- >>> :set -XOverloadedStrings -- -- >>> import Language.Rust.Syntax.AST --module Language.Rust.Pretty -- | 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 -> Either ResolveFail (Doc b) -- | 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)) --pretty' :: (Resolve a, Pretty a) => a -> Doc b -- | 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 -> Either ResolveFail (Doc a) -- | 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' --prettyAnnotated' :: (Resolve (f a), PrettyAnnotated f) => f a -> Doc a -- | Given a handle to a file, write a SourceFile in with a desired -- width of 100 characters. writeSourceFile :: (Monoid a, Typeable a) => Handle -> SourceFile a -> IO () -- | 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. writeTokens :: Handle -> [Spanned Token] -> IO () -- | Describes things that can be pretty printed. class Pretty a -- | Pretty print the given value without resolving it. prettyUnresolved :: Pretty a => a -> Doc b -- | Similar to Pretty, but for types which are parametrized over an -- annotation type. class PrettyAnnotated p -- | Pretty print the given value without resolving it, adding annotations -- in the Doc whenever possible. prettyAnnUnresolved :: PrettyAnnotated p => p a -> Doc a -- | 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 -- --
-- >>> putStrLn (show (vsep ["hello", "world"])) -- hello -- world --data Doc ann :: * -> * -- | 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: -- --
-- parse' . pretty' . resolve' == id ---- --
-- resolve' . parse' = parse' --resolve' :: Resolve a => a -> a -- | 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. resolveVerbose :: Resolve a => a -> (a, Severity, [Issue]) -- | 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. data ResolveFail ResolveFail :: [Dynamic] -> String -> ResolveFail -- | Localized information about an issue in a syntax tree. data Issue Issue :: String -> !Severity -> [Dynamic] -> Issue -- | Description of the issue [description] :: Issue -> String -- | Severity of the issue [severity] :: Issue -> !Severity -- | 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. [location] :: Issue -> [Dynamic] -- | Diagnostic for how severe an Issue is. data Severity -- | Everything is normal (this variant is returned when there was nothing -- to resolve) Clean :: Severity -- | There is something fishy looking (AST is valid, but may not be what -- you expect) Warning :: Severity -- | The AST was invalid, but in a way that could be corrected Correction :: Severity -- | The AST was invalid in some way that could not be automatically fixed Error :: Severity instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.Attribute a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.Block a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.SourceFile a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.Expr a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.Field a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.FieldPat a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.FnDecl a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.ForeignItem a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.Generics a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.ImplItem a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.Item a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.Lifetime a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.LifetimeDef a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.Lit a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.Mac a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.Nonterminal a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.Pat a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.Path a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.PolyTraitRef a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.Stmt a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.StructField a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.TraitItem a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.TraitRef a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.Ty a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.TyParam a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.TyParamBound a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.Variant a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.UseTree a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.Visibility a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.WhereClause a) instance Language.Rust.Pretty.Pretty (Language.Rust.Syntax.AST.WherePredicate a) instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.Attribute instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.Block instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.SourceFile instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.Expr instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.Field instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.FieldPat instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.FnDecl instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.ForeignItem instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.Generics instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.ImplItem instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.Item instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.Lifetime instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.LifetimeDef instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.Lit instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.Mac instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.Nonterminal instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.Pat instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.Path instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.PolyTraitRef instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.Stmt instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.StructField instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.TraitItem instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.TraitRef instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.Ty instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.TyParam instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.TyParamBound instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.Variant instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.UseTree instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.Visibility instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.WhereClause instance Language.Rust.Pretty.PrettyAnnotated Language.Rust.Syntax.AST.WherePredicate instance Language.Rust.Pretty.Pretty Language.Rust.Syntax.AST.Abi instance Language.Rust.Pretty.Pretty Language.Rust.Syntax.AST.BindingMode instance Language.Rust.Pretty.Pretty Language.Rust.Syntax.AST.BinOp instance Language.Rust.Pretty.Pretty Language.Rust.Data.Ident.Ident instance Language.Rust.Pretty.Pretty Language.Rust.Syntax.AST.ImplPolarity instance Language.Rust.Pretty.Pretty Language.Rust.Syntax.AST.Suffix instance Language.Rust.Pretty.Pretty Language.Rust.Syntax.Token.LitTok instance Language.Rust.Pretty.Pretty Language.Rust.Syntax.AST.Mutability instance Language.Rust.Pretty.Pretty Language.Rust.Syntax.AST.RangeLimits instance Language.Rust.Pretty.Pretty Language.Rust.Syntax.Token.Token instance Language.Rust.Pretty.Pretty Language.Rust.Syntax.AST.TokenTree instance Language.Rust.Pretty.Pretty Language.Rust.Syntax.AST.TokenStream instance Language.Rust.Pretty.Pretty Language.Rust.Syntax.AST.UnOp instance Language.Rust.Pretty.Pretty Language.Rust.Syntax.AST.Unsafety instance Language.Rust.Pretty.Pretty Language.Rust.Data.Position.Position instance Language.Rust.Pretty.Pretty Language.Rust.Data.Position.Span -- | Quasiquoters for converting Rust code into the equivalent Haskell -- patterns and expressions. These are just convenience wrappers over -- dataToExpQ and dataToPatQ. These quasiquoters only work -- as expressions and patterns, not as declarations or types. The pattern -- quasiquoters recursively ignore any Span or Position -- fields (replacing them with wildcard patterns). -- -- Using quasiquotes instead of manually writing out the AST means that -- even if the AST evolves (perhaps by adding extra fields to certain -- nodes), your code is likely to continue to work. -- -- The examples below assume the following GHCi flag and import: -- --
-- >>> :set -XQuasiQuotes -- -- >>> import Control.Monad ( void ) --module Language.Rust.Quote -- | Quasiquoter for literals (see Lit). -- --
-- >>> void [lit| 1.4e29f64 |] -- Float 1.4e29 F64 () --lit :: QuasiQuoter -- | Quasiquoter for attributes (see Attribute) -- --
-- >>> void [attr| #[no_mangle] |] -- Attribute Outer (Path False [PathSegment "no_mangle" Nothing ()] ()) (Stream []) () --attr :: QuasiQuoter -- | Quasiquoter for types (see Ty) -- --
-- >>> void [ty| &(_,_) |] -- Rptr Nothing Immutable (TupTy [Infer (),Infer ()] ()) () --ty :: QuasiQuoter -- | Quasiquoter for patterns (see Pat) -- --
-- >>> void [pat| x @ 1...5 |] -- IdentP (ByValue Immutable) "x" (Just (RangeP (Lit [] (Int Dec 1 Unsuffixed ()) ()) -- (Lit [] (Int Dec 5 Unsuffixed ()) ()) ())) () --pat :: QuasiQuoter -- | Quasiquoter for statements (see Stmt) -- --
-- >>> void [stmt| let x = 4i32; |] -- Local (IdentP (ByValue Immutable) "x" Nothing ()) Nothing (Just (Lit [] (Int Dec 4 I32 ()) ())) [] () --stmt :: QuasiQuoter -- | Quasiquoter for expressions (see Expr) -- --
-- >>> void [expr| (x,) |] -- TupExpr [] [PathExpr [] Nothing (Path False [PathSegment "x" Nothing ()] ()) ()] () --expr :: QuasiQuoter -- | Quasiquoter for items (see Item) -- --
-- >>> void [item| type Unit = (); |] -- TyAlias [] InheritedV "Unit" (TupTy [] ()) (Generics [] [] (WhereClause [] ()) ()) () --item :: QuasiQuoter -- | Quasiquoter for a whole source file (see SourceFile) -- --
-- >>> void [sourceFile| fn main() { } |]
-- SourceFile Nothing [] [Fn [] InheritedV "main"
-- (FnDecl [] Nothing False ())
-- Normal NotConst Rust
-- (Generics [] [] (WhereClause [] ()) ())
-- (Block [] Normal ()) ()]
--
sourceFile :: QuasiQuoter
-- | Quasiquoter for impl items (see ImplItem)
--
-- -- >>> void [implItem| type Item = (); |] -- TypeI [] InheritedV Final "Item" (TupTy [] ()) () --implItem :: QuasiQuoter -- | Quasiquoter for trait items (see TraitItem) -- --
-- >>> void [traitItem| type Item; |] -- TypeT [] "Item" [] Nothing () --traitItem :: QuasiQuoter -- | Quasiquoter for token trees (see TokenTree) -- --
-- >>> [tokenTree| fn |] -- Token (Span (Position 1 2 14) (Position 3 2 16)) fn --tokenTree :: QuasiQuoter -- | Quasiquoter for blocks (see Block) -- --
-- >>> void [block| unsafe { 1i32 } |]
-- Block [NoSemi (Lit [] (Int Dec 1 I32 ()) ()) ()] Unsafe ()
--
block :: QuasiQuoter
-- | Selecting the right parser may require adding an annotation or using
-- -XTypeApplications to avoid an "Ambiguous type variable"
-- error.
--
-- Using void (as in the examples below) exploits the fact that
-- most AST nodes are instances of Functor to discard the
-- Span annotation that is attached to most parsed AST nodes.
-- Conversely, if you wish to extract the Span annotation, the
-- Located typeclass provides a spanOf method.
--
-- The examples below assume the following GHCi flags and imports:
--
-- -- >>> :set -XTypeApplications -XOverloadedStrings -- -- >>> import Language.Rust.Syntax.AST -- -- >>> import Control.Monad ( void ) -- -- >>> import System.IO --module Language.Rust.Parser -- | Parse something from an input stream (it is assumed the initial -- position is initPos). -- --
-- >>> fmap void $ parse @(Expr Span) "x + 1" -- Right (Binary [] AddOp (PathExpr [] Nothing (Path False [PathSegment "x" Nothing ()] ()) ()) -- (Lit [] (Int Dec 1 Unsuffixed ()) ()) -- ()) ---- --
-- >>> fmap void $ parse @(Expr Span) "x + " -- Left (parse failure at 1:4 (Syntax error: unexpected `<EOF>' (expected an expression))) --parse :: Parse a => InputStream -> Either ParseFail a -- | Same as parse, but throws a ParseFail exception if it -- cannot parse. This function is intended for situations in which you -- are already stuck catching exceptions - otherwise you should prefer -- parse. -- --
-- >>> void $ parse' @(Expr Span) "x + 1" -- Binary [] AddOp (PathExpr [] Nothing (Path False [PathSegment "x" Nothing ()] ()) ()) -- (Lit [] (Int Dec 1 Unsuffixed ()) ()) -- () ---- --
-- >>> void $ parse' @(Expr Span) "x + " -- *** Exception: parse failure at 1:4 (Syntax error: unexpected `<EOF>' (expected an expression)) --parse' :: Parse a => InputStream -> a -- | Given a handle to a Rust source file, read that file and parse it into -- a SourceFile -- --
-- >>> writeFile "empty_main.rs" "fn main() { }"
--
-- >>> fmap void $ withFile "empty_main.rs" ReadMode readSourceFile
-- SourceFile Nothing [] [Fn [] InheritedV "main"
-- (FnDecl [] Nothing False ())
-- Normal NotConst Rust
-- (Generics [] [] (WhereClause [] ()) ())
-- (Block [] Normal ()) ()]
--
readSourceFile :: Handle -> IO (SourceFile Span)
-- | Given a path pointing to a Rust source file, read that file and lex it
-- (ignoring whitespace)
--
--
-- >>> writeFile "empty_main.rs" "fn main() { }"
--
-- >>> withFile "empty_main.rs" ReadMode readTokens
-- [fn,main,(,),{,}]
--
readTokens :: Handle -> IO [Spanned Token]
-- | Describes things that can be parsed
class Parse a
-- | Complete parser (fails if not all of the input is consumed)
parser :: Parse a => P a
-- | Parsing and lexing monad. A value of type P a
-- represents a parser that can be run (using execParser) to
-- possibly produce a value of type a.
data P a
-- | Execute the given parser on the supplied input stream at the given
-- start position, returning either the position of an error and the
-- error message, or the value parsed.
execParser :: P a -> InputStream -> Position -> Either ParseFail a
-- | Same as execParser, but working from a list of tokens instead
-- of an InputStream.
execParserTokens :: P a -> [Spanned Token] -> Position -> Either ParseFail a
-- | Starting position in a file.
initPos :: Position
-- | Spans represent a contiguous region of code, delimited by two
-- Positions. The endpoints are inclusive. Analogous to the
-- information encoded in a selection.
data Span
-- | Lexer for one Token. The only token this cannot produce is
-- Interpolated.
lexToken :: P (Spanned Token)
-- | Lexer for one non-whitespace Token. The only tokens this cannot
-- produce are Interpolated and Space (which includes
-- comments that aren't doc comments).
lexNonSpace :: P (Spanned Token)
-- | Apply the given lexer repeatedly until (but not including) the
-- Eof token. Meant for debugging purposes - in general this
-- defeats the point of a threaded lexer.
lexTokens :: P (Spanned Token) -> P [Spanned Token]
-- | Parse a valid LitTok into a Lit.
translateLit :: LitTok -> Suffix -> a -> Lit a
-- | Read an encoded file into an InputStream
readInputStream :: FilePath -> IO InputStream
-- | Read an InputStream from a Handle
hReadInputStream :: Handle -> IO InputStream
-- | Convert InputStream to String.
inputStreamToString :: InputStream -> String
-- | Convert a String to an InputStream.
inputStreamFromString :: String -> InputStream
-- | Signal a lexical error.
lexicalError :: P a
-- | Signal a syntax error.
parseError :: Show b => b -> P a
-- | Exceptions that occur during parsing
data ParseFail
ParseFail :: Position -> String -> ParseFail
instance Language.Rust.Parser.Parse (Language.Rust.Syntax.AST.Lit Language.Rust.Data.Position.Span)
instance Language.Rust.Parser.Parse (Language.Rust.Syntax.AST.Attribute Language.Rust.Data.Position.Span)
instance Language.Rust.Parser.Parse (Language.Rust.Syntax.AST.Ty Language.Rust.Data.Position.Span)
instance Language.Rust.Parser.Parse (Language.Rust.Syntax.AST.Pat Language.Rust.Data.Position.Span)
instance Language.Rust.Parser.Parse (Language.Rust.Syntax.AST.Expr Language.Rust.Data.Position.Span)
instance Language.Rust.Parser.Parse (Language.Rust.Syntax.AST.Stmt Language.Rust.Data.Position.Span)
instance Language.Rust.Parser.Parse (Language.Rust.Syntax.AST.Item Language.Rust.Data.Position.Span)
instance Language.Rust.Parser.Parse (Language.Rust.Syntax.AST.SourceFile Language.Rust.Data.Position.Span)
instance Language.Rust.Parser.Parse Language.Rust.Syntax.AST.TokenTree
instance Language.Rust.Parser.Parse Language.Rust.Syntax.AST.TokenStream
instance Language.Rust.Parser.Parse (Language.Rust.Syntax.AST.Block Language.Rust.Data.Position.Span)
instance Language.Rust.Parser.Parse (Language.Rust.Syntax.AST.ImplItem Language.Rust.Data.Position.Span)
instance Language.Rust.Parser.Parse (Language.Rust.Syntax.AST.TraitItem Language.Rust.Data.Position.Span)
instance Language.Rust.Parser.Parse (Language.Rust.Syntax.AST.TyParam Language.Rust.Data.Position.Span)
instance Language.Rust.Parser.Parse (Language.Rust.Syntax.AST.LifetimeDef Language.Rust.Data.Position.Span)
instance Language.Rust.Parser.Parse (Language.Rust.Syntax.AST.Generics Language.Rust.Data.Position.Span)
instance Language.Rust.Parser.Parse (Language.Rust.Syntax.AST.WhereClause Language.Rust.Data.Position.Span)