language-rust-0.1.0.0: Parsing and pretty printing of Rust code

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

Language.Rust.Data.Position

Contents

Description

Everything to do with describing a position or a contiguous region in a file.

Synopsis

Positions in files

data Position Source #

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.

Constructors

Position 

Fields

NoPosition 

Instances

Eq Position Source # 
Data Position Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Position -> c Position #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Position #

toConstr :: Position -> Constr #

dataTypeOf :: Position -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c Position) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Position) #

gmapT :: (forall b. Data b => b -> b) -> Position -> Position #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Position -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Position -> r #

gmapQ :: (forall d. Data d => d -> u) -> Position -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Position -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Position -> m Position #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Position -> m Position #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Position -> m Position #

Ord Position Source # 
Show Position Source #

Field names are not shown

Generic Position Source # 

Associated Types

type Rep Position :: * -> * #

Methods

from :: Position -> Rep Position x #

to :: Rep Position x -> Position #

NFData Position Source # 

Methods

rnf :: Position -> () #

Pretty Position Source # 
type Rep Position Source # 
type Rep Position = D1 (MetaData "Position" "Language.Rust.Data.Position" "language-rust-0.1.0.0-1eCZRQHreljBZIFWrl4lEQ" False) ((:+:) (C1 (MetaCons "Position" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "absoluteOffset") SourceUnpack SourceStrict DecidedUnpack) (Rec0 Int)) ((:*:) (S1 (MetaSel (Just Symbol "row") SourceUnpack SourceStrict DecidedUnpack) (Rec0 Int)) (S1 (MetaSel (Just Symbol "col") SourceUnpack SourceStrict DecidedUnpack) (Rec0 Int))))) (C1 (MetaCons "NoPosition" PrefixI False) U1))

maxPos :: Position -> Position -> Position Source #

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

minPos :: Position -> Position -> Position Source #

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

initPos :: Position Source #

Starting position in a file.

incPos :: Position -> Int -> Position Source #

Advance column a certain number of times.

retPos :: Position -> Position Source #

Advance to the next line.

incOffset :: Position -> Int -> Position Source #

Advance only the absolute offset, not the row and column information. Only use this if you know what you are doing!

Spans in files

data Span Source #

Spans represent a contiguous region of code, delimited by two Positions. The endpoints are inclusive. Analogous to the information encoded in a selection.

Constructors

Span 

Fields

Instances

Eq Span Source # 

Methods

(==) :: Span -> Span -> Bool #

(/=) :: Span -> Span -> Bool #

Data Span Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Span -> c Span #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Span #

toConstr :: Span -> Constr #

dataTypeOf :: Span -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c Span) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Span) #

gmapT :: (forall b. Data b => b -> b) -> Span -> Span #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Span -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Span -> r #

gmapQ :: (forall d. Data d => d -> u) -> Span -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Span -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Span -> m Span #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Span -> m Span #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Span -> m Span #

Ord Span Source # 

Methods

compare :: Span -> Span -> Ordering #

(<) :: Span -> Span -> Bool #

(<=) :: Span -> Span -> Bool #

(>) :: Span -> Span -> Bool #

(>=) :: Span -> Span -> Bool #

max :: Span -> Span -> Span #

min :: Span -> Span -> Span #

Show Span Source #

Field names are not shown

Methods

showsPrec :: Int -> Span -> ShowS #

show :: Span -> String #

showList :: [Span] -> ShowS #

Generic Span Source # 

Associated Types

type Rep Span :: * -> * #

Methods

from :: Span -> Rep Span x #

to :: Rep Span x -> Span #

Semigroup Span Source #

smallest covering Span

Methods

(<>) :: Span -> Span -> Span #

sconcat :: NonEmpty Span -> Span #

stimes :: Integral b => b -> Span -> Span #

Monoid Span Source # 

Methods

mempty :: Span #

mappend :: Span -> Span -> Span #

mconcat :: [Span] -> Span #

NFData Span Source # 

Methods

rnf :: Span -> () #

Located Span Source # 

Methods

spanOf :: Span -> Span Source #

Pretty Span Source # 
Parse (WhereClause Span) Source # 
Parse (TyParam Span) Source # 

Methods

parser :: P (TyParam Span) Source #

Parse (Ty Span) Source # 

Methods

