language-python-0.5.4: Parsing and pretty printing of Python code.

Copyright | (c) 2009 Bernie Pope
License | BSD-style
Maintainer | bjpop@csse.unimelb.edu.au
Stability | experimental
Portability | ghc
Safe Haskell | Safe
Language | Haskell98

Language.Python.Common.SrcLocation

Contents

- Construction
- Modification
- Projection of components of a span

Description

Source location information for the Python lexer and parser. This module provides single-point locations and spans, and conversions between them.

Synopsis

- data SrcLocation
  - = Sloc {
    - sloc_filename :: !String
    - sloc_row :: !Int
    - sloc_column :: !Int
    }
  - | NoLocation
- data SrcSpan
  - = SpanCoLinear {
    - span_filename :: !String
    - span_row :: !Int
    - span_start_column :: !Int
    - span_end_column :: !Int
    }
  - | SpanMultiLine {
    - span_filename :: !String
    - span_start_row :: !Int
    - span_start_column :: !Int
    - span_end_row :: !Int
    - span_end_column :: !Int
    }
  - | SpanPoint {
    - span_filename :: !String
    - span_row :: !Int
    - span_column :: !Int
    }
  - | SpanEmpty
- class Span a where
- spanning :: (Span a, Span b) => a -> b -> SrcSpan
- mkSrcSpan :: SrcLocation -> SrcLocation -> SrcSpan
- combineSrcSpans :: SrcSpan -> SrcSpan -> SrcSpan
- initialSrcLocation :: String -> SrcLocation
- spanStartPoint :: SrcSpan -> SrcSpan
- incColumn :: Int -> SrcLocation -> SrcLocation
- decColumn :: Int -> SrcLocation -> SrcLocation
- incLine :: Int -> SrcLocation -> SrcLocation
- incTab :: SrcLocation -> SrcLocation
- endCol :: SrcSpan -> Int
- endRow :: SrcSpan -> Int
- startCol :: SrcSpan -> Int
- startRow :: SrcSpan -> Int

# Construction

data SrcLocation #

A location for a syntactic entity from the source code. The location is specified by its filename, and starting row and column.

Constructors

Sloc |
Fields sloc_filename :: !String sloc_row :: !Int sloc_column :: !Int
NoLocation |

Instances

Eq SrcLocation # |
Methods (==) :: SrcLocation -> SrcLocation -> Bool # (/=) :: SrcLocation -> SrcLocation -> Bool #
Data SrcLocation # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SrcLocation -> c SrcLocation # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c SrcLocation # toConstr :: SrcLocation -> Constr # dataTypeOf :: SrcLocation -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c SrcLocation) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SrcLocation) # gmapT :: (forall b. Data b => b -> b) -> SrcLocation -> SrcLocation # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SrcLocation -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SrcLocation -> r # gmapQ :: (forall d. Data d => d -> u) -> SrcLocation -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> SrcLocation -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> SrcLocation -> m SrcLocation # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SrcLocation -> m SrcLocation # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SrcLocation -> m SrcLocation #
Ord SrcLocation # |
Methods compare :: SrcLocation -> SrcLocation -> Ordering # (<) :: SrcLocation -> SrcLocation -> Bool # (<=) :: SrcLocation -> SrcLocation -> Bool # (>) :: SrcLocation -> SrcLocation -> Bool # (>=) :: SrcLocation -> SrcLocation -> Bool # max :: SrcLocation -> SrcLocation -> SrcLocation # min :: SrcLocation -> SrcLocation -> SrcLocation #
Show SrcLocation # |
Methods showsPrec :: Int -> SrcLocation -> ShowS # show :: SrcLocation -> String # showList :: [SrcLocation] -> ShowS #
Pretty SrcLocation # |
Methods pretty :: SrcLocation -> Doc #
Span SrcLocation # |
Methods getSpan :: SrcLocation -> SrcSpan #

data SrcSpan #

Source location spanning a contiguous section of a file.

Constructors

SpanCoLinear | A span which starts and ends on the same line.
Fields span_filename :: !String span_row :: !Int span_start_column :: !Int span_end_column :: !Int
SpanMultiLine | A span which starts and ends on different lines.
Fields span_filename :: !String span_start_row :: !Int span_start_column :: !Int span_end_row :: !Int span_end_column :: !Int
SpanPoint | A span which is actually just one point in the file.
Fields span_filename :: !String span_row :: !Int span_column :: !Int
SpanEmpty | No span information.

