language-ninja-0.1.0: A library for dealing with the Ninja build language.

CopyrightCopyright 2017 Awake Security
LicenseApache-2.0
Maintaineropensource@awakesecurity.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Language.Ninja.Misc.Located

Contents

Description

Tokenize text into a list of non-whitespace chunks, each of which is annotated with its source location.

Since: 0.1.0

Synopsis

Located

data Located t Source #

This datatype represents a value annotated with a source location.

Since: 0.1.0

Instances

Functor Located Source # 

Methods

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

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

Foldable Located Source # 

Methods

fold :: Monoid m => Located m -> m #

foldMap :: Monoid m => (a -> m) -> Located a -> m #

foldr :: (a -> b -> b) -> b -> Located a -> b #

foldr' :: (a -> b -> b) -> b -> Located a -> b #

foldl :: (b -> a -> b) -> b -> Located a -> b #

foldl' :: (b -> a -> b) -> b -> Located a -> b #

foldr1 :: (a -> a -> a) -> Located a -> a #

foldl1 :: (a -> a -> a) -> Located a -> a #

toList :: Located a -> [a] #

null :: Located a -> Bool #

length :: Located a -> Int #

elem :: Eq a => a -> Located a -> Bool #

maximum :: Ord a => Located a -> a #

minimum :: Ord a => Located a -> a #

sum :: Num a => Located a -> a #

product :: Num a => Located a -> a #

Traversable Located Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Located a -> f (Located b) #

sequenceA :: Applicative f => Located (f a) -> f (Located a) #

mapM :: Monad m => (a -> m b) -> Located a -> m (Located b) #

sequence :: Monad m => Located (m a) -> m (Located a) #

(Monad m, Serial m Text, Serial m t) => Serial m (Located t) Source #

Default Serial instance via Generic.

Since: 0.1.0

Methods

series :: Series m (Located t) #

(Monad m, CoSerial m Text, CoSerial m t) => CoSerial m (Located t) Source #

Default CoSerial instance via Generic.

Since: 0.1.0

Methods

coseries :: Series m b -> Series m (Located t -> b) #

Eq t => Eq (Located t) Source # 

Methods

(==) :: Located t -> Located t -> Bool #

(/=) :: Located t -> Located t -> Bool #

Show t => Show (Located t) Source # 

Methods

showsPrec :: Int -> Located t -> ShowS #

show :: Located t -> String #

showList :: [Located t] -> ShowS #

Generic (Located t) Source # 

Associated Types

type Rep (Located t) :: * -> * #

Methods

from :: Located t -> Rep (Located t) x #

to :: Rep (Located t) x -> Located t #

Hashable t => Hashable (Located t) Source #

Default Hashable instance via Generic.

Since: 0.1.0

Methods

hashWithSalt :: Int -> Located t -> Int #

hash :: Located t -> Int #

ToJSON t => ToJSON (Located t) Source #

Converts to {position: …, value: …}.

Since: 0.1.0

FromJSON t => FromJSON (Located t) Source #

Inverse of the ToJSON instance.

Since: 0.1.0

NFData t => NFData (Located t) Source #

Default NFData instance via Generic.

Since: 0.1.0

Methods

rnf :: Located t -> () #

type Rep (Located t) Source # 
type Rep (Located t) = D1 (MetaData "Located" "Language.Ninja.Misc.Located" "language-ninja-0.1.0-CTXTL0Lugm4Llo91nN4SIr" False) (C1 (MetaCons "MkLocated" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "_locatedPos") SourceUnpack SourceStrict DecidedUnpack) (Rec0 Position)) (S1 (MetaSel (Just Symbol "_locatedVal") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 t))))

tokenize :: Maybe Path -> Text -> [Located Text] Source #

Given path :: Maybe Path and a text :: Text, do the following:

  • Remove all '\r' characters from the text.
  • Split the text into chunks that are guaranteed not to contain newlines or whitespace, and which are annotated with their location.

Since: 0.1.0

tokenizeFile :: MonadReadFile m => Path -> m [Located Text] Source #