parser :: P (Ty Span) Source #

Parse (TraitItem Span) Source # 
Parse (Stmt Span) Source # 

Methods

parser :: P (Stmt Span) Source #

Parse (Pat Span) Source # 

Methods

parser :: P (Pat Span) Source #

Parse (Lit Span) Source # 

Methods

parser :: P (Lit Span) Source #

Parse (SourceFile Span) Source # 
Parse (LifetimeDef Span) Source # 
Parse (Item Span) Source # 

Methods

parser :: P (Item Span) Source #

Parse (ImplItem Span) Source # 
Parse (Generics Span) Source # 
Parse (Expr Span) Source # 

Methods

parser :: P (Expr Span) Source #

Parse (Block Span) Source # 

Methods

parser :: P (Block Span) Source #

Parse (Attribute Span) Source # 
type Rep Span Source # 
type Rep Span = D1 (MetaData "Span" "Language.Rust.Data.Position" "language-rust-0.1.0.0-1eCZRQHreljBZIFWrl4lEQ" False) (C1 (MetaCons "Span" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "lo") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Position)) (S1 (MetaSel (Just Symbol "hi") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Position))))

unspan :: Spanned a -> a Source #

Extract the wrapped value from Spanned

prettySpan :: Span -> String Source #

Pretty print a Span

subsetOf :: Span -> Span -> Bool Source #

Check if a span is a subset of another span

(#) :: (Located a, Located b) => a -> b -> Span Source #

Convenience function lifting <> to work on all Located things

data Spanned a Source #

A "tagging" of something with a Span that describes its extent.

Constructors

Spanned a !Span 

Instances

Monad Spanned Source # 

Methods

(>>=) :: Spanned a -> (a -> Spanned b) -> Spanned b #

(>>) :: Spanned a -> Spanned b -> Spanned b #

return :: a -> Spanned a #

fail :: String -> Spanned a #

Functor Spanned Source # 

Methods

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

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

Applicative Spanned Source # 

Methods

pure :: a -> Spanned a #

(<*>) :: Spanned (a -> b) -> Spanned a -> Spanned b #

(*>) :: Spanned a -> Spanned b -> Spanned b #

(<*) :: Spanned a -> Spanned b -> Spanned a #

Eq a => Eq (Spanned a) Source # 

Methods

(==) :: Spanned a -> Spanned a -> Bool #

(/=) :: Spanned a -> Spanned a -> Bool #

Data a => Data (Spanned a) Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Spanned a -> c (Spanned a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Spanned a) #

toConstr :: Spanned a -> Constr #

dataTypeOf :: Spanned a -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Spanned a)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Spanned a)) #

gmapT :: (forall b. Data b => b -> b) -> Spanned a -> Spanned a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Spanned a -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Spanned a -> r #

gmapQ :: (forall d. Data d => d -> u) -> Spanned a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Spanned a -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Spanned a -> m (Spanned a) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Spanned a -> m (Spanned a) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Spanned a -> m (Spanned a) #

Ord a => Ord (Spanned a) Source # 

Methods

compare :: Spanned a -> Spanned a -> Ordering #

(<) :: Spanned a -> Spanned a -> Bool #

(<=) :: Spanned a -> Spanned a -> Bool #

(>) :: Spanned a -> Spanned a -> Bool #

(>=) :: Spanned a -> Spanned a -> Bool #

max :: Spanned a -> Spanned a -> Spanned a #

min :: Spanned a -> Spanned a -> Spanned a #

Show a => Show (Spanned a) Source # 

Methods

showsPrec :: Int -> Spanned a -> ShowS #

show :: Spanned a -> String #

showList :: [Spanned a] -> ShowS #

Generic (Spanned a) Source # 

Associated Types

type Rep (Spanned a) :: * -> * #

Methods

from :: Spanned a -> Rep (Spanned a) x #

to :: Rep (Spanned a) x -> Spanned a #

NFData a => NFData (Spanned a) Source # 

Methods

rnf :: Spanned a -> () #

Located (Spanned a) Source # 

Methods

spanOf :: Spanned a -> Span Source #