Instances

Eq SrcSpan # |
Methods (==) :: SrcSpan -> SrcSpan -> Bool # (/=) :: SrcSpan -> SrcSpan -> Bool #
Data SrcSpan # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SrcSpan -> c SrcSpan # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c SrcSpan # toConstr :: SrcSpan -> Constr # dataTypeOf :: SrcSpan -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c SrcSpan) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SrcSpan) # gmapT :: (forall b. Data b => b -> b) -> SrcSpan -> SrcSpan # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SrcSpan -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SrcSpan -> r # gmapQ :: (forall d. Data d => d -> u) -> SrcSpan -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> SrcSpan -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan #
Ord SrcSpan # |
Methods compare :: SrcSpan -> SrcSpan -> Ordering # (<) :: SrcSpan -> SrcSpan -> Bool # (<=) :: SrcSpan -> SrcSpan -> Bool # (>) :: SrcSpan -> SrcSpan -> Bool # (>=) :: SrcSpan -> SrcSpan -> Bool # max :: SrcSpan -> SrcSpan -> SrcSpan # min :: SrcSpan -> SrcSpan -> SrcSpan #
Show SrcSpan # |
Methods showsPrec :: Int -> SrcSpan -> ShowS # show :: SrcSpan -> String # showList :: [SrcSpan] -> ShowS #
Pretty SrcSpan # |
Methods pretty :: SrcSpan -> Doc #
Span SrcSpan # |
Methods getSpan :: SrcSpan -> SrcSpan #
Span AssignOpSpan # |
Methods getSpan :: AssignOpSpan -> SrcSpan #
Span OpSpan # |
Methods getSpan :: OpSpan -> SrcSpan #
Span SliceSpan # |
Methods getSpan :: SliceSpan -> SrcSpan #
Span DictMappingPairSpan # |
Methods getSpan :: DictMappingPairSpan -> SrcSpan #
Span YieldArgSpan # |
Methods getSpan :: YieldArgSpan -> SrcSpan #
Span ExprSpan # |
Methods getSpan :: ExprSpan -> SrcSpan #
Span CompIterSpan # |
Methods getSpan :: CompIterSpan -> SrcSpan #
Span CompIfSpan # |
Methods getSpan :: CompIfSpan -> SrcSpan #
Span CompForSpan # |
Methods getSpan :: CompForSpan -> SrcSpan #
Span ComprehensionExprSpan # |
Methods getSpan :: ComprehensionExprSpan -> SrcSpan #
Span ComprehensionSpan # |
Methods getSpan :: ComprehensionSpan -> SrcSpan #
Span ExceptClauseSpan # |
Methods getSpan :: ExceptClauseSpan -> SrcSpan #
Span HandlerSpan # |
Methods getSpan :: HandlerSpan -> SrcSpan #
Span ArgumentSpan # |
Methods getSpan :: ArgumentSpan -> SrcSpan #
Span ParamTupleSpan # |
Methods getSpan :: ParamTupleSpan -> SrcSpan #
Span ParameterSpan # |
Methods getSpan :: ParameterSpan -> SrcSpan #
Span DecoratorSpan # |
Methods getSpan :: DecoratorSpan -> SrcSpan #
Span StatementSpan # |
Methods getSpan :: StatementSpan -> SrcSpan #
Span ImportRelativeSpan # |
Methods getSpan :: ImportRelativeSpan -> SrcSpan #
Span FromItemsSpan # |
Methods getSpan :: FromItemsSpan -> SrcSpan #
Span FromItemSpan # |
Methods getSpan :: FromItemSpan -> SrcSpan #
Span ImportItemSpan # |
Methods getSpan :: ImportItemSpan -> SrcSpan #
Span IdentSpan # |
Methods getSpan :: IdentSpan -> SrcSpan #

class Span a where #

Types which have a span.

Methods

getSpan :: a -> SrcSpan #

Instances