Read the file at the given Path and then run tokenize on the resulting Text.

Since: 0.1.0

tokenizeText :: Text -> [Located Text] Source #

This function is equivalent to tokenize Nothing.

Since: 0.1.0

locatedPos :: Lens' (Located t) Position Source #

The position of this located value.

Since: 0.1.0

locatedVal :: Lens' (Located t) t Source #

The value underlying this located value.

Since: 0.1.0

Spans

data Spans Source #

A type representing a set of source spans.

Since: 0.1.0

Instances

Eq Spans Source # 

Methods

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

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

Show Spans Source # 

Methods

showsPrec :: Int -> Spans -> ShowS #

show :: Spans -> String #

showList :: [Spans] -> ShowS #

Generic Spans Source # 

Associated Types

type Rep Spans :: * -> * #

Methods

from :: Spans -> Rep Spans x #

to :: Rep Spans x -> Spans #

Semigroup Spans Source # 

Methods

(<>) :: Spans -> Spans -> Spans #

sconcat :: NonEmpty Spans -> Spans #

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

Monoid Spans Source # 

Methods

mempty :: Spans #

mappend :: Spans -> Spans -> Spans #

mconcat :: [Spans] -> Spans #

Hashable Spans Source # 

Methods

hashWithSalt :: Int -> Spans -> Int #

hash :: Spans -> Int #

ToJSON Spans Source # 
FromJSON Spans Source # 
NFData Spans Source # 

Methods

rnf :: Spans -> () #

(Monad m, Serial m (HashSet Span)) => Serial m Spans Source #

Default Serial instance via Generic.

Since: 0.1.0

Methods

series :: Series m Spans #

(Monad m, CoSerial m (HashSet Span)) => CoSerial m Spans Source #

Default CoSerial instance via Generic.

Since: 0.1.0

Methods

coseries :: Series m b -> Series m (Spans -> b) #

type Rep Spans Source # 
type Rep Spans = D1 (MetaData "Spans" "Language.Ninja.Misc.Located" "language-ninja-0.1.0-CTXTL0Lugm4Llo91nN4SIr" True) (C1 (MetaCons "MkSpans" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (HashSet Span))))

makeSpans :: [Span] -> Spans Source #

Construct a Spans from a list of Spans.

Since: 0.1.0

spansSet :: Iso' Spans (HashSet Span) Source #

A lens into the HashSet Span underlying a value of type Spans.

Since: 0.1.0

Span

data Span Source #

Represents a span of source code.

Since: 0.1.0

Instances

Eq Span Source # 

Methods

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

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

Show Span Source # 

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 #

Hashable Span Source #

Default Hashable instance via Generic.

Since: 0.1.0

Methods

hashWithSalt :: Int -> Span -> Int #

hash :: Span -> Int #

ToJSON Span Source #

Converts to {file: …, start: …, end: …}.

Since: 0.1.0

FromJSON Span Source #

Inverse of the ToJSON instance.

Since: 0.1.0

NFData Span Source #

Default NFData instance via Generic.

Since: 0.1.0

Methods

rnf :: Span -> () #

(Monad m, Serial m Text) => Serial m Span Source #

Default Serial instance via Generic.

Since: 0.1.0

Methods

series :: Series m Span #

(Monad m, CoSerial m Text) => CoSerial m Span Source #

Default CoSerial instance via Generic.

Since: 0.1.0

Methods

coseries :: Series m b -> Series m (Span -> b) #

type Rep Span Source # 

makeSpan Source #

Arguments

:: Maybe Path

The file in which this span resides, if any.

-> Offset

The start offset.

-> Offset

The end offset.

-> Span 

Construct a Span from a given start position to a given end position.

Since: 0.1.0

spanPath :: Lens' Span (Maybe Path) Source #

A lens into the (nullable) path associated with a Span.

Since: 0.1.0

spanRange :: Lens' Span (Offset, Offset) Source #

A lens giving the start and end Offsets associated with a Span.

Since: 0.1.0