type Rep (Spanned a) Source # 
type Rep (Spanned a) = D1 (MetaData "Spanned" "Language.Rust.Data.Position" "language-rust-0.1.0.0-1eCZRQHreljBZIFWrl4lEQ" False) (C1 (MetaCons "Spanned" PrefixI False) ((:*:) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)) (S1 (MetaSel (Nothing Symbol) SourceUnpack SourceStrict DecidedUnpack) (Rec0 Span))))

class Located a where Source #

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

Minimal complete definition

spanOf

Methods

spanOf :: a -> Span Source #

Instances

Located Span Source # 

Methods

spanOf :: Span -> Span Source #

Located TokenTree Source # 
Located TokenStream Source #

Span is not stored on TokenStream - it is computed

Located a => Located [a] Source #

O(n) time complexity

Methods

spanOf :: [a] -> Span Source #

Located a => Located (Maybe a) Source # 

Methods

spanOf :: Maybe a -> Span Source #

Located a => Located (NonEmpty a) Source #

O(n) time complexity

Methods

spanOf :: NonEmpty a -> Span Source #

Located (Spanned a) Source # 

Methods

spanOf :: Spanned a -> Span Source #

Located a => Located (WherePredicate a) Source # 
Located a => Located (WhereClause a) Source # 

Methods

spanOf :: WhereClause a -> Span Source #

Located a => Located (UseTree a) Source # 

Methods

spanOf :: UseTree a -> Span Source #

Located a => Located (VariantData a) Source # 

Methods

spanOf :: VariantData a -> Span Source #

Located a => Located (Variant a) Source # 

Methods

spanOf :: Variant a -> Span Source #

Located a => Located (TyParamBound a) Source # 
Located a => Located (TyParam a) Source # 

Methods

spanOf :: TyParam a -> Span Source #

Located a => Located (Ty a) Source # 

Methods

spanOf :: Ty a -> Span Source #

Located a => Located (TraitRef a) Source # 

Methods

spanOf :: TraitRef a -> Span Source #

Located a => Located (TraitItem a) Source # 

Methods

spanOf :: TraitItem a -> Span Source #

Located a => Located (StructField a) Source # 

Methods

spanOf :: StructField a -> Span Source #

Located a => Located (Stmt a) Source # 

Methods

spanOf :: Stmt a -> Span Source #

Located a => Located (PolyTraitRef a) Source # 
Located a => Located (PathSegment a) Source # 

Methods

spanOf :: PathSegment a -> Span Source #

Located a => Located (PathParameters a) Source # 
Located a => Located (Path a) Source # 

Methods

spanOf :: Path a -> Span Source #

Located a => Located (Pat a) Source # 

Methods

spanOf :: Pat a -> Span Source #

Located a => Located (Mac a) Source # 

Methods

spanOf :: Mac a -> Span Source #

Located a => Located (Lit a) Source # 

Methods

spanOf :: Lit a -> Span Source #

Located a => Located (LifetimeDef a) Source # 

Methods

spanOf :: LifetimeDef a -> Span Source #

Located a => Located (Lifetime a) Source # 

Methods

spanOf :: Lifetime a -> Span Source #

Located a => Located (Label a) Source # 

Methods

spanOf :: Label a -> Span Source #

Located a => Located (Item a) Source # 

Methods

spanOf :: Item a -> Span Source #

Located a => Located (ImplItem a) Source # 

Methods

spanOf :: ImplItem a -> Span Source #

Located a => Located (Generics a) Source # 

Methods

spanOf :: Generics a -> Span Source #

Located a => Located (ForeignItem a) Source # 

Methods

spanOf :: ForeignItem a -> Span Source #

Located a => Located (FnDecl a) Source # 

Methods

spanOf :: FnDecl a -> Span Source #

Located a => Located (FieldPat a) Source # 

Methods

spanOf :: FieldPat a -> Span Source #

Located a => Located (Field a) Source # 

Methods

spanOf :: Field a -> Span Source #

Located a => Located (Expr a) Source # 

Methods

spanOf :: Expr a -> Span Source #

Located a => Located (Block a) Source # 

Methods

spanOf :: Block a -> Span Source #

Located a => Located (Attribute a) Source # 

Methods

spanOf :: Attribute a -> Span Source #

Located a => Located (Arm a) Source # 

Methods

spanOf :: Arm a -> Span Source #

Located a => Located (Arg a) Source # 

Methods

spanOf :: Arg a -> Span Source #