Span SrcSpan # |
Methods getSpan :: SrcSpan -> SrcSpan #
Span SrcLocation # |
Methods getSpan :: SrcLocation -> SrcSpan #
Span Token # |
Methods getSpan :: Token -> SrcSpan #
Span AssignOpSpan # |
Methods getSpan :: AssignOpSpan -> SrcSpan #
Span OpSpan # |
Methods getSpan :: OpSpan -> SrcSpan #
Span SliceSpan # |
Methods getSpan :: SliceSpan -> SrcSpan #
Span DictMappingPairSpan # |
Methods getSpan :: DictMappingPairSpan -> SrcSpan #
Span YieldArgSpan # |
Methods getSpan :: YieldArgSpan -> SrcSpan #
Span ExprSpan # |
Methods getSpan :: ExprSpan -> SrcSpan #
Span CompIterSpan # |
Methods getSpan :: CompIterSpan -> SrcSpan #
Span CompIfSpan # |
Methods getSpan :: CompIfSpan -> SrcSpan #
Span CompForSpan # |
Methods getSpan :: CompForSpan -> SrcSpan #
Span ComprehensionExprSpan # |
Methods getSpan :: ComprehensionExprSpan -> SrcSpan #
Span ComprehensionSpan # |
Methods getSpan :: ComprehensionSpan -> SrcSpan #
Span ExceptClauseSpan # |
Methods getSpan :: ExceptClauseSpan -> SrcSpan #
Span HandlerSpan # |
Methods getSpan :: HandlerSpan -> SrcSpan #
Span ArgumentSpan # |
Methods getSpan :: ArgumentSpan -> SrcSpan #
Span ParamTupleSpan # |
Methods getSpan :: ParamTupleSpan -> SrcSpan #
Span ParameterSpan # |
Methods getSpan :: ParameterSpan -> SrcSpan #
Span DecoratorSpan # |
Methods getSpan :: DecoratorSpan -> SrcSpan #
Span StatementSpan # |
Methods getSpan :: StatementSpan -> SrcSpan #
Span ImportRelativeSpan # |
Methods getSpan :: ImportRelativeSpan -> SrcSpan #
Span FromItemsSpan # |
Methods getSpan :: FromItemsSpan -> SrcSpan #
Span FromItemSpan # |
Methods getSpan :: FromItemSpan -> SrcSpan #
Span ImportItemSpan # |
Methods getSpan :: ImportItemSpan -> SrcSpan #
Span IdentSpan # |
Methods getSpan :: IdentSpan -> SrcSpan #
Span a => Span [a] # |
Methods getSpan :: [a] -> SrcSpan #
Span a => Span (Maybe a) # |
Methods getSpan :: Maybe a -> SrcSpan #
(Span a, Span b) => Span (Either a b) # |
Methods getSpan :: Either a b -> SrcSpan #
(Span a, Span b) => Span (a, b) # |
Methods getSpan :: (a, b) -> SrcSpan #

spanning :: (Span a, Span b) => a -> b -> SrcSpan #

Create a new span which encloses two spanned things.

mkSrcSpan :: SrcLocation -> SrcLocation -> SrcSpan #

Make a span from two locations. Assumption: either the arguments are the same, or the left one preceeds the right one.

combineSrcSpans :: SrcSpan -> SrcSpan -> SrcSpan #

Combines two `SrcSpan` into one that spans at least all the characters within both spans. Assumes the "file" part is the same in both inputs

initialSrcLocation :: String -> SrcLocation #

Construct the initial source location for a file.

spanStartPoint :: SrcSpan -> SrcSpan #

Make a point span from the start of a span

# Modification

incColumn :: Int -> SrcLocation -> SrcLocation #

Increment the column of a location.

decColumn :: Int -> SrcLocation -> SrcLocation #

Decrement the column of a location, only if they are on the same row.

incLine :: Int -> SrcLocation -> SrcLocation #

Increment the line number (row) of a location by one.

incTab :: SrcLocation -> SrcLocation #

Increment the column of a location by one tab stop.

endCol :: SrcSpan -> Int #

Get the column of the end of a span.

# Projection of components of a span

endRow :: SrcSpan -> Int #

Get the row of the end of a span.

startCol :: SrcSpan -> Int #

Get the column of the start of a span.

startRow :: SrcSpan -> Int #

Get the row of the start of a span.