spanStart :: Lens' Span Offset Source #

A lens into the Offset associated with the start of a Span.

Since: 0.1.0

spanEnd :: Lens' Span Offset Source #

A lens into the Offset associated with the end of a Span.

Since: 0.1.0

spanStartPos :: Getter Span Position Source #

A getter for the Position associated with the start of a Span.

Since: 0.1.0

spanEndPos :: Getter Span Position Source #

A getter for the Position associated with the end of a Span.

Since: 0.1.0

Position

data Position Source #

This datatype represents the position of a cursor in a text file.

Since: 0.1.0

Instances

Eq Position Source # 
Show Position Source # 
Generic Position Source # 

Associated Types

type Rep Position :: * -> * #

Methods

from :: Position -> Rep Position x #

to :: Rep Position x -> Position #

Hashable Position Source #

Default Hashable instance via Generic.

Since: 0.1.0

Methods

hashWithSalt :: Int -> Position -> Int #

hash :: Position -> Int #

ToJSON Position Source #

Converts to {file: …, line: …, col: …}.

Since: 0.1.0

FromJSON Position Source #

Inverse of the ToJSON instance.

Since: 0.1.0

NFData Position Source #

Default NFData instance via Generic.

Since: 0.1.0

Methods

rnf :: Position -> () #

(Monad m, Serial m Text) => Serial m Position Source #

Default Serial instance via Generic.

Since: 0.1.0

Methods

series :: Series m Position #

(Monad m, CoSerial m Text) => CoSerial m Position Source #

Default CoSerial instance via Generic.

Since: 0.1.0

Methods

coseries :: Series m b -> Series m (Position -> b) #

type Rep Position Source # 
type Rep Position = D1 (MetaData "Position" "Language.Ninja.Misc.Located" "language-ninja-0.1.0-CTXTL0Lugm4Llo91nN4SIr" False) (C1 (MetaCons "MkPosition" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "_positionFile") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Maybe Path))) ((:*:) (S1 (MetaSel (Just Symbol "_positionLine") SourceUnpack SourceStrict DecidedUnpack) (Rec0 Line)) (S1 (MetaSel (Just Symbol "_positionCol") SourceUnpack SourceStrict DecidedUnpack) (Rec0 Column)))))

makePosition :: Maybe Path -> Offset -> Position Source #

Construct a Position from a (nullable) path and a (line, column) pair.

Since: 0.1.0

positionFile :: Lens' Position (Maybe Path) Source #

The path of the file pointed to by this position, if any.

Since: 0.1.0

positionOffset :: Lens' Position Offset Source #

The offset in the file pointed to by this position.

Since: 0.1.0

positionLine :: Lens' Position Line Source #

The line number in the file pointed to by this position.

Since: 0.1.0

positionCol :: Lens' Position Column Source #

The column number in the line pointed to by this position.

Since: 0.1.0

comparePosition :: Position -> Position -> Maybe Ordering Source #

If two Positions are comparable (i.e.: if they are in the same file), this function will return an Ordering giving their relative positions. Otherwise, it will of course return Nothing.

Since: 0.1.0

Offset

type Offset = (Line, Column) Source #

A line/column offset into a file.

Since: 0.1.0

compareOffset :: Offset -> Offset -> Ordering Source #

Compare two Offsets in lexicographic order (i.e.: the Column is ignored unless they are on the same Line).

Since: 0.1.0

offsetLine :: Lens' Offset Line Source #

A lens into the Line associated with an Offset.

For now, this is simply defined as offsetLine = _1, but if Offset is later refactored to be an abstract data type, using this lens instead of _1 will decrease the amount of code that breaks.

Since: 0.1.0

offsetColumn :: Lens' Offset Column Source #

A lens into the Line associated with an Offset.

Read the description of offsetLine for an understanding of why this exists and why you should use it instead of _2.

Since: 0.1.0

Miscellaneous

type Line = Int Source #

A line number.

Since: 0.1.0

type Column = Int Source #

A column number.

Since: 0.1.0