semantic-source-0.2.0.0: Types and functionality for working with source code
Safe HaskellSafe-Inferred
LanguageHaskell2010

Source.Source

Description

Source models source code, represented as a thin wrapper around a ByteString with conveniences for splitting by line, slicing, etc.

This module is intended to be imported qualified to avoid name clashes with Prelude:

import qualified Source.Source as Source
Synopsis

Documentation

data Source Source #

The contents of a source file. This is represented as a UTF-8 ByteString under the hood. Construct these with fromUTF8; obviously, passing fromUTF8 non-UTF8 bytes will cause crashes.

Instances

Instances details
IsString Source Source # 
Instance details

Defined in Source.Source

Methods

fromString :: String -> Source #

Monoid Source Source # 
Instance details

Defined in Source.Source

Semigroup Source Source # 
Instance details

Defined in Source.Source

Generic Source Source # 
Instance details

Defined in Source.Source

Associated Types

type Rep Source :: Type -> Type #

Methods

from :: Source -> Rep Source x #

to :: Rep Source x -> Source #

Show Source Source # 
Instance details

Defined in Source.Source

NFData Source Source # 
Instance details

Defined in Source.Source

Methods

rnf :: Source -> () #

Eq Source Source # 
Instance details

Defined in Source.Source

Methods

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

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

FromJSON Source Source # 
Instance details

Defined in Source.Source

Methods

parseJSON :: Value -> Parser Source

parseJSONList :: Value -> Parser [Source]

type Rep Source Source # 
Instance details

Defined in Source.Source

type Rep Source = D1 ('MetaData "Source" "Source.Source" "semantic-source-0.2.0.0-inplace" 'True) (C1 ('MetaCons "Source" 'PrefixI 'True) (S1 ('MetaSel ('Just "bytes") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

Measurement

totalRange :: Source -> Range Source #

Return a Range that covers the entire text.

totalSpan :: Source -> Span Source #

Return a Span that covers the entire text.

En/decoding

fromText :: Text -> Source Source #

Return a Source from a Text.

toText :: Source -> Text Source #

Return the Text contained in the Source.

Slicing

slice :: Source -> Range -> Source Source #

Return a Source that contains a slice of the given Source.

Splitting

lines :: Source -> [Source] Source #

Split the contents of the source after newlines.

lineRanges :: Source -> [Range] Source #

Compute the Ranges of each line in a Source.

lineRangesWithin :: Source -> Range -> [Range] Source #

Compute the Ranges of each line in a Range of a Source.

newlineIndices :: ByteString -> [Int] Source #

Return all indices of newlines ('n', 'r', and 'rn') in the ByteString.